From 2d13d437d01947427feff4a7f55173935604c4e7 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Mon, 13 Mar 2023 12:27:40 +0900 Subject: [PATCH] Clear the CallingIdentity before in the context of property check Using packageManager from ConnectivityService context to get the caller application info in binder calls can cause the permission issue. Calling the Binder.clearCallingIdentity() before interact with packageManager can fix the permission issue. Test: atest CtsHostsideNetworkTests Bug: 272165411 Change-Id: I0a289afc6fb0e42a92aa3ffa0c77ed396c4485c3 --- service/src/com/android/server/ConnectivityService.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/service/src/com/android/server/ConnectivityService.java b/service/src/com/android/server/ConnectivityService.java index 5f519711f3..7cc4d975cd 100755 --- a/service/src/com/android/server/ConnectivityService.java +++ b/service/src/com/android/server/ConnectivityService.java @@ -911,7 +911,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // This is the cache for the packageName -> ApplicationSelfCertifiedNetworkCapabilities. This // value can be accessed from both handler thread and any random binder thread. Therefore, - // accessing this value requires holding a lock. + // accessing this value requires holding a lock. The cache is the same across all the users. @GuardedBy("mSelfCertifiedCapabilityCache") private final Map mSelfCertifiedCapabilityCache = new HashMap<>(); @@ -7001,6 +7001,7 @@ public class ConnectivityService extends IConnectivityManager.Stub return; } ApplicationSelfCertifiedNetworkCapabilities applicationNetworkCapabilities; + final long ident = Binder.clearCallingIdentity(); try { synchronized (mSelfCertifiedCapabilityCache) { applicationNetworkCapabilities = mSelfCertifiedCapabilityCache.get( @@ -7027,6 +7028,8 @@ public class ConnectivityService extends IConnectivityManager.Stub + " property"); } catch (XmlPullParserException | IOException | InvalidTagException e) { throw new SecurityException(e.getMessage()); + } finally { + Binder.restoreCallingIdentity(ident); } applicationNetworkCapabilities.enforceSelfCertifiedNetworkCapabilitiesDeclared(