Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e87848e authored by Winson's avatar Winson Committed by Vasyl Gello
Browse files

DO NOT MERGE: Verify INSTALL_PACKAGES permissions when adding installer package



Without this check, any package can set the installer package of
another package whose installer has been removed or was never set.
This provides access to other privileged actions and is undesired.

Bug: 150857253

Test: manual verify with proof of concept in linked bug
Test: atest android.appsecurity.cts.PackageSetInstallerTest

[basilgello: Backport to 14.1:
 - callingUid -> Binder.getCallingUid()]
Signed-off-by: default avatarVasyl Gello <vasek.gello@gmail.com>

Change-Id: I2159c357911ff39ffd819054b42f96ae86bc98bc
(cherry picked from commit fc8bfed5)
parent c3ad6422
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -12593,20 +12593,26 @@ public class PackageManagerService extends IPackageManager.Stub {
            // Verify: if target already has an installer package, it must
            // be signed with the same cert as the caller.
            if (targetPackageSetting.installerPackageName != null) {
                PackageSetting setting = mSettings.mPackages.get(
                        targetPackageSetting.installerPackageName);
                // If the currently set package isn't valid, then it's always
                // okay to change it.
                if (setting != null) {
            String targetInstallerPackageName =
                    targetPackageSetting.installerPackageName;
            PackageSetting targetInstallerPkgSetting = targetInstallerPackageName == null ? null :
                    mSettings.mPackages.get(targetInstallerPackageName);
            if (targetInstallerPkgSetting != null) {
                if (compareSignatures(callerSignature,
                            setting.signatures.mSignatures)
                        targetInstallerPkgSetting.signatures.mSignatures)
                        != PackageManager.SIGNATURE_MATCH) {
                    throw new SecurityException(
                            "Caller does not have same cert as old installer package "
                                + targetPackageSetting.installerPackageName);
                    }
                                    + targetInstallerPackageName);
                }
            } else if (mContext.checkCallingOrSelfPermission(Manifest.permission.INSTALL_PACKAGES)
                    != PackageManager.PERMISSION_GRANTED) {
                // This is probably an attempt to exploit vulnerability b/150857253 of taking
                // privileged installer permissions when the installer has been uninstalled or
                // was never set.
                EventLog.writeEvent(0x534e4554, "150857253", Binder.getCallingUid(), "");
                return;
            }
            // Okay!