@@ -3024,6 +3024,22 @@ private void enforceAllowedToStartOrBindServiceIfSdkSandbox(Intent intent) {
30243024 }
30253025 }
30263026
3027+ /**
3028+ * Enforces that the uid of the caller matches the uid of the package.
3029+ *
3030+ * @param packageName the name of the package to match uid against.
3031+ * @param callingUid the uid of the caller.
3032+ * @throws SecurityException if the calling uid doesn't match uid of the package.
3033+ */
3034+ private void enforceCallingPackage(String packageName, int callingUid) {
3035+ final int userId = UserHandle.getUserId(callingUid);
3036+ final int packageUid = getPackageManagerInternal().getPackageUid(packageName,
3037+ /*flags=*/ 0, userId);
3038+ if (packageUid != callingUid) {
3039+ throw new SecurityException(packageName + " does not belong to uid " + callingUid);
3040+ }
3041+ }
3042+
30273043 @Override
30283044 public void setPackageScreenCompatMode(String packageName, int mode) {
30293045 mActivityTaskManager.setPackageScreenCompatMode(packageName, mode);
@@ -12994,13 +13010,16 @@ private void clearPendingBackup(int userId) {
1299413010 // A backup agent has just come up
1299513011 @Override
1299613012 public void backupAgentCreated(String agentPackageName, IBinder agent, int userId) {
13013+ final int callingUid = Binder.getCallingUid();
13014+ enforceCallingPackage(agentPackageName, callingUid);
13015+
1299713016 // Resolve the target user id and enforce permissions.
12998- userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid() ,
13017+ userId = mUserController.handleIncomingUser(Binder.getCallingPid(), callingUid ,
1299913018 userId, /* allowAll */ false, ALLOW_FULL_ONLY, "backupAgentCreated", null);
1300013019 if (DEBUG_BACKUP) {
1300113020 Slog.v(TAG_BACKUP, "backupAgentCreated: " + agentPackageName + " = " + agent
1300213021 + " callingUserId = " + UserHandle.getCallingUserId() + " userId = " + userId
13003- + " callingUid = " + Binder.getCallingUid() + " uid = " + Process.myUid());
13022+ + " callingUid = " + callingUid + " uid = " + Process.myUid());
1300413023 }
1300513024
1300613025 synchronized(this) {
0 commit comments