diff options
author | Victor Chang <vichang@google.com> | 2019-02-01 20:01:27 +0000 |
---|---|---|
committer | Victor Chang <vichang@google.com> | 2019-02-08 13:34:09 +0000 |
commit | f70a2fe4c1149ba94105b1ed64903f0d6758b2cc (patch) | |
tree | 9caaaf8e86cac452f7eb872b5bd0c43ff778452c /libnativeloader/native_loader.cpp | |
parent | bece53e515db3fd7d8f401c040ca4a4bff7d86c8 (diff) |
Remove the public libs in runtime namespace
These libs are listed in public.android.txt, but not exposed in the default namespace
Bug: 120786417
Bug: 121372395
Test: app can still DT_NEEDED libicuuc.so
Change-Id: I03dc51f04e29c2d15679c4daf82b05a812efb2db
Diffstat (limited to 'libnativeloader/native_loader.cpp')
-rw-r--r-- | libnativeloader/native_loader.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index a4e00bd0b..2631a8a55 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -128,6 +128,12 @@ static constexpr const char* kWhitelistedDirectories = "/data:/mnt/expand"; static constexpr const char* kApexPath = "/apex/"; +#if defined(__LP64__) +static constexpr const char* kRuntimeApexLibPath = "/apex/com.android.runtime/lib64"; +#else +static constexpr const char* kRuntimeApexLibPath = "/apex/com.android.runtime/lib"; +#endif + static bool is_debuggable() { char debuggable[PROP_VALUE_MAX]; property_get("ro.debuggable", debuggable, "0"); @@ -399,6 +405,14 @@ class LibraryNamespaces { } } + // Remove the public libs in the runtime namespace. + // These libs are listed in public.android.txt, but we don't want the rest of android + // in default namespace to dlopen the libs. + // For example, libicuuc.so is exposed to classloader namespace from runtime namespace. + // Unfortunately, it does not have stable C symbols, and default namespace should only use + // stable symbols in libandroidicu.so. http://b/120786417 + removePublicLibsIfExistsInRuntimeApex(sonames); + // android_init_namespaces() expects all the public libraries // to be loaded so that they can be found by soname alone. // @@ -493,6 +507,27 @@ class LibraryNamespaces { } } + /** + * Remove the public libs in runtime namespace + */ + void removePublicLibsIfExistsInRuntimeApex(std::vector<std::string>& sonames) { + for (const std::string& lib_name : kRuntimePublicLibraries) { + std::string path(kRuntimeApexLibPath); + path.append("/").append(lib_name); + + struct stat s; + // Do nothing if the path in /apex does not exist. + // Runtime APEX must be mounted since libnativeloader is in the same APEX + if (stat(path.c_str(), &s) != 0) { + continue; + } + + auto it = std::find(sonames.begin(), sonames.end(), lib_name); + if (it != sonames.end()) { + sonames.erase(it); + } + } + } bool ReadConfig(const std::string& configFile, std::vector<std::string>* sonames, const std::function<bool(const std::string& /* soname */, |