Skip to content

Commit 935eb5e

Browse files
piee199Android Build Coastguard Worker
authored andcommitted
[DO NOT MERGE] Check caller's uid in backupAgentCreated callback
AM.backupAgentCreated() should enforce that caller belongs the package called in the API. Bug: 289549315 Test: atest android.security.cts.ActivityManagerTest#testActivityManager_backupAgentCreated_rejectIfCallerUidNotEqualsPackageUid (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c31434d6a097f815e8daec899ba92348487cbfac) Merged-In: I9f3ae5ec0b8f00e020d471cc0eddf8bd8bdbb82d Change-Id: I9f3ae5ec0b8f00e020d471cc0eddf8bd8bdbb82d
1 parent 08f9c38 commit 935eb5e

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

services/core/java/com/android/server/am/ActivityManagerService.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,6 +2988,22 @@ private void enforceAllowedToStartOrBindServiceIfSdkSandbox(Intent intent) {
29882988
}
29892989
}
29902990

2991+
/**
2992+
* Enforces that the uid of the caller matches the uid of the package.
2993+
*
2994+
* @param packageName the name of the package to match uid against.
2995+
* @param callingUid the uid of the caller.
2996+
* @throws SecurityException if the calling uid doesn't match uid of the package.
2997+
*/
2998+
private void enforceCallingPackage(String packageName, int callingUid) {
2999+
final int userId = UserHandle.getUserId(callingUid);
3000+
final int packageUid = getPackageManagerInternal().getPackageUid(packageName,
3001+
/*flags=*/ 0, userId);
3002+
if (packageUid != callingUid) {
3003+
throw new SecurityException(packageName + " does not belong to uid " + callingUid);
3004+
}
3005+
}
3006+
29913007
@Override
29923008
public void setPackageScreenCompatMode(String packageName, int mode) {
29933009
mActivityTaskManager.setPackageScreenCompatMode(packageName, mode);
@@ -12918,13 +12934,16 @@ private void clearPendingBackup(int userId) {
1291812934
// A backup agent has just come up
1291912935
@Override
1292012936
public void backupAgentCreated(String agentPackageName, IBinder agent, int userId) {
12937+
final int callingUid = Binder.getCallingUid();
12938+
enforceCallingPackage(agentPackageName, callingUid);
12939+
1292112940
// Resolve the target user id and enforce permissions.
12922-
userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
12941+
userId = mUserController.handleIncomingUser(Binder.getCallingPid(), callingUid,
1292312942
userId, /* allowAll */ false, ALLOW_FULL_ONLY, "backupAgentCreated", null);
1292412943
if (DEBUG_BACKUP) {
1292512944
Slog.v(TAG_BACKUP, "backupAgentCreated: " + agentPackageName + " = " + agent
1292612945
+ " callingUserId = " + UserHandle.getCallingUserId() + " userId = " + userId
12927-
+ " callingUid = " + Binder.getCallingUid() + " uid = " + Process.myUid());
12946+
+ " callingUid = " + callingUid + " uid = " + Process.myUid());
1292812947
}
1292912948

1293012949
synchronized(this) {

0 commit comments

Comments
 (0)