From bc099b6d592e1b363abc3e34c5407be204bb720e Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 28 Aug 2019 23:19:20 +0900 Subject: [PATCH] Revert "Fix: vendor public libraries are accessible via System.loadLibrary" This reverts commit cfe38cdb1cc45c8b7dcbe4f39329551f6602b9ce. The CL 8f712189dfc02285573337e2b4ab17678011db14 in libcore project avoids the need for adding the new paths in LoadedApk. With the CL, a classloader does not give up even when loader.findLibrary() has failed due to some paths are not added to it. Instead, the classloader converts the given libname into a filename (e.g. foo -> libfoo.so) then calls dlopen() with the filename. The classloader reports failure only when the dlopen() call has failed. Therefore, manually adding these paths to the classloader is no longer needed and thus removed. Bug: 109720125 Test: System.loadLibrary("adsprpc") is successful in Pixel (because libadsprpc.so is in Pixel's vendor public lib list) Test: atest cts/tests/tests/jni Merged-In: I1970eba7e732728699042a36b89571915ec81451 (cherry picked from commit 37131e1ee61dd83121ef02744855ee514f0aa6c5) Change-Id: I1970eba7e732728699042a36b89571915ec81451 --- core/java/android/app/LoadedApk.java | 42 ---------------------------- 1 file changed, 42 deletions(-) diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java index 8987b239013c7..f0b354650cf42 100644 --- a/core/java/android/app/LoadedApk.java +++ b/core/java/android/app/LoadedApk.java @@ -883,48 +883,6 @@ public final class LoadedApk { } } - // /apex/com.android.art/lib, /vendor/lib, /odm/lib and /product/lib - // are added to the native lib search paths of the classloader. - // Note that this is done AFTER the classloader is - // created by ApplicationLoaders.getDefault().getClassLoader(...). The - // reason is because if we have added the paths when creating the classloader - // above, the paths are also added to the search path of the linker namespace - // 'classloader-namespace', which will allow ALL libs in the paths to apps. - // Since only the libs listed in /etc/public.libraries.txt can be - // available to apps, we shouldn't add the paths then. - // - // However, we need to add the paths to the classloader (Java) though. This - // is because when a native lib is requested via System.loadLibrary(), the - // classloader first tries to find the requested lib in its own native libs - // search paths. If a lib is not found in one of the paths, dlopen() is not - // called at all. This can cause a problem that a vendor public native lib - // is accessible when directly opened via dlopen(), but inaccesible via - // System.loadLibrary(). In order to prevent the problem, we explicitly - // add the paths only to the classloader, and not to the native loader - // (linker namespace). - List extraLibPaths = new ArrayList<>(4); - String abiSuffix = VMRuntime.getRuntime().is64Bit() ? "64" : ""; - if (!defaultSearchPaths.contains("/apex/com.android.art/lib")) { - extraLibPaths.add("/apex/com.android.art/lib" + abiSuffix); - } - if (!defaultSearchPaths.contains("/vendor/lib")) { - extraLibPaths.add("/vendor/lib" + abiSuffix); - } - if (!defaultSearchPaths.contains("/odm/lib")) { - extraLibPaths.add("/odm/lib" + abiSuffix); - } - if (!defaultSearchPaths.contains("/product/lib")) { - extraLibPaths.add("/product/lib" + abiSuffix); - } - if (!extraLibPaths.isEmpty()) { - StrictMode.ThreadPolicy oldPolicy = allowThreadDiskReads(); - try { - ApplicationLoaders.getDefault().addNative(mDefaultClassLoader, extraLibPaths); - } finally { - setThreadPolicy(oldPolicy); - } - } - if (addedPaths != null && addedPaths.size() > 0) { final String add = TextUtils.join(File.pathSeparator, addedPaths); ApplicationLoaders.getDefault().addPath(mDefaultClassLoader, add);