Skip to content

Commit a16f46f

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:ff4b0f29e5bcaea805fd5106c8f6353cdc92123d) Merged-In: I9f3ae5ec0b8f00e020d471cc0eddf8bd8bdbb82d Change-Id: I9f3ae5ec0b8f00e020d471cc0eddf8bd8bdbb82d
1 parent 248bde5 commit a16f46f

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
@@ -2982,6 +2982,22 @@ private void enforceAllowedToStartOrBindServiceIfSdkSandbox(Intent intent) {
29822982
}
29832983
}
29842984

2985+
/**
2986+
* Enforces that the uid of the caller matches the uid of the package.
2987+
*
2988+
* @param packageName the name of the package to match uid against.
2989+
* @param callingUid the uid of the caller.
2990+
* @throws SecurityException if the calling uid doesn't match uid of the package.
2991+
*/
2992+
private void enforceCallingPackage(String packageName, int callingUid) {
2993+
final int userId = UserHandle.getUserId(callingUid);
2994+
final int packageUid = getPackageManagerInternal().getPackageUid(packageName,
2995+
/*flags=*/ 0, userId);
2996+
if (packageUid != callingUid) {
2997+
throw new SecurityException(packageName + " does not belong to uid " + callingUid);
2998+
}
2999+
}
3000+
29853001
@Override
29863002
public void setPackageScreenCompatMode(String packageName, int mode) {
29873003
mActivityTaskManager.setPackageScreenCompatMode(packageName, mode);
@@ -12951,13 +12967,16 @@ private void clearPendingBackup(int userId) {
1295112967
// A backup agent has just come up
1295212968
@Override
1295312969
public void backupAgentCreated(String agentPackageName, IBinder agent, int userId) {
12970+
final int callingUid = Binder.getCallingUid();
12971+
enforceCallingPackage(agentPackageName, callingUid);
12972+
1295412973
// Resolve the target user id and enforce permissions.
12955-
userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
12974+
userId = mUserController.handleIncomingUser(Binder.getCallingPid(), callingUid,
1295612975
userId, /* allowAll */ false, ALLOW_FULL_ONLY, "backupAgentCreated", null);
1295712976
if (DEBUG_BACKUP) {
1295812977
Slog.v(TAG_BACKUP, "backupAgentCreated: " + agentPackageName + " = " + agent
1295912978
+ " callingUserId = " + UserHandle.getCallingUserId() + " userId = " + userId
12960-
+ " callingUid = " + Binder.getCallingUid() + " uid = " + Process.myUid());
12979+
+ " callingUid = " + callingUid + " uid = " + Process.myUid());
1296112980
}
1296212981

1296312982
synchronized(this) {

0 commit comments

Comments
 (0)