CVE-2026-55264 AI-generated analysis
platform/packages/providers/DownloadProvider, DownloadProvider insert path for completed downloads (DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD) and Helpers path validation
Makes the addCompletedDownload() ownership check in DownloadProvider fail closed: callers without MANAGE_EXTERNAL_STORAGE (or legacy READ_EXTERNAL_STORAGE) are rejected unless the file is in an app-specific directory of a package of the calling UID or MediaStore (after a synchronous scan) records a package of the calling UID as owner.
Root cause
In DownloadProvider.checkDownloadedFilePath(), the only ownership gate for a file registered via addCompletedDownload() was checkWhetherCallingAppHasAccess(filePath, uid). It queried MediaStore for the path and threw SecurityException only when three things held: a row existed, OWNER_PACKAGE_NAME was non-null, and that package was not among the caller UID's packages. Every other outcome returned silently: no MediaStore row yet (the commit cites race conditions with FUSE), a null owner, a null ContentProviderClient, or a RemoteException. Per the commit message, this let unprivileged apps read arbitrary files in /sdcard/Download/ via addCompletedDownload(). Separately, Helpers.isFilenameValidInExternalPackage() only considered getCallingPackage(), not other packages sharing the calling UID, and returned false on IOException.
How the fix works
- src/com/android/providers/downloads/DownloadProvider.java:checkDownloadedFilePath: after Helpers.checkDestinationFilePathRestrictions(), the ownership check is skipped only if Helpers.isFilenameValidInExternalPackage(getContext(), file, getCallingPackage(), Binder.getCallingUid()) reports that the file is in an app-specific directory of the calling UID. Otherwise checkWhetherCallingAppHasAccess(file.getPath(), Binder.getCallingUid(), isLegacyMode) is called with the new isLegacyMode argument.
- DownloadProvider.java:checkWhetherCallingAppHasAccess: rewritten to fail closed. (1) It returns early if hasStoragePermissions(uid, isLegacyMode). (2) It calls MediaStore.scanFile(), then queries MediaStore (setIncludePending) for _ID and OWNER_PACKAGE_NAME by DATA path and records fileInMediaStore and the owner. Any Exception, not just RemoteException, is logged and treated as not found. (3) It returns only if fileInMediaStore is true and the owner package is in getPackagesForUid(uid). (4) Otherwise it throws SecurityException("Caller does not have access to this path: " + filePath).
- DownloadProvider.java:hasStoragePermissions (new): returns true if the caller holds MANAGE_EXTERNAL_STORAGE, or if isLegacyMode is true and the caller holds READ_EXTERNAL_STORAGE. Both are checked via getContext().checkPermission(perm, Binder.getCallingPid(), uid).
- src/com/android/providers/downloads/Helpers.java:isFilenameValidInExternalPackage: new signature (Context, File, String packageName, int uid). It is null-safe on packageName and checks the data/obb/media app directories of packageName. It then iterates every package returned by PackageManager.getPackagesForUid(uid), skipping packageName, and checks the same directories. An IOException is logged per package instead of aborting with false.
- Helpers.java:checkDestinationFilePathRestrictions: updated to call the new isFilenameValidInExternalPackage(context, file, callingPackage, Binder.getCallingUid()).
- DownloadProvider.java:checkInsertPermissions: the reassignment values = new ContentValues(values) is replaced by a local ContentValues 'check' used for enforceAllowedValues, remove and size validation. Per the commit message, this resolves a parameter shadowing warning and ensures the original values are not stripped.
- DownloadProvider.java:openFile: adds a filename != null guard before new java.io.File(filename).isFile() in the verbose logging branch.
Completeness
- All fail-open outcomes of the old check (no MediaStore row, null owner, null client, exception) now end in SecurityException for callers without broad storage permission. The added MediaStore.scanFile() call targets the case where a file is not yet indexed.
- The ownership check is applied only in checkDownloadedFilePath() (the addCompletedDownload / DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD path). checkFileUriDestination() (DESTINATION_FILE_URI) still relies only on Helpers.checkDestinationFilePathRestrictions() and does not call checkWhetherCallingAppHasAccess(). The material does not show whether that path needs the check.
- Ownership is still decided from MediaStore's OWNER_PACKAGE_NAME. Files that MediaStore records with a null owner are now rejected for non-privileged callers rather than accepted. Callers in the same process (Binder.getCallingPid() == Process.myPid()) still return before these checks, as before.
- hasStoragePermissions() grants access on MANAGE_EXTERNAL_STORAGE or legacy READ_EXTERNAL_STORAGE. It does not consider READ_MEDIA_* or WRITE_EXTERNAL_STORAGE, so callers holding only those permissions depend on MediaStore ownership.
Behavior changes
- addCompletedDownload() for a file in the public Downloads directory now throws SecurityException (the message includes the path) when two conditions hold. First, the caller lacks MANAGE_EXTERNAL_STORAGE or legacy READ_EXTERNAL_STORAGE. Second, MediaStore does not list a package of the calling UID as owner, which includes the cases where the file is unknown to MediaStore, has no owner, or the MediaStore query fails.
- MediaStore.scanFile() is now called inside the insert path for callers without broad storage permission.
- Files in the app-specific external directories of any package sharing the calling UID, not only getCallingPackage(), are accepted without the MediaStore check, in both checkDownloadedFilePath() and checkDestinationFilePathRestrictions(). An IOException while canonicalising one package's directories no longer fails the whole check.
- Any Exception from the MediaStore interaction is caught and logged; previously only RemoteException was caught.
- openFile() no longer dereferences a null filename in its verbose logging branch.
Per major
- Android 14: Same fix: commit 8397bd246e60 in android-security-14.0.0_r29. The diff is identical to Android 15, with the same blob hashes 0e5d341c..c08cfff0 and 9b99e477..3f88d3b2. At android-security-14.0.0_r31, 5/8 lines of the patched region are present.
- Android 15: Same fix: commit 842086d94f37 in android-security-15.0.0_r17 (RESTRICT AUTOMERGE cherry-pick, Change-Id I159a2a9be7da21b2738be8dc8362dc3fb463d638). At android-security-15.0.0_r19, 5/8 lines of the patched region are present.
- Android 16: Same fix: commit e28ef02f33a9 in android-security-16.0.0_r8 with identical content. The first three DownloadProvider.java hunks start 2 lines earlier and the openFile hunk 7 lines later. At android-security-16.0.0_r10, 5/8 lines of the patched region are present.
- Android 17: Same fix: commit 30a6a1220e98 in android-security-17.0.0_r1 with the same changes. Helpers.java has different blob hashes and its hunks start at old lines 592/645 instead of 550/603. At android-security-17.0.0_r3, 5/8 lines of the patched region are present.
Unknowns
- Whether the Binder calling identity is cleared before MediaStore.scanFile() and the query, so that both run with DownloadProvider's own identity. The surrounding insert() code is not in the material.
- Whether DESTINATION_FILE_URI (checkFileUriDestination) was ever subject to the same fail-open issue. The material only shows the addCompletedDownload path being changed.
- Whether the checkInsertPermissions refactor changes behaviour, since the rest of that method is not in the material.
- Why only 5/8 lines of the patched region match at the latest security tags on every branch.
- Which CtsDownloadManagerTestCases tests cover the new rejection behaviour.