From: Jeff Sharkey Date: Wed, 2 Nov 2016 21:26:01 +0000 (-0600) Subject: Public volumes belong to a single user. X-Git-Tag: android-x86-7.1-r1~41^2~20^2~2^2~3^2~5^2~1^2~21^2 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=6b0079d3bc;p=android-x86%2Fframeworks-base.git Public volumes belong to a single user. When a public (vfat) device is inserted, it's strongly associated with the current foreground user, and no other users should be able to access it, since otherwise that would be a cross-user data leak. To use the device under a different user, switch users and then eject/remount the device. Test: verified user isolation of USB drive Bug: 32523490 Change-Id: I590c791996f1fea8d78f625dc942d149f1f41614 --- diff --git a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java index 18335b6586a8..d41d0e5b089b 100644 --- a/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java +++ b/packages/ExternalStorageProvider/src/com/android/externalstorage/ExternalStorageProvider.java @@ -135,7 +135,8 @@ public class ExternalStorageProvider extends DocumentsProvider { final VolumeInfo privateVol = mStorageManager.findPrivateForEmulated(volume); title = mStorageManager.getBestVolumeDescription(privateVol); } - } else if (volume.getType() == VolumeInfo.TYPE_PUBLIC) { + } else if (volume.getType() == VolumeInfo.TYPE_PUBLIC + && volume.getMountUserId() == userId) { rootId = volume.getFsUuid(); title = mStorageManager.getBestVolumeDescription(volume); } else { diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java index 5e674145da34..6c33cff693bd 100644 --- a/services/core/java/com/android/server/MountService.java +++ b/services/core/java/com/android/server/MountService.java @@ -169,6 +169,11 @@ class MountService extends IMountService.Stub } @Override + public void onSwitchUser(int userHandle) { + mMountService.mCurrentUserId = userHandle; + } + + @Override public void onStartUser(int userHandle) { mMountService.onStartUser(userHandle); } @@ -307,6 +312,8 @@ class MountService extends IMountService.Stub @GuardedBy("mLock") private String mMoveTargetUuid; + private volatile int mCurrentUserId = UserHandle.USER_OWNER; + private VolumeInfo findVolumeByIdOrThrow(String id) { synchronized (mLock) { final VolumeInfo vol = mVolumes.get(id); @@ -1189,7 +1196,7 @@ class MountService extends IMountService.Stub vol.mountFlags |= VolumeInfo.MOUNT_FLAG_VISIBLE; } - vol.mountUserId = UserHandle.USER_OWNER; + vol.mountUserId = mCurrentUserId; mHandler.obtainMessage(H_VOLUME_MOUNT, vol).sendToTarget(); } else if (vol.type == VolumeInfo.TYPE_PRIVATE) {