CVE-2026-59020 AI-generated analysis
platform/frameworks/base, services/devicepolicy (DevicePolicyManagerService, TransferOwnershipMetadataManager)
DevicePolicyManagerService now deletes the device-global ownership-transfer metadata file during removeUserData() when that file refers to the user being removed, so a stale journal cannot survive the removal of the profile it points to and trigger an unguarded boot-time revert that crash-loops system_server.
Root cause
The ownership-transfer metadata file managed by mTransferOwnershipMetadataManager is device-global and records a userId. When the user it referenced was removed, removeUserData() cleared mOwners, mUserData, user restrictions and the per-user device_policies.xml, but never touched the transfer metadata file. Per the commit message, a profile owner could leave such a file pointing at its own profile (via a race in transferOwnership()) and then wipe the profile; at boot an unguarded revert attempt then threw an uncaught exception, producing a persistent system_server crash loop. The boot-time revert code itself is not part of the provided diff.
How the fix works
- services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java:removeUserData(int) - inside the synchronized (getLockObject()) block, after mUserData.remove(userHandle) and before the per-user device_policies.xml is deleted, a new call deleteUserTransferOwnershipMetadataFileLocked(userHandle) is added.
- services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java:deleteUserTransferOwnershipMetadataFileLocked(int) - new private helper: if mTransferOwnershipMetadataManager.metadataFileExists(), it calls loadMetadataFile(); if the result is non-null and metadata.userId == userHandle it calls the existing deleteTransferOwnershipMetadataFileLocked(), which delegates to mTransferOwnershipMetadataManager.deleteMetadataFile().
- Net effect: the metadata file's lifetime is bound to the user it names, so the boot-time revert no longer finds a file referencing a removed user via this path.
Completeness
- Covers only the user-removal path (removeUserData). The file is deleted solely when its userId equals the removed user; files naming other users are left in place.
- The fix does not change transferOwnership() or the race the commit message describes; the stale file can still be created, it is just cleaned up on user removal.
- The boot-time revert path that throws the uncaught exception is not modified in this diff; no try/catch or user-existence check is added there, so any other way of reaching that path with inconsistent metadata is not covered by this commit.
- If metadataFileExists() is true but loadMetadataFile() returns null, the helper does nothing and the file remains.
- removeUserData() returns early for UserHandle.USER_SYSTEM, so the new cleanup never runs for user 0.
Behavior changes
- During user removal, DPMS now performs an additional read of the transfer-ownership metadata file under the DPMS lock and deletes it when it refers to the removed user.
- A pending ownership transfer journal for a user being removed is discarded rather than left for boot-time processing.
Per major
- Android 14: same fix: commit f3e432dd70c2 in android-security-14.0.0_r31, call inserted after mUserData.remove(userHandle) at ~line 2316 and helper added at ~line 19911; 6/6 patched lines present.
- Android 15: same fix: commit c3533fa33152 in android-security-15.0.0_r19, identical hunks at different offsets (2333 / 19881); 6/6 lines present.
- Android 16: same fix: commit 6c9b487885b4 in android-security-16.0.0_r10, identical hunks at offsets 2413 / 19857; 6/6 lines present.
- Android 17: adapted placement: commit d00f145f6aff in android-security-17.0.0_r3; the call is inserted after mDeviceAdmins.removeUserData(userHandle), right before the device_policies.xml deletion, and the identical helper is placed after a different method (one returning deviceOwner.endUserSessionMessage); 7/7 lines present.
Unknowns
- The transferOwnership() race and the boot-time revert code that throws are not included in the material, so the exact exception and whether they were hardened in other commits is unknown.
- Which caller invokes removeUserData() (user-removal callback) is not shown in the provided context.
- The commit touches only DevicePolicyManagerService.java; any test coverage for the referenced DevicePolicyManagerTest run is not part of this commit.