Enforce DISALLOW_MOUNT_PHYSICAL_MEDIA.
Bug: 22697024 Change-Id: Ib7277e8850a49909e5d8d5ad5502cd9315cddf0b
This commit is contained in:
@@ -146,8 +146,6 @@ import javax.crypto.spec.PBEKeySpec;
|
|||||||
class MountService extends IMountService.Stub
|
class MountService extends IMountService.Stub
|
||||||
implements INativeDaemonConnectorCallbacks, Watchdog.Monitor {
|
implements INativeDaemonConnectorCallbacks, Watchdog.Monitor {
|
||||||
|
|
||||||
// TODO: finish enforcing UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA
|
|
||||||
|
|
||||||
// Static direct instance pointer for the tightly-coupled idle service to use
|
// Static direct instance pointer for the tightly-coupled idle service to use
|
||||||
static MountService sSelf = null;
|
static MountService sSelf = null;
|
||||||
|
|
||||||
@@ -631,6 +629,10 @@ class MountService extends IMountService.Stub
|
|||||||
}
|
}
|
||||||
case H_VOLUME_MOUNT: {
|
case H_VOLUME_MOUNT: {
|
||||||
final VolumeInfo vol = (VolumeInfo) msg.obj;
|
final VolumeInfo vol = (VolumeInfo) msg.obj;
|
||||||
|
if (isMountDisallowed(vol)) {
|
||||||
|
Slog.i(TAG, "Ignoring mount " + vol.getId() + " due to policy");
|
||||||
|
break;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
mConnector.execute("volume", "mount", vol.id, vol.mountFlags,
|
mConnector.execute("volume", "mount", vol.id, vol.mountFlags,
|
||||||
vol.mountUserId);
|
vol.mountUserId);
|
||||||
@@ -1305,10 +1307,16 @@ class MountService extends IMountService.Stub
|
|||||||
mContext.enforceCallingOrSelfPermission(perm, perm);
|
mContext.enforceCallingOrSelfPermission(perm, perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enforceUserRestriction(String restriction) {
|
/**
|
||||||
UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
* Decide if volume is mountable per device policies.
|
||||||
if (um.hasUserRestriction(restriction, Binder.getCallingUserHandle())) {
|
*/
|
||||||
throw new SecurityException("User has restriction " + restriction);
|
private boolean isMountDisallowed(VolumeInfo vol) {
|
||||||
|
if (vol.type == VolumeInfo.TYPE_PUBLIC || vol.type == VolumeInfo.TYPE_PRIVATE) {
|
||||||
|
final UserManager userManager = mContext.getSystemService(UserManager.class);
|
||||||
|
return userManager.hasUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA,
|
||||||
|
Binder.getCallingUserHandle());
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1586,8 +1594,8 @@ class MountService extends IMountService.Stub
|
|||||||
waitForReady();
|
waitForReady();
|
||||||
|
|
||||||
final VolumeInfo vol = findVolumeByIdOrThrow(volId);
|
final VolumeInfo vol = findVolumeByIdOrThrow(volId);
|
||||||
if (vol.type == VolumeInfo.TYPE_PUBLIC || vol.type == VolumeInfo.TYPE_PRIVATE) {
|
if (isMountDisallowed(vol)) {
|
||||||
enforceUserRestriction(UserManager.DISALLOW_MOUNT_PHYSICAL_MEDIA);
|
throw new SecurityException("Mounting " + volId + " restricted by policy");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
mConnector.execute("volume", "mount", vol.id, vol.mountFlags, vol.mountUserId);
|
mConnector.execute("volume", "mount", vol.id, vol.mountFlags, vol.mountUserId);
|
||||||
|
|||||||
Reference in New Issue
Block a user