Merge "Ensure calling package name and uid are matched" into sc-qpr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e93efb6f96
@@ -2361,6 +2361,26 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getAppUid(final String app, final UserHandle user) {
|
||||||
|
final PackageManager pm =
|
||||||
|
mContext.createContextAsUser(user, 0 /* flags */).getPackageManager();
|
||||||
|
final long token = Binder.clearCallingIdentity();
|
||||||
|
try {
|
||||||
|
return pm.getPackageUid(app, 0 /* flags */);
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
return -1;
|
||||||
|
} finally {
|
||||||
|
Binder.restoreCallingIdentity(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyCallingUidAndPackage(String packageName, int callingUid) {
|
||||||
|
final UserHandle user = UserHandle.getUserHandleForUid(callingUid);
|
||||||
|
if (getAppUid(packageName, user) != callingUid) {
|
||||||
|
throw new SecurityException(packageName + " does not belong to uid " + callingUid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure that a network route exists to deliver traffic to the specified
|
* Ensure that a network route exists to deliver traffic to the specified
|
||||||
* host via the specified network interface.
|
* host via the specified network interface.
|
||||||
@@ -2376,6 +2396,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
if (disallowedBecauseSystemCaller()) {
|
if (disallowedBecauseSystemCaller()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
verifyCallingUidAndPackage(callingPackageName, mDeps.getCallingUid());
|
||||||
enforceChangePermission(callingPackageName, callingAttributionTag);
|
enforceChangePermission(callingPackageName, callingAttributionTag);
|
||||||
if (mProtectedNetworks.contains(networkType)) {
|
if (mProtectedNetworks.contains(networkType)) {
|
||||||
enforceConnectivityRestrictedNetworksPermission();
|
enforceConnectivityRestrictedNetworksPermission();
|
||||||
|
|||||||
@@ -13941,4 +13941,11 @@ public class ConnectivityServiceTest {
|
|||||||
mDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
mDefaultNetworkCallback.expectCallback(CallbackEntry.LOST, mWiFiNetworkAgent);
|
||||||
mDefaultNetworkCallback.expectAvailableCallbacksValidated(mCellNetworkAgent);
|
mDefaultNetworkCallback.expectAvailableCallbacksValidated(mCellNetworkAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRequestRouteToHostAddress_PackageDoesNotBelongToCaller() {
|
||||||
|
assertThrows(SecurityException.class, () -> mService.requestRouteToHostAddress(
|
||||||
|
ConnectivityManager.TYPE_NONE, null /* hostAddress */, "com.not.package.owner",
|
||||||
|
null /* callingAttributionTag */));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user