Skip to content

Commit 6a9250e

Browse files
Tetiana MeronykAndroid Build Coastguard Worker
authored andcommitted
Truncate user data to a limit of 500 characters
Fix vulnerability that allows creating users with no restrictions. This is done by creating an intent to create a user and putting extras that are too long to be serialized. It causes IOException and the restrictions are not written in the file. By truncating the string values when writing them to the file, we ensure that the exception does not happen and it can be recorded correctly. Bug: 293602317 Test: install app provided in the bug, open app and click add. Check logcat to see there is no more IOException. Reboot the device by either opening User details page or running adb shell dumpsys user | grep -A12 heen and see that the restrictions are in place. (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:59042a32c7e192d160c295ecb6477a09bb5da0bb) Merged-In: I633dc10974a64ef2abd07e67ff2d209847129989 Change-Id: I633dc10974a64ef2abd07e67ff2d209847129989
1 parent d42f8d7 commit 6a9250e

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

services/core/java/com/android/server/pm/UserManagerService.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ public class UserManagerService extends IUserManager.Stub {
255255

256256
private static final int USER_VERSION = 9;
257257

258+
private static final int MAX_USER_STRING_LENGTH = 500;
259+
258260
private static final long EPOCH_PLUS_30_YEARS = 30L * 365 * 24 * 60 * 60 * 1000L; // ms
259261

260262
static final int WRITE_USER_MSG = 1;
@@ -3404,15 +3406,17 @@ void writeUserLP(UserData userData, OutputStream os)
34043406
// Write seed data
34053407
if (userData.persistSeedData) {
34063408
if (userData.seedAccountName != null) {
3407-
serializer.attribute(null, ATTR_SEED_ACCOUNT_NAME, userData.seedAccountName);
3409+
serializer.attribute(null, ATTR_SEED_ACCOUNT_NAME,
3410+
truncateString(userData.seedAccountName));
34083411
}
34093412
if (userData.seedAccountType != null) {
3410-
serializer.attribute(null, ATTR_SEED_ACCOUNT_TYPE, userData.seedAccountType);
3413+
serializer.attribute(null, ATTR_SEED_ACCOUNT_TYPE,
3414+
truncateString(userData.seedAccountType));
34113415
}
34123416
}
34133417
if (userInfo.name != null) {
34143418
serializer.startTag(null, TAG_NAME);
3415-
serializer.text(userInfo.name);
3419+
serializer.text(truncateString(userInfo.name));
34163420
serializer.endTag(null, TAG_NAME);
34173421
}
34183422
synchronized (mRestrictionsLock) {
@@ -3452,6 +3456,13 @@ void writeUserLP(UserData userData, OutputStream os)
34523456
serializer.endDocument();
34533457
}
34543458

3459+
private String truncateString(String original) {
3460+
if (original == null || original.length() <= MAX_USER_STRING_LENGTH) {
3461+
return original;
3462+
}
3463+
return original.substring(0, MAX_USER_STRING_LENGTH);
3464+
}
3465+
34553466
/*
34563467
* Writes the user list file in this format:
34573468
*
@@ -3857,6 +3868,8 @@ private UserInfo createUserInternalUncheckedNoTracing(@Nullable String name,
38573868
boolean preCreate, @Nullable String[] disallowedPackages,
38583869
@NonNull TimingsTraceAndSlog t, @Nullable Object token)
38593870
throws UserManager.CheckedUserOperationException {
3871+
3872+
String truncatedName = truncateString(name);
38603873
final UserTypeDetails userTypeDetails = mUserTypes.get(userType);
38613874
if (userTypeDetails == null) {
38623875
Slog.e(LOG_TAG, "Cannot create user of invalid user type: " + userType);
@@ -3888,8 +3901,8 @@ private UserInfo createUserInternalUncheckedNoTracing(@Nullable String name,
38883901

38893902
// Try to use a pre-created user (if available).
38903903
if (!preCreate && parentId < 0 && isUserTypeEligibleForPreCreation(userTypeDetails)) {
3891-
final UserInfo preCreatedUser = convertPreCreatedUserIfPossible(userType, flags, name,
3892-
token);
3904+
final UserInfo preCreatedUser = convertPreCreatedUserIfPossible(userType, flags,
3905+
truncatedName, token);
38933906
if (preCreatedUser != null) {
38943907
return preCreatedUser;
38953908
}
@@ -3985,7 +3998,7 @@ private UserInfo createUserInternalUncheckedNoTracing(@Nullable String name,
39853998
flags &= ~UserInfo.FLAG_EPHEMERAL;
39863999
}
39874000

3988-
userInfo = new UserInfo(userId, name, null, flags, userType);
4001+
userInfo = new UserInfo(userId, truncatedName, null, flags, userType);
39894002
userInfo.serialNumber = mNextSerialNumber++;
39904003
userInfo.creationTime = getCreationTime();
39914004
userInfo.partial = true;
@@ -5397,8 +5410,8 @@ private void setSeedAccountDataNoChecks(@UserIdInt int userId, String accountNam
53975410
Slog.e(LOG_TAG, "No such user for settings seed data u=" + userId);
53985411
return;
53995412
}
5400-
userData.seedAccountName = accountName;
5401-
userData.seedAccountType = accountType;
5413+
userData.seedAccountName = truncateString(accountName);
5414+
userData.seedAccountType = truncateString(accountType);
54025415
userData.seedAccountOptions = accountOptions;
54035416
userData.persistSeedData = persist;
54045417
}

0 commit comments

Comments
 (0)