From 83b247891cea88347b759d638814cea61995d2ca Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Thu, 11 Aug 2016 16:07:10 -0700 Subject: [PATCH] logd: klogd crash (part deux) LogBuffer::pidToUid(pid_t pid) { return stats.pidToUid(pid); } needs to have LogBuffer::lock()/unlock() to prevent unordered_map data corruption. This can lead to multiple symptoms, crashes and continuous spins on corrupted iterators. Bug: 30688716 Bug: 30050636 Bug: 30614675 Bug: 25620123 Bug: 30792935 Change-Id: I1d8fec8e5fda98c6a08645e7456b081507696b3c --- logd/LogKlog.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/logd/LogKlog.cpp b/logd/LogKlog.cpp index 0495463dc..ef6c1ae2c 100644 --- a/logd/LogKlog.cpp +++ b/logd/LogKlog.cpp @@ -26,6 +26,7 @@ #include #include +#include #include "LogBuffer.h" #include "LogKlog.h" @@ -589,7 +590,12 @@ int LogKlog::log(const char *buf, size_t len) { // Parse pid, tid and uid const pid_t pid = sniffPid(p, len - (p - buf)); const pid_t tid = pid; - const uid_t uid = pid ? logbuf->pidToUid(pid) : 0; + uid_t uid = AID_ROOT; + if (pid) { + logbuf->lock(); + uid = logbuf->pidToUid(pid); + logbuf->unlock(); + } // Parse (rules at top) to pull out a tag from the incoming kernel message. // Some may view the following as an ugly heuristic, the desire is to