Enforce package visibility filters to grantUriPermission()

App can query which applications are installed on the device via
Context#grantUriPermission. This cl enforces package visibility filters
to the api to fix the security issue.

Bug: 207133709
Test: atest AppEnumerationTests
Test: atest ContextTest
Test: atest DownloadManagerTest
Test: atest CtsScopedStorageHostTest
Test: atest CtsScopedStorageDeviceOnlyTest
Test: atest CtsScopedStorageCoreHostTest
Test: atest CtsJobSchedulerSharedUidTestCases
Test: atest SQLiteTest
Test: atest AppSecurityTests
Test: atest CtsMediaProviderTranscodeTests
Test: atest ExternalStorageHostTest
Change-Id: Ic8ed5f2fb46b8de605bd091a2a62d8070e28a1eb
This commit is contained in:
Rhed Jao
2021-12-15 14:35:06 +08:00
parent b77d15fc92
commit abc1ce5ba2

View File

@@ -5913,6 +5913,10 @@ public class ActivityManagerService extends IActivityManager.Stub
if (targetPkg == null) {
throw new IllegalArgumentException("null target");
}
final int callingUserId = UserHandle.getUserId(r.uid);
if (mPackageManagerInt.filterAppAccess(targetPkg, r.uid, callingUserId)) {
return;
}
Preconditions.checkFlagsArgument(modeFlags, Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
@@ -5924,7 +5928,7 @@ public class ActivityManagerService extends IActivityManager.Stub
intent.setFlags(modeFlags);
final NeededUriGrants needed = mUgmInternal.checkGrantUriPermissionFromIntent(intent,
r.uid, targetPkg, UserHandle.getUserId(r.uid));
r.uid, targetPkg, callingUserId);
mUgmInternal.grantUriPermissionUncheckedFromIntent(needed, null);
}
}