Skip to content

Commit 3e7694c

Browse files
Christopher Tateandi34
authored andcommitted
DO NOT MERGE: Don't trust callers to supply app info to bindBackupAgent()
Get the canonical identity and metadata about the package from the Package Manager at time of usage rather than rely on the caller to have gotten things right, even when the caller has the system uid. Bug 28795098 Change-Id: I62710b15bb601fdfedd68e32349168c10725eb45 (cherry picked from commit d85a4ed)
1 parent ce65785 commit 3e7694c

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

core/java/android/app/ActivityManagerNative.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,9 +1434,10 @@ public boolean onTransact(int code, Parcel data, Parcel reply, int flags)
14341434

14351435
case START_BACKUP_AGENT_TRANSACTION: {
14361436
data.enforceInterface(IActivityManager.descriptor);
1437-
ApplicationInfo info = ApplicationInfo.CREATOR.createFromParcel(data);
1437+
String packageName = data.readString();
14381438
int backupRestoreMode = data.readInt();
1439-
boolean success = bindBackupAgent(info, backupRestoreMode);
1439+
int userId = data.readInt();
1440+
boolean success = bindBackupAgent(packageName, backupRestoreMode, userId);
14401441
reply.writeNoException();
14411442
reply.writeInt(success ? 1 : 0);
14421443
return true;
@@ -3125,13 +3126,14 @@ public IBinder peekService(Intent service, String resolvedType) throws RemoteExc
31253126
return binder;
31263127
}
31273128

3128-
public boolean bindBackupAgent(ApplicationInfo app, int backupRestoreMode)
3129+
public boolean bindBackupAgent(String packageName, int backupRestoreMode, int userId)
31293130
throws RemoteException {
31303131
Parcel data = Parcel.obtain();
31313132
Parcel reply = Parcel.obtain();
31323133
data.writeInterfaceToken(IActivityManager.descriptor);
3133-
app.writeToParcel(data, 0);
3134+
data.writeString(packageName);
31343135
data.writeInt(backupRestoreMode);
3136+
data.writeInt(userId);
31353137
mRemote.transact(START_BACKUP_AGENT_TRANSACTION, data, reply, 0);
31363138
reply.readException();
31373139
boolean success = reply.readInt() != 0;

core/java/android/app/IActivityManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public void serviceDoneExecuting(IBinder token, int type, int startId,
163163
int res) throws RemoteException;
164164
public IBinder peekService(Intent service, String resolvedType) throws RemoteException;
165165

166-
public boolean bindBackupAgent(ApplicationInfo appInfo, int backupRestoreMode)
166+
public boolean bindBackupAgent(String packageName, int backupRestoreMode, int userId)
167167
throws RemoteException;
168168
public void clearPendingBackup() throws RemoteException;
169169
public void backupAgentCreated(String packageName, IBinder agent) throws RemoteException;

services/java/com/android/server/BackupManagerService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,8 @@ IBackupAgent bindToAgentSynchronous(ApplicationInfo app, int mode) {
17801780
mConnecting = true;
17811781
mConnectedAgent = null;
17821782
try {
1783-
if (mActivityManager.bindBackupAgent(app, mode)) {
1783+
if (mActivityManager.bindBackupAgent(app.packageName, mode,
1784+
UserHandle.USER_OWNER)) {
17841785
Slog.d(TAG, "awaiting agent for " + app);
17851786

17861787
// success; wait for the agent to arrive

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12823,10 +12823,22 @@ public void serviceDoneExecuting(IBinder token, int type, int startId, int res)
1282312823
// Cause the target app to be launched if necessary and its backup agent
1282412824
// instantiated. The backup agent will invoke backupAgentCreated() on the
1282512825
// activity manager to announce its creation.
12826-
public boolean bindBackupAgent(ApplicationInfo app, int backupMode) {
12827-
if (DEBUG_BACKUP) Slog.v(TAG, "bindBackupAgent: app=" + app + " mode=" + backupMode);
12826+
public boolean bindBackupAgent(String packageName, int backupMode, int userId) {
12827+
if (DEBUG_BACKUP) Slog.v(TAG, "bindBackupAgent: app=" + packageName + " mode=" + backupMode);
1282812828
enforceCallingPermission("android.permission.CONFIRM_FULL_BACKUP", "bindBackupAgent");
1282912829

12830+
IPackageManager pm = AppGlobals.getPackageManager();
12831+
ApplicationInfo app = null;
12832+
try {
12833+
app = pm.getApplicationInfo(packageName, 0, userId);
12834+
} catch (RemoteException e) {
12835+
// can't happen; package manager is process-local
12836+
}
12837+
if (app == null) {
12838+
Slog.w(TAG, "Unable to bind backup agent for " + packageName);
12839+
return false;
12840+
}
12841+
1283012842
synchronized(this) {
1283112843
// !!! TODO: currently no check here that we're already bound
1283212844
BatteryStatsImpl.Uid.Pkg.Serv ss = null;

0 commit comments

Comments
 (0)