[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 Change-Id: I9f3ae5ec0b8f00e020d471cc0eddf8bd8bdbb82d
This commit is contained in:
@@ -2982,6 +2982,22 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforces that the uid of the caller matches the uid of the package.
|
||||||
|
*
|
||||||
|
* @param packageName the name of the package to match uid against.
|
||||||
|
* @param callingUid the uid of the caller.
|
||||||
|
* @throws SecurityException if the calling uid doesn't match uid of the package.
|
||||||
|
*/
|
||||||
|
private void enforceCallingPackage(String packageName, int callingUid) {
|
||||||
|
final int userId = UserHandle.getUserId(callingUid);
|
||||||
|
final int packageUid = getPackageManagerInternal().getPackageUid(packageName,
|
||||||
|
/*flags=*/ 0, userId);
|
||||||
|
if (packageUid != callingUid) {
|
||||||
|
throw new SecurityException(packageName + " does not belong to uid " + callingUid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPackageScreenCompatMode(String packageName, int mode) {
|
public void setPackageScreenCompatMode(String packageName, int mode) {
|
||||||
mActivityTaskManager.setPackageScreenCompatMode(packageName, mode);
|
mActivityTaskManager.setPackageScreenCompatMode(packageName, mode);
|
||||||
@@ -12951,13 +12967,16 @@ public class ActivityManagerService extends IActivityManager.Stub
|
|||||||
// A backup agent has just come up
|
// A backup agent has just come up
|
||||||
@Override
|
@Override
|
||||||
public void backupAgentCreated(String agentPackageName, IBinder agent, int userId) {
|
public void backupAgentCreated(String agentPackageName, IBinder agent, int userId) {
|
||||||
|
final int callingUid = Binder.getCallingUid();
|
||||||
|
enforceCallingPackage(agentPackageName, callingUid);
|
||||||
|
|
||||||
// Resolve the target user id and enforce permissions.
|
// Resolve the target user id and enforce permissions.
|
||||||
userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
|
userId = mUserController.handleIncomingUser(Binder.getCallingPid(), callingUid,
|
||||||
userId, /* allowAll */ false, ALLOW_FULL_ONLY, "backupAgentCreated", null);
|
userId, /* allowAll */ false, ALLOW_FULL_ONLY, "backupAgentCreated", null);
|
||||||
if (DEBUG_BACKUP) {
|
if (DEBUG_BACKUP) {
|
||||||
Slog.v(TAG_BACKUP, "backupAgentCreated: " + agentPackageName + " = " + agent
|
Slog.v(TAG_BACKUP, "backupAgentCreated: " + agentPackageName + " = " + agent
|
||||||
+ " callingUserId = " + UserHandle.getCallingUserId() + " userId = " + userId
|
+ " callingUserId = " + UserHandle.getCallingUserId() + " userId = " + userId
|
||||||
+ " callingUid = " + Binder.getCallingUid() + " uid = " + Process.myUid());
|
+ " callingUid = " + callingUid + " uid = " + Process.myUid());
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized(this) {
|
synchronized(this) {
|
||||||
|
|||||||
Reference in New Issue
Block a user