[RESTRICT AUTOMERGE] Pass correct realCallingUid to startActivity() if provided by PendingIntentRecord#sendInner()

Previously we'd ignore realCallingPid and realCallingUid that
PendingIntentRecord#sendInner() provided to startActivityInPackage().
Now we correctly pass it on, preserving past behaviour if none
provided.

Test: manual; we added logging statements to check the value of realCallingUid
in startActivitiesMayWait when launching the calendar app from the calendar widget
and verified that it was the calendar uid rather than the system uid.

Bug: 123013720
Change-Id: I0ef42c2f89b537a720f1ad5aefac756b0ccac52e
Merged-In: I0ef42c2f89b537a720f1ad5aefac756b0ccac52e
This commit is contained in:
Bryan Ferris
2019-05-21 12:38:19 -07:00
parent 46c0bc9407
commit 13a804ee27
3 changed files with 55 additions and 11 deletions

View File

@@ -4891,9 +4891,9 @@ public class ActivityManagerService extends IActivityManager.Stub
userId, false, ALLOW_FULL_ONLY, "startActivityInPackage", null); userId, false, ALLOW_FULL_ONLY, "startActivityInPackage", null);
// TODO: Switch to user app stacks here. // TODO: Switch to user app stacks here.
int ret = mActivityStarter.startActivityMayWait(null, uid, callingPackage, intent, int ret = mActivityStarter.startActivityMayWait(null, uid, ActivityStarter.PID_NULL, uid,
resolvedType, null, null, resultTo, resultWho, requestCode, startFlags, callingPackage, intent, resolvedType, null, null, resultTo, resultWho, requestCode,
null, null, null, bOptions, false, userId, container, inTask, reason); startFlags, null, null, null, bOptions, false, userId, container, inTask, reason);
return ret; return ret;
} }
@@ -4914,13 +4914,20 @@ public class ActivityManagerService extends IActivityManager.Stub
final int startActivitiesInPackage(int uid, String callingPackage, final int startActivitiesInPackage(int uid, String callingPackage,
Intent[] intents, String[] resolvedTypes, IBinder resultTo, Intent[] intents, String[] resolvedTypes, IBinder resultTo,
Bundle bOptions, int userId) { Bundle bOptions, int userId) {
return startActivitiesInPackage(uid, ActivityStarter.PID_NULL, UserHandle.USER_NULL,
callingPackage, intents, resolvedTypes, resultTo, bOptions, userId);
}
final int startActivitiesInPackage(int uid, int realCallingPid, int realCallingUid,
String callingPackage, Intent[] intents, String[] resolvedTypes,
IBinder resultTo, Bundle bOptions, int userId) {
final String reason = "startActivityInPackage"; final String reason = "startActivityInPackage";
userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
userId, false, ALLOW_FULL_ONLY, reason, null); userId, false, ALLOW_FULL_ONLY, reason, null);
// TODO: Switch to user app stacks here. // TODO: Switch to user app stacks here.
int ret = mActivityStarter.startActivities(null, uid, callingPackage, intents, resolvedTypes, int ret = mActivityStarter.startActivities(null, uid, realCallingPid, realCallingUid,
resultTo, bOptions, userId, reason); callingPackage, intents, resolvedTypes, resultTo, bOptions, userId, reason);
return ret; return ret;
} }

View File

