CVE-2026-58875 AI-generated analysis
platform/frameworks/base, DevicePolicy (device policy engine Bundle policy values and XML serializer)
Adds a BundlePolicyTypeVerifier that rejects Bundle policy values containing types other than Boolean, Integer, String, String[], Bundle or Parcelable[] of Bundles, enforced in the BundlePolicyValue constructor. It also makes BundlePolicySerializer.writeBundle throw IllegalArgumentException instead of casting unknown values to String[] without a check.
Root cause
BundlePolicyValue accepted any Bundle without checking the types of its entries. In services/devicepolicy/.../BundlePolicySerializer.java, writeBundle() handled specific value types in earlier branches. The diff shows a Parcelable[] branch that writes each element as a Bundle; the other branches are not shown. Its final else branch assumed anything left over was a String[] and cast it unchecked with `(String[]) value`. A Bundle holding any other type could therefore reach the serializer and cause a runtime exception while the policy was being written to XML. The tests use Long, Double, a Long nested in a child Bundle, and an Intent inside a Parcelable[]. The bulletin classifies the issue as a DoS.
How the fix works
- core/java/android/app/admin/BundlePolicyTypeVerifier.java (new): enforceValidTypes(Bundle) walks the bundle breadth-first using an ArrayDeque. For each key it fetches the raw value via Bundle.get(String) and allows null, Boolean, Integer, String and String[]. A Bundle value is queued for inspection. A Parcelable[] must contain only Bundle elements: a null or any other Parcelable throws IllegalArgumentException 'bundle-array can only hold Bundles', and each Bundle element is queued. Any other type throws IllegalArgumentException 'Invalid type inside Bundle: <class> for key: <key>'.
- core/java/android/app/admin/BundlePolicyValue.java: the public constructor BundlePolicyValue(Bundle) now calls BundlePolicyTypeVerifier.enforceValidTypes(value) right after super(value), before the existing flag-gated PolicySizeVerifier.enforceMaxBundleFieldsLength. The private Parcel constructor delegates to this(source.readBundle()), and BundlePolicySerializer.readFromXml returns new BundlePolicyValue(bundle), so values created on both paths are also validated.
- services/devicepolicy/java/com/android/server/devicepolicy/BundlePolicySerializer.java: writeBundle() turns the trailing `else` into `else if (value instanceof String[])`, so the String[] serialization path is only taken for real String arrays. It adds a new final `else` that throws IllegalArgumentException("Unsupported type in Bundle for key '<key>': <class>") as an extra safety measure. The new test expects nested invalid entries to be rejected as well, with the nestedKey message.
- services/tests/servicestests/.../BundlePolicySerializerTest.kt (new): parameterized tests assert that saveToXml throws for Long, Double, a nested Long and a non-Bundle Parcelable array entry, and does not throw for the supported type set.
Completeness
- The verifier covers top-level entries, arbitrarily nested Bundles and the Bundle elements of Parcelable[] arrays, all at construction time.
- The serializer change only hardens the String[] branch. The Parcelable[] branch of writeBundle, which casts elements to Bundle, is not modified in the diff. The test expects saveToXml to throw 'bundle-array can only hold Bundles', which implies an existing check in that branch, but the diff does not confirm this.
- The verifier accepts null values. The serializer still tolerates null elements inside a String[] and writes them as empty text. The verifier rejects null elements inside a Parcelable[].
- Validation happens only where a BundlePolicyValue is constructed. A Bundle passed to BundlePolicySerializer.saveToXml without going through BundlePolicyValue now gets an IllegalArgumentException instead of a ClassCastException, so serialization still fails with an exception.
- In BundlePolicySerializer.readFromXml, the catch clause handles only XmlPullParserException and IOException. An IllegalArgumentException from the new constructor check would therefore propagate. Whether readBundle can produce any non-permitted type is not shown.
Behavior changes
- Constructing a BundlePolicyValue, including through the Parcel constructor, with a Bundle that contains a type outside {null, Boolean, Integer, String, String[], Bundle, Parcelable[] of Bundle} now throws IllegalArgumentException. Before the fix such values were accepted.
- BundlePolicySerializer.writeBundle now throws IllegalArgumentException with a descriptive message for unsupported value types, instead of a ClassCastException from the unchecked String[] cast.
- The commit's Test line (ApplicationRestrictionsTest#setApplicationRestrictions_invalidBundleType_throwsIllegalArgumentException) indicates that setApplicationRestrictions with an invalid Bundle type is expected to return an IllegalArgumentException to the caller. That test is not part of this diff.
- The supported-types test confirms that Boolean, Integer, String, String[], a nested Bundle and a Bundle array still serialize without error.
Per major
- Android 14: Adapted fix (ce0d10c09fab, android-security-14.0.0_r31): the same verifier, with @NonNull on the parameter, and the same serializer change. BundlePolicyValue on 14 has no PolicySizeVerifier call, so the verifier call is the only statement after super(value). The commit also adds a new PolicyValueTest.kt. 8/8 lines of the patched region are present.
- Android 15: Same fix (5186ece4af3a, android-security-15.0.0_r19): the verifier call is added before the flag-gated PolicySizeVerifier.enforceMaxBundleFieldsLength call, and BundlePolicySerializerTest.kt is added. PolicyValueTest.kt is not in this commit's file list. 8/8 lines of the patched region are present.
- Android 16: Adapted fix (fdf981f52e3c, android-security-16.0.0_r10): identical logic. The verifier parameter is annotated @NonNull, and BundlePolicyValue calls PolicySizeVerifier unconditionally (no flag) after the new check. 8/8 lines of the patched region are present.
- Android 17: Adapted fix (539718792716, android-security-17.0.0_r3): the verifier uses the @Hide annotation instead of the @hide javadoc tag and has no private constructor; otherwise it is identical. PolicyValueTest.kt is restructured to add BundlePolicyValue type tests. 8/8 lines of the patched region are present.
Unknowns
- The unmodified middle of BundlePolicySerializer.writeBundle (the branches before the String[] branch) is not shown. So it cannot be confirmed which types it handled, or whether the Parcelable[] branch already rejected non-Bundle elements with the 'bundle-array can only hold Bundles' message the new test expects.
- The service-side call site that constructs BundlePolicyValue from caller-supplied Bundles (for example for setApplicationRestrictions), and the permission checks around it, are not in the material. The ApplicationRestrictionsTest referenced in the commit message is not part of the diff.
- Whether BundlePolicySerializer.readBundle can ever produce a value type that the new constructor check rejects is not shown.
- Beyond the bulletin's DoS classification, the material does not show the exact failure mode before the fix (process crash or repeated persistence failure).