Update taskAffinity with application uid.
F365d3a8e, Limit Activity taskAffinity to application uid for security vulnerability issue. It modifies the taskAffinity during ActivityRecord created, but the format of taskAffinity is also compared in shouldUpRecreateTaskLocked. AppCompactActivity uses this function to judge if it should recreate the task when navigating up or not. The CL update taskAffinity format with application uid to align above changed. Bug: 153390756 Fixes: 153570741 Test: atest ActivityStackTests ActivityTaskAffinityTests Change-Id: I6a5c062d4869fbda46ae70096ee1d2be7140efe5
This commit is contained in:
@@ -1609,13 +1609,9 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
||||
hasBeenLaunched = false;
|
||||
mStackSupervisor = supervisor;
|
||||
|
||||
// b/35954083: Limit task affinity to uid to avoid various issues associated with sharing
|
||||
// affinity across uids.
|
||||
final String uid = Integer.toString(info.applicationInfo.uid);
|
||||
if (info.taskAffinity != null && !info.taskAffinity.startsWith(uid)) {
|
||||
info.taskAffinity = uid + ":" + info.taskAffinity;
|
||||
}
|
||||
info.taskAffinity = getTaskAffinityWithUid(info.taskAffinity, info.applicationInfo.uid);
|
||||
taskAffinity = info.taskAffinity;
|
||||
final String uid = Integer.toString(info.applicationInfo.uid);
|
||||
if (info.windowLayout != null && info.windowLayout.windowLayoutAffinity != null
|
||||
&& !info.windowLayout.windowLayoutAffinity.startsWith(uid)) {
|
||||
info.windowLayout.windowLayoutAffinity =
|
||||
@@ -1673,6 +1669,22 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the task affinity with uid. For b/35954083, Limit task affinity to uid to avoid
|
||||
* issues associated with sharing affinity across uids.
|
||||
*
|
||||
* @param affinity The affinity of the activity.
|
||||
* @param uid The user-ID that has been assigned to this application.
|
||||
* @return The task affinity with uid.
|
||||
*/
|
||||
static String getTaskAffinityWithUid(String affinity, int uid) {
|
||||
final String uidStr = Integer.toString(uid);
|
||||
if (affinity != null && !affinity.startsWith(uidStr)) {
|
||||
affinity = uidStr + ":" + affinity;
|
||||
}
|
||||
return affinity;
|
||||
}
|
||||
|
||||
static int getLockTaskLaunchMode(ActivityInfo aInfo, @Nullable ActivityOptions options) {
|
||||
int lockTaskLaunchMode = aInfo.lockTaskLaunchMode;
|
||||
if (aInfo.applicationInfo.isPrivilegedApp()
|
||||
|
||||
@@ -2373,8 +2373,10 @@ class ActivityStack extends Task {
|
||||
boolean shouldUpRecreateTaskLocked(ActivityRecord srec, String destAffinity) {
|
||||
// Basic case: for simple app-centric recents, we need to recreate
|
||||
// the task if the affinity has changed.
|
||||
|
||||
final String affinity = ActivityRecord.getTaskAffinityWithUid(destAffinity, srec.getUid());
|
||||
if (srec == null || srec.getTask().affinity == null
|
||||
|| !srec.getTask().affinity.equals(destAffinity)) {
|
||||
|| !srec.getTask().affinity.equals(affinity)) {
|
||||
return true;
|
||||
}
|
||||
// Document-centric case: an app may be split in to multiple documents;
|
||||
|
||||
@@ -66,6 +66,7 @@ import android.app.ActivityManager;
|
||||
import android.app.IApplicationThread;
|
||||
import android.content.ComponentName;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Binder;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
|
||||
@@ -1290,6 +1291,27 @@ public class ActivityStackTests extends ActivityTestsBase {
|
||||
assertEquals(starter.mRequest.callingUid, secondActivity.getUid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldUpRecreateTaskLockedWithCorrectAffinityFormat() {
|
||||
final String affinity = "affinity";
|
||||
final ActivityRecord activity = new ActivityBuilder(mService).setAffinity(affinity)
|
||||
.setUid(Binder.getCallingUid()).setCreateTask(true).build();
|
||||
activity.getTask().affinity = activity.taskAffinity;
|
||||
|
||||
assertFalse(mStack.shouldUpRecreateTaskLocked(activity, affinity));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldUpRecreateTaskLockedWithWrongAffinityFormat() {
|
||||
final String affinity = "affinity";
|
||||
final ActivityRecord activity = new ActivityBuilder(mService).setAffinity(affinity)
|
||||
.setUid(Binder.getCallingUid()).setCreateTask(true).build();
|
||||
activity.getTask().affinity = activity.taskAffinity;
|
||||
final String fakeAffinity = activity.getUid() + activity.taskAffinity;
|
||||
|
||||
assertTrue(mStack.shouldUpRecreateTaskLocked(activity, fakeAffinity));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResetTaskWithFinishingActivities() {
|
||||
final ActivityRecord taskTop =
|
||||
|
||||
@@ -108,6 +108,7 @@ class ActivityTestsBase extends SystemServiceTestsBase {
|
||||
private String mTargetActivity;
|
||||
private Task mTask;
|
||||
private String mProcessName = "name";
|
||||
private String mAffinity;
|
||||
private int mUid = 12345;
|
||||
private boolean mCreateTask;
|
||||
private ActivityStack mStack;
|
||||
@@ -222,6 +223,11 @@ class ActivityTestsBase extends SystemServiceTestsBase {
|
||||
return this;
|
||||
}
|
||||
|
||||
ActivityBuilder setAffinity(String affinity) {
|
||||
mAffinity = affinity;
|
||||
return this;
|
||||
}
|
||||
|
||||
ActivityRecord build() {
|
||||
try {
|
||||
mService.deferWindowLayout();
|
||||
@@ -270,6 +276,7 @@ class ActivityTestsBase extends SystemServiceTestsBase {
|
||||
aInfo.maxAspectRatio = mMaxAspectRatio;
|
||||
aInfo.screenOrientation = mScreenOrientation;
|
||||
aInfo.configChanges |= mConfigChanges;
|
||||
aInfo.taskAffinity = mAffinity;
|
||||
|
||||
ActivityOptions options = null;
|
||||
if (mLaunchTaskBehind) {
|
||||
|
||||
Reference in New Issue
Block a user