From d69e801fe890d1732906aaadb8aa06244bb4ac52 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Tue, 14 Feb 2017 13:06:12 -0800 Subject: [PATCH] liblog: Harden log_id check. Logd currently checks against LOG_ID_MAX and LOG_ID_KERNEL to determine if a given log_id is available. liblog uses only LOG_ID_KERNEL. While this matches with the comments in log/log_id.h to always keep LOG_ID_KERNEL at the end it does not match with other checks that logd makes, causing inconsistent behavior. This inconsistency is noticable on devices that errantly rewrite LOG_ID_MAX to not equal LOG_ID_KERNEL + 1. For log buffers with id's greater than LOG_ID_KERNEL, liblog reports that logd is unavailable while logd would accept the request. The guideline is to not use buffer ids above LOG_ID_KERNEL. This hardening change prevents an inconsistency that results if these guidelines are not followed. Partners are urged instead to increase LOG_ID_KERNEL locally to match their LOG_ID_MAX - 1 when they add new local log buffers in their private builds. Signed-off-by: Evan Ralston Signed-off-by: Mark Salyzyn Test: compiles. no functional change Change-Id: Icd4b12ac79c1e5cd1d8a32f67a9795797580aad5 --- liblog/logd_reader.c | 2 +- liblog/logd_writer.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/liblog/logd_reader.c b/liblog/logd_reader.c index ccc7da8ae..a6c3f7a44 100644 --- a/liblog/logd_reader.c +++ b/liblog/logd_reader.c @@ -91,7 +91,7 @@ LIBLOG_HIDDEN struct android_log_transport_read logdLoggerRead = { static int logdAvailable(log_id_t logId) { - if (logId > LOG_ID_KERNEL) { + if (logId >= LOG_ID_MAX) { return -EINVAL; } if (logId == LOG_ID_SECURITY) { diff --git a/liblog/logd_writer.c b/liblog/logd_writer.c index 2bab92ef8..12b797dae 100644 --- a/liblog/logd_writer.c +++ b/liblog/logd_writer.c @@ -117,7 +117,7 @@ static void logdClose() static int logdAvailable(log_id_t logId) { - if (logId > LOG_ID_SECURITY) { + if (logId >= LOG_ID_MAX || logId == LOG_ID_KERNEL) { return -EINVAL; } if (atomic_load(&logdLoggerWrite.context.sock) < 0) {