From fadb2b3a27e4c23f5c566e6f7eadfaed9e23e68c Mon Sep 17 00:00:00 2001 From: Benjamin Franz Date: Wed, 14 Jan 2015 18:22:42 +0000 Subject: Avoid SecurityException when calling getUserData Currently we risk getting a SecurityException in a number of places, where getUserData is called for a different user than the calling user. To avoid this, the caller is cleared in a helper function. Bug: 18662452 Change-Id: Ibc131c602e52d9f013fe739a9c18e693181ded67 --- .../devicepolicy/DevicePolicyManagerService.java | 63 ++++++++++++++-------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 579fae4e2ccb..6d6ac1ef291d 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -989,6 +989,25 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { } } + /** + * Creates and loads the policy data from xml for data that is shared between + * various profiles of a user. In contrast to {@link #getUserData(int)} + * it allows access to data of users other than the calling user. + * + * This function should only be used for shared data, e.g. everything regarding + * passwords and should be removed once multiple screen locks are present. + * @param userHandle the user for whom to load the policy data + * @return + */ + DevicePolicyData getUserDataUnchecked(int userHandle) { + long ident = Binder.clearCallingIdentity(); + try { + return getUserData(userHandle); + } finally { + Binder.restoreCallingIdentity(ident); + } + } + void removeUserData(int userHandle) { synchronized (this) { if (userHandle == UserHandle.USER_OWNER) { @@ -1927,7 +1946,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // Return strictest policy for this user and profiles that are visible from this user. List profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i=0; i profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i=0; i profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i = 0; i < N; i++) { ActiveAdmin admin = policy.mAdminList.get(i); @@ -2082,7 +2101,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { List profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i = 0; i < N; i++) { ActiveAdmin admin = policy.mAdminList.get(i); @@ -2180,7 +2199,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { List profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i = 0; i < N; i++) { ActiveAdmin admin = policy.mAdminList.get(i); @@ -2237,7 +2256,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // Return strictest policy for this user and profiles that are visible from this user. List profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i=0; i profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i=0; i profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i=0; i profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i = 0; i < N; i++) { ActiveAdmin admin = policy.mAdminList.get(i); @@ -2422,7 +2441,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { // Return strictest policy for this user and profiles that are visible from this user. List profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i=0; i profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i=0; i profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { - DevicePolicyData policy = getUserData(userInfo.id); + DevicePolicyData policy = getUserDataUnchecked(userInfo.id); final int N = policy.mAdminList.size(); for (int i=0; i profiles = mUserManager.getProfiles(userHandle); for (UserInfo userInfo : profiles) { int profileId = userInfo.id; - DevicePolicyData policy = getUserData(profileId); + DevicePolicyData policy = getUserDataUnchecked(profileId); final int N = policy.mAdminList.size(); if (N > 0) { for (int i=0; i