From 1906e77665758c61b0d97c35f3d64225f296504a Mon Sep 17 00:00:00 2001 From: vichang Date: Wed, 6 Feb 2019 16:42:21 +0000 Subject: [PATCH] Revert "Allow dlopen("/system/lib/") for pre-Q" This reverts commit f6e4cfd933ec94f830b2d5074d9737ae236e3bf4. Reason for revert: b/123972211 Change-Id: I1ea199c27e224bbd27dee7692f9f448ca9c2b6d1 --- linker/linker.cpp | 91 ++++++++--------------------------------------- 1 file changed, 14 insertions(+), 77 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index da0b02328..4dcdf7e89 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -91,21 +91,19 @@ static const char* const kLdConfigFilePath = "/system/etc/ld.config.txt"; static const char* const kLdConfigVndkLiteFilePath = "/system/etc/ld.config.vndk_lite.txt"; #if defined(__LP64__) -static const char* const kSystemLibDir = "/system/lib64"; -static const char* const kOdmLibDir = "/odm/lib64"; -static const char* const kVendorLibDir = "/vendor/lib64"; -static const char* const kAsanSystemLibDir = "/data/asan/system/lib64"; -static const char* const kAsanOdmLibDir = "/data/asan/odm/lib64"; -static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib64"; -static const char* const kRuntimeApexLibDir = "/apex/com.android.runtime/lib64"; +static const char* const kSystemLibDir = "/system/lib64"; +static const char* const kOdmLibDir = "/odm/lib64"; +static const char* const kVendorLibDir = "/vendor/lib64"; +static const char* const kAsanSystemLibDir = "/data/asan/system/lib64"; +static const char* const kAsanOdmLibDir = "/data/asan/odm/lib64"; +static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib64"; #else -static const char* const kSystemLibDir = "/system/lib"; -static const char* const kOdmLibDir = "/odm/lib"; -static const char* const kVendorLibDir = "/vendor/lib"; -static const char* const kAsanSystemLibDir = "/data/asan/system/lib"; -static const char* const kAsanOdmLibDir = "/data/asan/odm/lib"; -static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib"; -static const char* const kRuntimeApexLibDir = "/apex/com.android.runtime/lib"; +static const char* const kSystemLibDir = "/system/lib"; +static const char* const kOdmLibDir = "/odm/lib"; +static const char* const kVendorLibDir = "/vendor/lib"; +static const char* const kAsanSystemLibDir = "/data/asan/system/lib"; +static const char* const kAsanOdmLibDir = "/data/asan/odm/lib"; +static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib"; #endif static const char* const kAsanLibDirPrefix = "/data/asan"; @@ -230,44 +228,6 @@ static bool is_greylisted(android_namespace_t* ns, const char* name, const soinf } // END OF WORKAROUND -// Workaround for dlopen(/system/lib(64)/) when .so is in /apex. http://b/121248172 -/** - * Translate /system path to /apex path if needed - * The workaround should work only when targetSdkVersion < Q. - * - * param out_name_to_apex pointing to /apex path - * return true if translation is needed - */ -static bool translateSystemPathToApexPath(const char* name, std::string* out_name_to_apex) { - static const char* const kSystemToRuntimeApexLibs[] = { - "libicuuc.so", - "libicui18n.so", - }; - // New mapping for new apex should be added below - - // Nothing to do if target sdk version is Q or above - if (get_application_target_sdk_version() >= __ANDROID_API_Q__) { - return false; - } - - // If the path is not absolute, or isn't /system/lib, there's nothing to do. - if (name[0] != '/' || dirname(name).compare(kSystemLibDir) != 0) { - return false; - } - - const char* base_name = basename(name); - - for (const char* soname : kSystemToRuntimeApexLibs) { - if (strcmp(base_name, soname) == 0) { - *out_name_to_apex = std::string(kRuntimeApexLibDir) + "/" + base_name; - return true; - } - } - - return false; -} -// End Workaround for dlopen(/system/lib/) when .so is in /apex. - static std::vector g_ld_preload_names; static bool g_anonymous_namespace_initialized; @@ -2106,14 +2066,13 @@ void* do_dlopen(const char* name, int flags, android_namespace_t* ns = get_caller_namespace(caller); LD_LOG(kLogDlopen, - "dlopen(name=\"%s\", flags=0x%x, extinfo=%s, caller=\"%s\", caller_ns=%s@%p, targetSdkVersion=%i) ...", + "dlopen(name=\"%s\", flags=0x%x, extinfo=%s, caller=\"%s\", caller_ns=%s@%p) ...", name, flags, android_dlextinfo_to_string(extinfo).c_str(), caller == nullptr ? "(null)" : caller->get_realpath(), ns == nullptr ? "(null)" : ns->get_name(), - ns, - get_application_target_sdk_version()); + ns); auto failure_guard = android::base::make_scope_guard( [&]() { LD_LOG(kLogDlopen, "... dlopen failed: %s", linker_get_error_buffer()); }); @@ -2145,28 +2104,6 @@ void* do_dlopen(const char* name, int flags, } } - // Workaround for dlopen(/system/lib/) when .so is in /apex. http://b/121248172 - // The workaround works only when targetSdkVersion < Q. - std::string name_to_apex; - if (translateSystemPathToApexPath(name, &name_to_apex)) { - const char* new_name = name_to_apex.c_str(); - LD_LOG(kLogDlopen, "dlopen translating path to /apex: name=%s newName=%s", - name, - new_name); - // Some APEXs could be optionally disabled. Only translate the path - // when the old file is absent and the new file exists. - if (file_exists(name)) { - LD_LOG(kLogDlopen, "dlopen failed to translate path to /apex: /system file exists. %s", name); - } else if (!file_exists(new_name)) { - LD_LOG(kLogDlopen, "dlopen failed to translate path to /apex: /apex file does not exist. %s", - new_name); - } else { - LD_LOG(kLogDlopen, "dlopen new path to /apex: newName=%s", new_name); - name = new_name; - } - } - // End Workaround for dlopen(/system/lib/) when .so is in /apex. - std::string asan_name_holder; const char* translated_name = name;