From 36e16b2e947e73e95b903cdae4025af15dc988cb Mon Sep 17 00:00:00 2001 From: Zim Date: Fri, 31 Jan 2020 13:28:13 +0000 Subject: [PATCH] Restrict access_mtp permission access to Android/ Ensure only platform signed apps holding the access_mtp permission can access the sensitive Android/ TODO: On devices without sdcardfs, will also need to give the two new ext_data_rw and ext_obb_rw gids to these processes. May need to do same for apps with pass_through mount mode as well Test: MTP app still has sdcard_rw Bug: 148555237 Change-Id: I140a2ffec8a5887c7cd25d6976ee19555f2a47c1 --- .../java/com/android/server/StorageManagerService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java index a04f25b0d20c6..ffdaa65eb91a4 100644 --- a/services/core/java/com/android/server/StorageManagerService.java +++ b/services/core/java/com/android/server/StorageManagerService.java @@ -3941,8 +3941,12 @@ class StorageManagerService extends IStorageManager.Stub final boolean hasMtp = mIPackageManager.checkUidPermission(ACCESS_MTP, uid) == PERMISSION_GRANTED; if (mIsFuseEnabled && hasMtp) { - // The process hosting the MTP server should be able to write in Android/ - return Zygote.MOUNT_EXTERNAL_ANDROID_WRITABLE; + ApplicationInfo ai = mIPackageManager.getApplicationInfo(packageName, + 0, UserHandle.getUserId(uid)); + if (ai.isSignedWithPlatformKey()) { + // Platform processes hosting the MTP server should be able to write in Android/ + return Zygote.MOUNT_EXTERNAL_ANDROID_WRITABLE; + } } // Determine if caller is holding runtime permission