From 76351e3e3fbbd386c059251dbc6b1081a8f77088 Mon Sep 17 00:00:00 2001 From: Pete Gillin Date: Fri, 9 Aug 2019 11:15:40 +0000 Subject: [PATCH] Revert "fdsan: make fatal by default." This reverts commit 66b5e3ca1941a118bbb8ea41bfe98f9725ee8d5d. Reason for revert: Causes installd_dexopt_test to fail. Presumably there is an existing issue which this change is turning into a hard fail, so that needs to be fixed before this can be rolled forwards. See b/139092341. Bug: 139092341 Bug: 137788030 Change-Id: I1beccddff64c86541bc003b9b009f4046ec9cbf1 --- libc/bionic/fdsan.cpp | 65 +++++++++++++--------------------- libc/include/android/fdsan.h | 4 --- linker/linker_sdk_versions.cpp | 11 ++---- 3 files changed, 26 insertions(+), 54 deletions(-) diff --git a/libc/bionic/fdsan.cpp b/libc/bionic/fdsan.cpp index 4ebc796d2..dd3a96e64 100644 --- a/libc/bionic/fdsan.cpp +++ b/libc/bionic/fdsan.cpp @@ -106,8 +106,30 @@ FdEntry* FdTableImpl::at(size_t idx) { } void __libc_init_fdsan() { - constexpr auto default_level = ANDROID_FDSAN_ERROR_LEVEL_FATAL; - android_fdsan_set_error_level_from_property(default_level); + constexpr auto default_level = ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE; + const prop_info* pi = __system_property_find(kFdsanPropertyName); + if (!pi) { + android_fdsan_set_error_level(default_level); + return; + } + __system_property_read_callback( + pi, + [](void*, const char*, const char* value, uint32_t) { + if (strcasecmp(value, "1") == 0 || strcasecmp(value, "fatal") == 0) { + android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_FATAL); + } else if (strcasecmp(value, "warn") == 0) { + android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_WARN_ALWAYS); + } else if (strcasecmp(value, "warn_once") == 0) { + android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE); + } else { + if (strlen(value) != 0 && strcasecmp(value, "0") != 0) { + async_safe_format_log(ANDROID_LOG_ERROR, "libc", + "debug.fdsan set to unknown value '%s', disabling", value); + } + android_fdsan_set_error_level(default_level); + } + }, + nullptr); } static FdTable& GetFdTable() { @@ -333,45 +355,6 @@ android_fdsan_error_level android_fdsan_set_error_level(android_fdsan_error_leve return atomic_exchange(&GetFdTable().error_level, new_level); } -android_fdsan_error_level android_fdsan_set_error_level_from_property( - android_fdsan_error_level default_level) { - const prop_info* pi = __system_property_find(kFdsanPropertyName); - if (!pi) { - return android_fdsan_set_error_level(default_level); - } - - struct callback_data { - android_fdsan_error_level default_value; - android_fdsan_error_level result; - }; - - callback_data data; - data.default_value = default_level; - - __system_property_read_callback( - pi, - [](void* arg, const char*, const char* value, uint32_t) { - callback_data* data = static_cast(arg); - - if (strcasecmp(value, "1") == 0 || strcasecmp(value, "fatal") == 0) { - data->result = android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_FATAL); - } else if (strcasecmp(value, "warn") == 0) { - data->result = android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_WARN_ALWAYS); - } else if (strcasecmp(value, "warn_once") == 0) { - data->result = android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE); - } else { - if (strlen(value) != 0 && strcasecmp(value, "0") != 0) { - async_safe_format_log(ANDROID_LOG_ERROR, "libc", - "debug.fdsan set to unknown value '%s', disabling", value); - } - data->result = android_fdsan_set_error_level(data->default_value); - } - }, - &data); - - return data.result; -} - int close(int fd) { int rc = android_fdsan_close_with_tag(fd, 0); if (rc == -1 && errno == EINTR) { diff --git a/libc/include/android/fdsan.h b/libc/include/android/fdsan.h index 83b9318ba..1169ed046 100644 --- a/libc/include/android/fdsan.h +++ b/libc/include/android/fdsan.h @@ -197,8 +197,4 @@ enum android_fdsan_error_level android_fdsan_get_error_level() __INTRODUCED_IN(2 */ enum android_fdsan_error_level android_fdsan_set_error_level(enum android_fdsan_error_level new_level) __INTRODUCED_IN(29) __attribute__((__weak__)); -/* - * Set the error level to the global setting if available, or a default value. - */ -enum android_fdsan_error_level android_fdsan_set_error_level_from_property(enum android_fdsan_error_level default_level) __INTRODUCED_IN(30) __attribute__((__weak__)); __END_DECLS diff --git a/linker/linker_sdk_versions.cpp b/linker/linker_sdk_versions.cpp index 29c0f4af2..b06f3e63f 100644 --- a/linker/linker_sdk_versions.cpp +++ b/linker/linker_sdk_versions.cpp @@ -26,12 +26,9 @@ * SUCH DAMAGE. */ -#include - -#include -#include - #include "linker.h" +#include +#include static std::atomic g_target_sdk_version(__ANDROID_API__); @@ -41,10 +38,6 @@ void set_application_target_sdk_version(int target) { target = __ANDROID_API__; } g_target_sdk_version = target; - - if (target < 30) { - android_fdsan_set_error_level_from_property(ANDROID_FDSAN_ERROR_LEVEL_WARN_ONCE); - } } int get_application_target_sdk_version() {