CVE-2026-28597 AI-generated analysis
platform/frameworks/base, system_server URI grants (services/core/java/com/android/server/uri, UriGrantsManagerService)
UriGrantsManagerService now checks each persisted URI grant snapshot before XML serialization (no null fields, URI at most 65,535 UTF-8 bytes, package names at most 255 bytes) and skips entries that fail, so one overly long URI can no longer make the whole urigrants.xml write fail and leave a revoked grant on disk.
Root cause
The grant persistence loop in UriGrantsManagerService writes mGrantFile through out.startTag(TAG_URI_GRANT) plus attribute writes for each UriPermission.Snapshot. It wrote the URI and package name strings without checking their size. Per the commit message, an overly long URI caused an IOException during XML serialization. The existing catch path then calls mGrantFile.failWrite(fos), so the grants file was not updated. The commit message says this let a malicious app keep a URI grant indefinitely after revocation by supplying an overly long URI.
How the fix works
- services/core/java/com/android/server/uri/UriGrantsManagerService.java: the try/catch body that writes the grants file moves out of the existing persist method into a new @VisibleForTesting method, writeGrantedUriPermissionWithSnapshot(FileOutputStream fos, long startTime, List<UriPermission.Snapshot> persist). The original method now calls it and then calls mMetricsHelper.reportPersistentUriFlushed as before.
- UriGrantsManagerService.writeGrantedUriPermissionWithSnapshot: inside the for loop over persist, each snapshot is checked before out.startTag(null, TAG_URI_GRANT). If perm.uri, perm.sourcePkg or perm.targetPkg is null, the entry is skipped with Slog.w. If perm.uri.toString() exceeds MAX_XML_STRING_ATTR_SIZE (65_535 bytes), it is skipped ("URI too long"). If perm.sourcePkg or perm.targetPkg exceeds MAX_PACKAGE_NAME_SIZE (255 bytes), it is skipped ("Package name too long"). Skipped entries use continue, so the remaining grants are still serialized.
- UriGrantsManagerService: adds a private static helper, stringSizeWithinBounds(String, int maxByteSize), which compares str.getBytes(UTF_8).length against the limit. Also adds the static import of java.nio.charset.StandardCharsets.UTF_8 and the two constants.
- services/core/java/com/android/server/uri/UriPermission.java: the Snapshot(UriPermission) constructor changes from private to package-visible with @VisibleForTesting, so the test can build snapshots directly.
- services/tests/servicestests/src/com/android/server/uri/UriGrantsManagerServiceTest.java: adds testPersistence_skipsMaliciouslyLongUri (AsbSecurityTest cveBugId 262884935). It writes one normal URI snapshot and one with a 65,536-character path through writeGrantedUriPermissionWithSnapshot. It then asserts that the long URI is absent from urigrants.xml, the safe one is present, and the file parses as well-formed XML.
Completeness
- Covers the single serialization loop for persisted grants. Entries with an oversized URI or package name, or with null fields, no longer abort the write, so other grants are still written out and the oversized grant itself is not written to disk.
- The limit applies only at serialization time. Nothing in the diff limits URI length when a grant is created or made persistable, so oversized grants can still exist in memory until the next write drops them.
- Only the three string fields (uri, sourcePkg, targetPkg) are checked. Any other IOException inside the loop still goes to the existing catch and failWrite path. The diff does not change that failure handling.
- The limits are hard-coded (65_535 and 255) rather than taken from the serializer. The check runs on perm.uri.toString(), while the exact attribute value written for the URI is outside the shown hunk.
- The reader side (parsing of urigrants.xml) is unchanged.
Behavior changes
- Persisted grants whose URI exceeds 65,535 UTF-8 bytes, or whose source or target package name exceeds 255 UTF-8 bytes, are left out of urigrants.xml with only a Slog.w warning.
- Snapshots with a null uri, sourcePkg or targetPkg are skipped instead of being serialized.
- Grant and revoke APIs are unchanged. reportPersistentUriFlushed is still called after the write.
- The UriPermission.Snapshot constructor becomes package-visible, and a new package-visible method, writeGrantedUriPermissionWithSnapshot, exists on the service.
Per major
- Android 14: Same fix: commit a8279722faf7 in android-security-14.0.0_r29 (cherry-pick, Change-Id I9f211dbfad84ce23222f256d4a8b18d976624345). 8/8 lines of the patched region are present at android-security-14.0.0_r31.
- Android 15: Same fix: commit 1fcacc7ecb60 in android-security-15.0.0_r17. The service and UriPermission hunks are identical; the test file hunks are adjusted for the parameterized/Ravenwood test layout. 8/8 lines are present at android-security-15.0.0_r19.
- Android 16: Same fix: commit 585e7556fcec in android-security-16.0.0_r8. The service hunks are identical; in UriPermission.java the import is added next to the existing GuardedBy import. 8/8 lines are present at android-security-16.0.0_r10.
- Android 17: The bulletin does not list Android 17 as affected. The patched region is present (8/8 lines) at android-security-17.0.0_r3.
Unknowns
- The exact serializer limit that caused the IOException is not shown. 65,535 is the constant the fix chose.
- The hunk does not show the attribute write for the URI value itself, so it is not visible whether perm.uri.toString() matches exactly what is serialized.
- Whether URI length is limited anywhere else, such as at grant creation, is not shown.
- How the Android 14 test resolves XmlPullParserException is not visible: the diff does not import it, and the import block shown at r31 does not list it.