diff options
author | Martin Stjernholm <mast@google.com> | 2019-02-23 02:10:14 +0000 |
---|---|---|
committer | Martin Stjernholm <mast@google.com> | 2019-02-23 03:46:27 +0000 |
commit | 7888b5cdd7dd62e07d39204dc8036a23e4ab2e5b (patch) | |
tree | d7344801acb081298621824f36ef7ce1140c31b8 /libnativeloader/native_loader.cpp | |
parent | 4ac1829d7ebb03d63f9ca1c1ddcdf45443e84f33 (diff) |
Avoid runtime namespace becoming parent for classloader-namespace.
Passing nullptr as parent namespace to android_create_namespace makes it use
the namespace of the caller as parent, which typically is the runtime
namespace. That in turn causes classloader-namespace to inherit any
libraries in the shared group of the runtime namespace, i.e. any libraries
that have been loaded in it with RTLD_GLOBAL or DF_1_GLOBAL up to that
point.
Let's instead pass the platform namespace from the linker config as fallback
when a parent namespace cannot be found. That is also what happened before
libnativeloader moved into the runtime namespace.
Test: Flash and boot
Test: atest CtsJniTestCases (on cuttlefish and taimen)
Bug: 124501296
Change-Id: If2faee74e2bdcf95d19516faec340fedcdd07e29
Diffstat (limited to 'libnativeloader/native_loader.cpp')
-rw-r--r-- | libnativeloader/native_loader.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index f9c161c6d..043f0380f 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -115,6 +115,8 @@ static constexpr const char* kVendorNamespaceName = "sphal"; static constexpr const char* kVndkNamespaceName = "vndk"; +static constexpr const char* kDefaultNamespaceName = "default"; +static constexpr const char* kPlatformNamespaceName = "platform"; static constexpr const char* kRuntimeNamespaceName = "runtime"; // classloader-namespace is a linker namespace that is created for the loaded @@ -272,8 +274,19 @@ class LibraryNamespaces { NativeLoaderNamespace native_loader_ns; if (!is_native_bridge) { - android_namespace_t* android_parent_ns = - parent_ns == nullptr ? nullptr : parent_ns->get_android_ns(); + android_namespace_t* android_parent_ns; + if (parent_ns != nullptr) { + android_parent_ns = parent_ns->get_android_ns(); + } else { + // Fall back to the platform namespace if no parent is found. It is + // called "default" for binaries in /system and "platform" for those in + // the Runtime APEX. Try "platform" first since "default" always exists. + android_parent_ns = android_get_exported_namespace(kPlatformNamespaceName); + if (android_parent_ns == nullptr) { + android_parent_ns = android_get_exported_namespace(kDefaultNamespaceName); + } + } + android_namespace_t* ns = android_create_namespace(namespace_name, nullptr, library_path.c_str(), @@ -322,8 +335,16 @@ class LibraryNamespaces { native_loader_ns = NativeLoaderNamespace(ns); } else { - native_bridge_namespace_t* native_bridge_parent_namespace = - parent_ns == nullptr ? nullptr : parent_ns->get_native_bridge_ns(); + native_bridge_namespace_t* native_bridge_parent_namespace; + if (parent_ns != nullptr) { + native_bridge_parent_namespace = parent_ns->get_native_bridge_ns(); + } else { + native_bridge_parent_namespace = NativeBridgeGetExportedNamespace(kPlatformNamespaceName); + if (native_bridge_parent_namespace == nullptr) { + native_bridge_parent_namespace = NativeBridgeGetExportedNamespace(kDefaultNamespaceName); + } + } + native_bridge_namespace_t* ns = NativeBridgeCreateNamespace(namespace_name, nullptr, library_path.c_str(), |