Skip to content

Commit e7cf91a

Browse files
Christopher TateThe Android Automerger
authored andcommitted
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: I215786bc894dedf7ca28e9c80cefabd0e40ca877 Merge conflict resolution for ag/1133474 (referencing ag/1148862) - directly to mnc-mr2-release
1 parent 9b8c6d2 commit e7cf91a

4 files changed

Lines changed: 23 additions & 9 deletions

File tree

core/java/android/app/ActivityManagerNative.java

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

15831583
case START_BACKUP_AGENT_TRANSACTION: {
15841584
data.enforceInterface(IActivityManager.descriptor);
1585-
ApplicationInfo info = ApplicationInfo.CREATOR.createFromParcel(data);
1585+
String packageName = data.readString();
15861586
int backupRestoreMode = data.readInt();
1587-
boolean success = bindBackupAgent(info, backupRestoreMode);
1587+
int userId = data.readInt();
1588+
boolean success = bindBackupAgent(packageName, backupRestoreMode, userId);
15881589
reply.writeNoException();
15891590
reply.writeInt(success ? 1 : 0);
15901591
return true;
@@ -3831,13 +3832,14 @@ public IBinder peekService(Intent service, String resolvedType, String callingPa
38313832
return binder;
38323833
}
38333834

3834-
public boolean bindBackupAgent(ApplicationInfo app, int backupRestoreMode)
3835+
public boolean bindBackupAgent(String packageName, int backupRestoreMode, int userId)
38353836
throws RemoteException {
38363837
Parcel data = Parcel.obtain();
38373838
Parcel reply = Parcel.obtain();
38383839
data.writeInterfaceToken(IActivityManager.descriptor);
3839-
app.writeToParcel(data, 0);
3840+
data.writeString(packageName);
38403841
data.writeInt(backupRestoreMode);
3842+
data.writeInt(userId);
38413843
mRemote.transact(START_BACKUP_AGENT_TRANSACTION, data, reply, 0);
38423844
reply.readException();
38433845
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
@@ -182,7 +182,7 @@ public void serviceDoneExecuting(IBinder token, int type, int startId,
182182
public IBinder peekService(Intent service, String resolvedType, String callingPackage)
183183
throws RemoteException;
184184

185-
public boolean bindBackupAgent(ApplicationInfo appInfo, int backupRestoreMode)
185+
public boolean bindBackupAgent(String packageName, int backupRestoreMode, int userId)
186186
throws RemoteException;
187187
public void clearPendingBackup() throws RemoteException;
188188
public void backupAgentCreated(String packageName, IBinder agent) throws RemoteException;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,8 @@ IBackupAgent bindToAgentSynchronous(ApplicationInfo app, int mode) {
22352235
mConnecting = true;
22362236
mConnectedAgent = null;
22372237
try {
2238-
if (mActivityManager.bindBackupAgent(app, mode)) {
2238+
if (mActivityManager.bindBackupAgent(app.packageName, mode,
2239+
UserHandle.USER_OWNER)) {
22392240
Slog.d(TAG, "awaiting agent for " + app);
22402241

22412242
// success; wait for the agent to arrive

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16038,11 +16038,22 @@ public void serviceDoneExecuting(IBinder token, int type, int startId, int res)
1603816038
// Cause the target app to be launched if necessary and its backup agent
1603916039
// instantiated. The backup agent will invoke backupAgentCreated() on the
1604016040
// activity manager to announce its creation.
16041-
public boolean bindBackupAgent(ApplicationInfo app, int backupMode) {
16042-
if (DEBUG_BACKUP) Slog.v(TAG_BACKUP,
16043-
"bindBackupAgent: app=" + app + " mode=" + backupMode);
16041+
public boolean bindBackupAgent(String packageName, int backupMode, int userId) {
16042+
if (DEBUG_BACKUP) Slog.v(TAG, "bindBackupAgent: app=" + packageName + " mode=" + backupMode);
1604416043
enforceCallingPermission("android.permission.CONFIRM_FULL_BACKUP", "bindBackupAgent");
1604516044

16045+
IPackageManager pm = AppGlobals.getPackageManager();
16046+
ApplicationInfo app = null;
16047+
try {
16048+
app = pm.getApplicationInfo(packageName, 0, userId);
16049+
} catch (RemoteException e) {
16050+
// can't happen; package manager is process-local
16051+
}
16052+
if (app == null) {
16053+
Slog.w(TAG, "Unable to bind backup agent for " + packageName);
16054+
return false;
16055+
}
16056+
1604616057
synchronized(this) {
1604716058
// !!! TODO: currently no check here that we're already bound
1604816059
BatteryStatsImpl.Uid.Pkg.Serv ss = null;

0 commit comments

Comments
 (0)