From 8e1a7cb303d7c8f763dfb99ae311b820996b1ab4 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Tue, 27 Mar 2018 08:14:25 +0000 Subject: Revert "Revert "Allow hidden API access from system libraries"" Libraries like RemoteDisplay provide an APK that an app loads into its process and which accesses internal APIs on the app's behalf, without exposing the internals to the app. These libraries are considered part of the platform, but were not exempt from hidden API checks because they are not loaded with the boot strap class loader. This patch adds a new flag to DexFile class which the constructor sets to true of the canonical location of the newly loaded dex file starts with "${ANDROID_ROOT}/framework/". Hidden API enforcement then checks this flag when determining whether the caller of a hidden class member is allowed to access it or not. This reverts commit 0127b71a2588efcd1a53c192c5c267157878b010. Previous CL saw two issues: - buildbots would set non-existent ANDROID_ROOT for host-side builds - calling realpath on unquickened dex files would overflow the stack Bug: 64382372 Bug: 76138670 Bug: 76165623 Bug: 76112393 Bug: 76452688 Bug: 76429651 Test: art/test.py --target -r -b -t 674-hiddenapi Test: SystemUI APCT test Change-Id: Ie07a088509002593353965d3d24bf7362b643f40 --- runtime/native/java_lang_Class.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'runtime/native/java_lang_Class.cc') diff --git a/runtime/native/java_lang_Class.cc b/runtime/native/java_lang_Class.cc index fc61c9597e..ad05856eaf 100644 --- a/runtime/native/java_lang_Class.cc +++ b/runtime/native/java_lang_Class.cc @@ -49,8 +49,8 @@ namespace art { -// Returns true if the first non-ClassClass caller up the stack is in boot class path. -static bool IsCallerInBootClassPath(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { +// Returns true if the first non-ClassClass caller up the stack is in a platform dex file. +static bool IsCallerInPlatformDex(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { // Walk the stack and find the first frame not from java.lang.Class. // This is very expensive. Save this till the last. struct FirstNonClassClassCallerVisitor : public StackVisitor { @@ -82,7 +82,7 @@ static bool IsCallerInBootClassPath(Thread* self) REQUIRES_SHARED(Locks::mutator FirstNonClassClassCallerVisitor visitor(self); visitor.WalkStack(); return visitor.caller != nullptr && - visitor.caller->GetDeclaringClass()->IsBootStrapClassLoaded(); + hiddenapi::IsCallerInPlatformDex(visitor.caller->GetDeclaringClass()); } // Returns true if the first non-ClassClass caller up the stack is not allowed to @@ -90,7 +90,7 @@ static bool IsCallerInBootClassPath(Thread* self) REQUIRES_SHARED(Locks::mutator ALWAYS_INLINE static bool ShouldEnforceHiddenApi(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { hiddenapi::EnforcementPolicy policy = Runtime::Current()->GetHiddenApiEnforcementPolicy(); - return policy != hiddenapi::EnforcementPolicy::kNoChecks && !IsCallerInBootClassPath(self); + return policy != hiddenapi::EnforcementPolicy::kNoChecks && !IsCallerInPlatformDex(self); } // Returns true if the first non-ClassClass caller up the stack should not be @@ -99,7 +99,7 @@ template ALWAYS_INLINE static bool ShouldBlockAccessToMember(T* member, Thread* self) REQUIRES_SHARED(Locks::mutator_lock_) { return hiddenapi::ShouldBlockAccessToMember( - member, self, IsCallerInBootClassPath, hiddenapi::kReflection); + member, self, IsCallerInPlatformDex, hiddenapi::kReflection); } // Returns true if a class member should be discoverable with reflection given -- cgit v1.2.3-59-g8ed1b