liblog: suppress pmsg on user builds
- add optimized & cached LIBLOG_HIDDEN __android_log_is_debuggable()
- check when writing, either LOG_ID_SECURITY, SafetyNet or
debuggable when pushing content to the pmsg buffer.
Bug: 27566046
Change-Id: I85f1b55ec329b38e00f4183836b6ed53046c323d
diff --git a/liblog/pmsg_writer.c b/liblog/pmsg_writer.c
index 7034ceb..9cd3c48 100644
--- a/liblog/pmsg_writer.c
+++ b/liblog/pmsg_writer.c
@@ -73,6 +73,11 @@
if (logId > LOG_ID_SECURITY) {
return -EINVAL;
}
+ if ((logId != LOG_ID_SECURITY) &&
+ (logId != LOG_ID_EVENTS) &&
+ !__android_log_is_debuggable()) {
+ return -EINVAL;
+ }
if (pmsgLoggerWrite.context.fd < 0) {
if (access("/dev/pmsg0", W_OK) == 0) {
return 0;
@@ -82,6 +87,14 @@
return 1;
}
+/*
+ * Extract a 4-byte value from a byte stream.
+ */
+static inline uint32_t get4LE(const uint8_t* src)
+{
+ return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
+}
+
static int pmsgWrite(log_id_t logId, struct timespec *ts,
struct iovec *vec, size_t nr)
{
@@ -92,6 +105,16 @@
size_t i, payloadSize;
ssize_t ret;
+ if ((logId == LOG_ID_EVENTS) && !__android_log_is_debuggable()) {
+ if (vec[0].iov_len < 4) {
+ return -EINVAL;
+ }
+
+ if (SNET_EVENT_LOG_TAG != get4LE(vec[0].iov_base)) {
+ return -EPERM;
+ }
+ }
+
if (pmsgLoggerWrite.context.fd < 0) {
return -EBADF;
}