summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2017-05-04 15:54:46 -0500
committerMark Salyzyn2017-05-11 14:21:02 -0500
commitc4e4823b00a94627e922eada1172688818471b0c (patch)
treeb0b593e27514fb33ff7d07be943036620001e739 /logd/LogListener.cpp
parent46bb1ffa8ad3a4cb3d2fe31f6f7baee418b5df6e (diff)
downloadplatform-system-core-c4e4823b00a94627e922eada1172688818471b0c.tar.gz
platform-system-core-c4e4823b00a94627e922eada1172688818471b0c.tar.xz
platform-system-core-c4e4823b00a94627e922eada1172688818471b0c.zip
logd: validate and fill in socket credentials
- android::pidToUid() additional checking. Make sure if we have to convert a PID to an UID that the parse of /proc/<pid>/status requires a trailing space after the number - android::tidToPid() added, in the same vein as android::pidToUid(). - stats.tidToPid() added - If no credentials, set PID to 0 and UID to DEFAULT_OVERFLOWUID - If credentialed PID is 0, use stats.tidToPid() - If credentialed UID is DEFAULT_OVERFLOWUID, use stats.pidToUid() Test: remove +passcred from logd.rc for daemon and confirm very few UID=65534 or PID=0 cases actually show up Bug: 37985222 Change-Id: I7d20506e70e67beb3043d1537cf9450ab58dc278
Diffstat (limited to 'logd/LogListener.cpp')
-rw-r--r--logd/LogListener.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/logd/LogListener.cpp b/logd/LogListener.cpp
index 3c0d08dc6..d2df68eef 100644
--- a/logd/LogListener.cpp
+++ b/logd/LogListener.cpp
@@ -14,7 +14,9 @@
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 16
17#include <ctype.h>
17#include <limits.h> 18#include <limits.h>
19#include <stdio.h>
18#include <sys/cdefs.h> 20#include <sys/cdefs.h>
19#include <sys/prctl.h> 21#include <sys/prctl.h>
20#include <sys/socket.h> 22#include <sys/socket.h>
@@ -72,8 +74,11 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
72 cmsg = CMSG_NXTHDR(&hdr, cmsg); 74 cmsg = CMSG_NXTHDR(&hdr, cmsg);
73 } 75 }
74 76
77 struct ucred fake_cred;
75 if (cred == NULL) { 78 if (cred == NULL) {
76 return false; 79 cred = &fake_cred;
80 cred->pid = 0;
81 cred->uid = DEFAULT_OVERFLOWUID;
77 } 82 }
78 83
79 if (cred->uid == AID_LOGD) { 84 if (cred->uid == AID_LOGD) {
@@ -96,6 +101,27 @@ bool LogListener::onDataAvailable(SocketClient* cli) {
96 return false; 101 return false;
97 } 102 }
98 103
104 // Check credential validity, acquire corrected details if not supplied.
105 if (cred->pid == 0) {
106 cred->pid = logbuf ? logbuf->tidToPid(header->tid)
107 : android::tidToPid(header->tid);
108 if (cred->pid == getpid()) {
109 // We expect that /proc/<tid>/ is accessible to self even without
110 // readproc group, so that we will always drop messages that come
111 // from any of our logd threads and their library calls.
112 return false; // ignore self
113 }
114 }
115 if (cred->uid == DEFAULT_OVERFLOWUID) {
116 uid_t uid =
117 logbuf ? logbuf->pidToUid(cred->pid) : android::pidToUid(cred->pid);
118 if (uid == AID_LOGD) {
119 uid = logbuf ? logbuf->pidToUid(header->tid)
120 : android::pidToUid(cred->pid);
121 }
122 if (uid != AID_LOGD) cred->uid = uid;
123 }
124
99 char* msg = ((char*)buffer) + sizeof(android_log_header_t); 125 char* msg = ((char*)buffer) + sizeof(android_log_header_t);
100 n -= sizeof(android_log_header_t); 126 n -= sizeof(android_log_header_t);
101 127