From 5fdc4cc746c97e1068bd5f7f33f4efe5f942e812 Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Fri, 23 Jun 2017 13:36:13 -0700 Subject: [PATCH] Revert "crash_dump: during early boot, output to kmsg on userdebug." This reverts commit bf2dd482412cb7b93f52d2ed2d9be9a32fa8d2f9. Addresses: avc: denied { relabelto } for name="kmsg_debug" dev="tmpfs" ino=10642 scontext=u:r:init:s0 tcontext=u:object_r:device:s0 tclass=chr_file Bug: 62101480, 35197529 Test: build and boot device. Verify selinux denial no longer occurs. Change-Id: I28ce16f50eec20ef15c1721f41b66f22a84e7cca --- debuggerd/libdebuggerd/utility.cpp | 46 +----------------------------- init/Android.mk | 2 -- init/init.cpp | 9 ------ 3 files changed, 1 insertion(+), 56 deletions(-) diff --git a/debuggerd/libdebuggerd/utility.cpp b/debuggerd/libdebuggerd/utility.cpp index 7f450e6bc..22fde5ea4 100644 --- a/debuggerd/libdebuggerd/utility.cpp +++ b/debuggerd/libdebuggerd/utility.cpp @@ -22,22 +22,16 @@ #include #include #include -#include #include #include #include -#include -#include #include -#include #include #include #include -using android::base::unique_fd; - // Whitelist output desired in the logcat output. bool is_allowed_in_logcat(enum logtype ltype) { if ((ltype == HEADER) @@ -48,19 +42,6 @@ bool is_allowed_in_logcat(enum logtype ltype) { return false; } -static bool should_write_to_kmsg() { - // Write to kmsg if tombstoned isn't up, and we're able to do so. - if (!android::base::GetBoolProperty("ro.debuggable", false)) { - return false; - } - - if (android::base::GetProperty("init.svc.tombstoned", "") == "running") { - return false; - } - - return true; -} - __attribute__((__weak__, visibility("default"))) void _LOG(log_t* log, enum logtype ltype, const char* fmt, ...) { bool write_to_tombstone = (log->tfd != -1); @@ -68,7 +49,6 @@ void _LOG(log_t* log, enum logtype ltype, const char* fmt, ...) { && log->crashed_tid != -1 && log->current_tid != -1 && (log->crashed_tid == log->current_tid); - static bool write_to_kmsg = should_write_to_kmsg(); char buf[512]; va_list ap; @@ -90,30 +70,6 @@ void _LOG(log_t* log, enum logtype ltype, const char* fmt, ...) { if (log->amfd_data != nullptr) { *log->amfd_data += buf; } - - if (write_to_kmsg) { - unique_fd kmsg_fd(open("/dev/kmsg_debug", O_WRONLY | O_APPEND | O_CLOEXEC)); - if (kmsg_fd.get() >= 0) { - // Our output might contain newlines which would otherwise be handled by the android logger. - // Split the lines up ourselves before sending to the kernel logger. - if (buf[len - 1] == '\n') { - buf[len - 1] = '\0'; - } - - std::vector fragments = android::base::Split(buf, "\n"); - for (const std::string& fragment : fragments) { - static constexpr char prefix[] = "<3>DEBUG: "; - struct iovec iov[3]; - iov[0].iov_base = const_cast(prefix); - iov[0].iov_len = strlen(prefix); - iov[1].iov_base = const_cast(fragment.c_str()); - iov[1].iov_len = fragment.length(); - iov[2].iov_base = const_cast("\n"); - iov[2].iov_len = 1; - TEMP_FAILURE_RETRY(writev(kmsg_fd.get(), iov, 3)); - } - } - } } } @@ -249,7 +205,7 @@ void dump_memory(log_t* log, Backtrace* backtrace, uintptr_t addr, const char* f } void read_with_default(const char* path, char* buf, size_t len, const char* default_value) { - unique_fd fd(open(path, O_RDONLY | O_CLOEXEC)); + android::base::unique_fd fd(open(path, O_RDONLY)); if (fd != -1) { int rc = TEMP_FAILURE_RETRY(read(fd.get(), buf, len - 1)); if (rc != -1) { diff --git a/init/Android.mk b/init/Android.mk index 489d0767a..866ea34bb 100644 --- a/init/Android.mk +++ b/init/Android.mk @@ -9,14 +9,12 @@ init_options += \ -DALLOW_LOCAL_PROP_OVERRIDE=1 \ -DALLOW_PERMISSIVE_SELINUX=1 \ -DREBOOT_BOOTLOADER_ON_PANIC=1 \ - -DWORLD_WRITABLE_KMSG=1 \ -DDUMP_ON_UMOUNT_FAILURE=1 else init_options += \ -DALLOW_LOCAL_PROP_OVERRIDE=0 \ -DALLOW_PERMISSIVE_SELINUX=0 \ -DREBOOT_BOOTLOADER_ON_PANIC=0 \ - -DWORLD_WRITABLE_KMSG=0 \ -DDUMP_ON_UMOUNT_FAILURE=0 endif diff --git a/init/init.cpp b/init/init.cpp index ee87145c3..9e238d449 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -889,9 +889,6 @@ static void selinux_restore_context() { LOG(INFO) << "Running restorecon..."; selinux_android_restorecon("/dev", 0); selinux_android_restorecon("/dev/kmsg", 0); - if constexpr (WORLD_WRITABLE_KMSG) { - selinux_android_restorecon("/dev/kmsg_debug", 0); - } selinux_android_restorecon("/dev/socket", 0); selinux_android_restorecon("/dev/random", 0); selinux_android_restorecon("/dev/urandom", 0); @@ -997,13 +994,7 @@ int main(int argc, char** argv) { setgroups(arraysize(groups), groups); mount("sysfs", "/sys", "sysfs", 0, NULL); mount("selinuxfs", "/sys/fs/selinux", "selinuxfs", 0, NULL); - mknod("/dev/kmsg", S_IFCHR | 0600, makedev(1, 11)); - - if constexpr (WORLD_WRITABLE_KMSG) { - mknod("/dev/kmsg_debug", S_IFCHR | 0622, makedev(1, 11)); - } - mknod("/dev/random", S_IFCHR | 0666, makedev(1, 8)); mknod("/dev/urandom", S_IFCHR | 0666, makedev(1, 9));