@@ -138,6 +138,8 @@ import java.util.Date;
* an activity and associated task and stack. * an activity and associated task and stack.
*/ */
class ActivityStarter { class ActivityStarter {
public static final int PID_NULL = 0;
private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStarter" : TAG_AM; private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStarter" : TAG_AM;
private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS; private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS;
private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS; private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS;
@@ -675,6 +677,20 @@ class ActivityStarter {
ProfilerInfo profilerInfo, WaitResult outResult, ProfilerInfo profilerInfo, WaitResult outResult,
Configuration globalConfig, Bundle bOptions, boolean ignoreTargetSecurity, int userId, Configuration globalConfig, Bundle bOptions, boolean ignoreTargetSecurity, int userId,
IActivityContainer iContainer, TaskRecord inTask, String reason) { IActivityContainer iContainer, TaskRecord inTask, String reason) {
return startActivityMayWait(caller, callingUid, PID_NULL, UserHandle.USER_NULL,
callingPackage, intent, resolvedType, voiceSession, voiceInteractor, resultTo,
resultWho, requestCode, startFlags, profilerInfo, outResult, globalConfig, bOptions,
ignoreTargetSecurity, userId, iContainer, inTask, reason);
}
final int startActivityMayWait(IApplicationThread caller, int callingUid,
int requestRealCallingPid, int requestRealCallingUid,
String callingPackage, Intent intent, String resolvedType,
IVoiceInteractionSession voiceSession, IVoiceInteractor voiceInteractor,
IBinder resultTo, String resultWho, int requestCode, int startFlags,
ProfilerInfo profilerInfo, WaitResult outResult,
Configuration globalConfig, Bundle bOptions, boolean ignoreTargetSecurity, int userId,
IActivityContainer iContainer, TaskRecord inTask, String reason) {
// Refuse possible leaked file descriptors // Refuse possible leaked file descriptors
if (intent != null && intent.hasFileDescriptors()) { if (intent != null && intent.hasFileDescriptors()) {
throw new IllegalArgumentException("File descriptors passed in Intent"); throw new IllegalArgumentException("File descriptors passed in Intent");
@@ -735,8 +751,14 @@ class ActivityStarter {
// Cannot start a child activity if the parent is not resumed. // Cannot start a child activity if the parent is not resumed.
return ActivityManager.START_CANCELED; return ActivityManager.START_CANCELED;
} }
final int realCallingPid = Binder.getCallingPid();
final int realCallingUid = Binder.getCallingUid(); final int realCallingPid = requestRealCallingPid != PID_NULL
? requestRealCallingPid
: Binder.getCallingPid();
final int realCallingUid = requestRealCallingUid != UserHandle.USER_NULL
? requestRealCallingUid
: Binder.getCallingUid();
int callingPid; int callingPid;
if (callingUid >= 0) { if (callingUid >= 0) {
callingPid = -1; callingPid = -1;
@@ -747,6 +769,7 @@ class ActivityStarter {
callingPid = callingUid = -1; callingPid = callingUid = -1;
} }
final ActivityStack stack; final ActivityStack stack;
if (container == null || container.mStack.isOnHomeDisplay()) { if (container == null || container.mStack.isOnHomeDisplay()) {
stack = mSupervisor.mFocusedStack; stack = mSupervisor.mFocusedStack;
@@ -893,6 +916,14 @@ class ActivityStarter {
final int startActivities(IApplicationThread caller, int callingUid, String callingPackage, final int startActivities(IApplicationThread caller, int callingUid, String callingPackage,
Intent[] intents, String[] resolvedTypes, IBinder resultTo, Intent[] intents, String[] resolvedTypes, IBinder resultTo,
Bundle bOptions, int userId, String reason) { Bundle bOptions, int userId, String reason) {
return startActivities(caller, callingUid, PID_NULL, UserHandle.USER_NULL, callingPackage,
intents, resolvedTypes, resultTo, bOptions, userId, reason);
}
final int startActivities(IApplicationThread caller, int callingUid,
int incomingRealCallingPid, int incomingRealCallingUid, String callingPackage,
Intent[] intents, String[] resolvedTypes, IBinder resultTo,
Bundle bOptions, int userId, String reason) {
if (intents == null) { if (intents == null) {
throw new NullPointerException("intents is null"); throw new NullPointerException("intents is null");
} }
@@ -903,8 +934,13 @@ class ActivityStarter {
throw new IllegalArgumentException("intents are length different than resolvedTypes"); throw new IllegalArgumentException("intents are length different than resolvedTypes");
} }
final int realCallingPid = Binder.getCallingPid(); final int realCallingPid = incomingRealCallingPid != PID_NULL
final int realCallingUid = Binder.getCallingUid(); ? incomingRealCallingPid
: Binder.getCallingPid();
final int realCallingUid = incomingRealCallingUid != UserHandle.USER_NULL
? incomingRealCallingUid
: Binder.getCallingUid();
int callingPid; int callingPid;
if (callingUid >= 0) { if (callingUid >= 0) {

View File

@@ -341,8 +341,9 @@ final class PendingIntentRecord extends IIntentSender.Stub {
} }
allIntents[allIntents.length-1] = finalIntent; allIntents[allIntents.length-1] = finalIntent;
allResolvedTypes[allResolvedTypes.length-1] = resolvedType; allResolvedTypes[allResolvedTypes.length-1] = resolvedType;
owner.startActivitiesInPackage(uid, key.packageName, allIntents, owner.startActivitiesInPackage(uid, callingPid, callingUid,
allResolvedTypes, resultTo, options, userId); key.packageName, allIntents, allResolvedTypes, resultTo,
options, userId);
} else { } else {
owner.startActivityInPackage(uid, key.packageName, finalIntent, owner.startActivityInPackage(uid, key.packageName, finalIntent,
resolvedType, resultTo, resultWho, requestCode, 0, resolvedType, resultTo, resultWho, requestCode, 0,