[pm] prevent non-debuggable app downgrades via shell

Downgrade can only be performed if the following conditions are met:

1. Downgrade is requested in the installFlags
2a. App is debuggable
Or 2b: If app is not debuggable, the build is debuggable or the calling
uid is system or root.

This means shell can't downgrade a non-debuggable app on a non-debuggable build.

BUG: 256202273
Test: manual
Change-Id: I841878502eaa9574e98a38a77e73352fd9735677
This commit is contained in:
Songchun Fan
2023-01-27 16:23:23 -08:00
parent 729d0a62be
commit 435c8fe2f8

View File

@@ -705,7 +705,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
}
}
if (Build.IS_DEBUGGABLE || isCalledBySystemOrShell(callingUid)) {
if (Build.IS_DEBUGGABLE || isCalledBySystem(callingUid)) {
params.installFlags |= PackageManager.INSTALL_ALLOW_DOWNGRADE;
} else {
params.installFlags &= ~PackageManager.INSTALL_ALLOW_DOWNGRADE;
@@ -906,6 +906,10 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
return sessionId;
}
private static boolean isCalledBySystem(int callingUid) {
return callingUid == Process.SYSTEM_UID || callingUid == Process.ROOT_UID;
}
private boolean isCalledBySystemOrShell(int callingUid) {
return callingUid == Process.SYSTEM_UID || callingUid == Process.ROOT_UID
|| callingUid == Process.SHELL_UID;