From 7623ac966ee0a8fd94925f14527565325ee9dbd8 Mon Sep 17 00:00:00 2001 From: Sumedh Sen Date: Mon, 27 Feb 2023 11:10:47 -0800 Subject: [PATCH] Remove the resolved path of session's APK from user confirmation intent Intent sent to the user for install confirmation includes the resolved path of the session's base apk. A malicious app can modify this path, resulting in the installer activity to show a different app icon and label in the confirmation dialog. To fix this, expose a SystemApi for getting the resolved path and permission protect it with a privileged permission. Bug: 269728874 Test: atest CtsPackageInstallTestCases:SessionTest Change-Id: Ibe7fe3ab5e74e3e910d9f7bd5b6f3f2e3c0ca658 --- core/api/system-current.txt | 3 ++- .../android/content/pm/PackageInstaller.java | 24 ++++++++++--------- core/res/AndroidManifest.xml | 9 +++++++ packages/PackageInstaller/AndroidManifest.xml | 1 + .../PackageInstallerActivity.java | 7 +++--- packages/Shell/AndroidManifest.xml | 3 +++ .../server/pm/PackageInstallerSession.java | 14 +++++------ 7 files changed, 38 insertions(+), 23 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index 41da5eaa77dbc..e0e9139ac500b 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -272,6 +272,7 @@ package android { field public static final String READ_DEVICE_CONFIG = "android.permission.READ_DEVICE_CONFIG"; field public static final String READ_DREAM_STATE = "android.permission.READ_DREAM_STATE"; field public static final String READ_GLOBAL_APP_SEARCH_DATA = "android.permission.READ_GLOBAL_APP_SEARCH_DATA"; + field public static final String READ_INSTALLED_SESSION_PATHS = "android.permission.READ_INSTALLED_SESSION_PATHS"; field public static final String READ_INSTALL_SESSIONS = "android.permission.READ_INSTALL_SESSIONS"; field public static final String READ_NETWORK_USAGE_HISTORY = "android.permission.READ_NETWORK_USAGE_HISTORY"; field public static final String READ_OEM_UNLOCK_STATE = "android.permission.READ_OEM_UNLOCK_STATE"; @@ -3802,7 +3803,6 @@ package android.content.pm { field public static final String EXTRA_CALLBACK = "android.content.pm.extra.CALLBACK"; field public static final String EXTRA_DATA_LOADER_TYPE = "android.content.pm.extra.DATA_LOADER_TYPE"; field public static final String EXTRA_LEGACY_STATUS = "android.content.pm.extra.LEGACY_STATUS"; - field public static final String EXTRA_RESOLVED_BASE_PATH = "android.content.pm.extra.RESOLVED_BASE_PATH"; field public static final int LOCATION_DATA_APP = 0; // 0x0 field public static final int LOCATION_MEDIA_DATA = 2; // 0x2 field public static final int LOCATION_MEDIA_OBB = 1; // 0x1 @@ -3839,6 +3839,7 @@ package android.content.pm { method public boolean getInstallAsVirtualPreload(); method public int getPendingUserActionReason(); method public boolean getRequestDowngrade(); + method @Nullable @RequiresPermission(android.Manifest.permission.READ_INSTALLED_SESSION_PATHS) public String getResolvedBaseApkPath(); method public int getRollbackDataPolicy(); method @NonNull public java.util.Set getWhitelistedRestrictedPermissions(); } diff --git a/core/java/android/content/pm/PackageInstaller.java b/core/java/android/content/pm/PackageInstaller.java index cb988dfdb2039..77d32a5d4fd37 100644 --- a/core/java/android/content/pm/PackageInstaller.java +++ b/core/java/android/content/pm/PackageInstaller.java @@ -333,17 +333,6 @@ public class PackageInstaller { @SystemApi public static final String EXTRA_DATA_LOADER_TYPE = "android.content.pm.extra.DATA_LOADER_TYPE"; - /** - * Path to the validated base APK for this session, which may point at an - * APK inside the session (when the session defines the base), or it may - * point at the existing base APK (when adding splits to an existing app). - * - * @hide - */ - @SystemApi - public static final String EXTRA_RESOLVED_BASE_PATH = - "android.content.pm.extra.RESOLVED_BASE_PATH"; - /** * Streaming installation pending. * Caller should make sure DataLoader is able to prepare image and reinitiate the operation. @@ -3549,6 +3538,19 @@ public class PackageInstaller { return referrerUri; } + /** + * @return the path to the validated base APK for this session, which may point at an + * APK inside the session (when the session defines the base), or it may + * point at the existing base APK (when adding splits to an existing app). + * + * @hide + */ + @SystemApi + @RequiresPermission(Manifest.permission.READ_INSTALLED_SESSION_PATHS) + public @Nullable String getResolvedBaseApkPath() { + return resolvedBaseCodePath; + } + /** * Get the value set in {@link SessionParams#setGrantedRuntimePermissions(String[])}. * diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index 479ea4e7b46ba..239a12637f28c 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -5421,6 +5421,15 @@ + + + + + +