From efc503d6770bfa37127090f76394c6a2ffc3db19 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Tue, 12 Feb 2019 01:08:57 +0900 Subject: [PATCH] Greylist libraries are attempted to be loaded in the default ns Some of the greylist libraries can be in directories other than /system/lib. For example, libnativehelper.so is moved from the directory to /apex/com.android.runtime/lib. Previous behavior for greylist libraries is to find the lib under /system/lib while "within" the current namespace which is usually the classloader-namespace. Since the libs no longer exist there, linker fails to load it and no further attempt is made. This change fixes the problem by loading the greylist libs "from" the default namespace. Since there is a link from the default namespace to the namespace where the moved libraries are intended to be loaded (e.g., the 'runtime' namespace for libnativehelper.so), the call is successful. Bug: 124201397 Test: bionic-unit-tests Change-Id: I11d15993d18896bdf663c408f9e40d8a607c9b80 --- linker/linker.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index e12a28c2b..ed84a4654 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -1158,14 +1158,6 @@ static int open_library(android_namespace_t* ns, fd = open_library_on_paths(zip_archive_cache, name, file_offset, ns->get_default_library_paths(), realpath); } - // TODO(dimitry): workaround for http://b/26394120 (the grey-list) - if (fd == -1 && ns->is_greylist_enabled() && is_greylisted(ns, name, needed_by)) { - // try searching for it on default_namespace default_library_path - fd = open_library_on_paths(zip_archive_cache, name, file_offset, - g_default_namespace.get_default_library_paths(), realpath); - } - // END OF WORKAROUND - return fd; } @@ -1544,6 +1536,20 @@ static bool find_library_internal(android_namespace_t* ns, return true; } + // TODO(dimitry): workaround for http://b/26394120 (the grey-list) + if (ns->is_greylist_enabled() && is_greylisted(ns, task->get_name(), task->get_needed_by())) { + // For the libs in the greylist, switch to the default namespace and then + // try the load again from there. The library could be loaded from the + // default namespace or from another namespace (e.g. runtime) that is linked + // from the default namespace. + ns = &g_default_namespace; + if (load_library(ns, task, zip_archive_cache, load_tasks, rtld_flags, + search_linked_namespaces)) { + return true; + } + } + // END OF WORKAROUND + if (search_linked_namespaces) { // if a library was not found - look into linked namespaces // preserve current dlerror in the case it fails.