CVE-2026-58994 AI-generated analysis
platform/packages/modules/Nfc, NfcNci NfcService.TagService (INfcTag binder)
Adds a server-side calling-UID check (isTagAccessAllowed) to the INfcTag binder methods of NfcService.TagService, tracking the UID of the reader-mode app a tag was dispatched to in a new mDispatchedUid field and rejecting tag operations from any other UID or when no tag is active.
Root cause
NfcService.TagService (INfcTag.Stub) methods connect, reconnect, getTechList, isNdef, transceive, ndefRead, ndefWrite, ndefMakeReadOnly, formatNdef and rediscover only enforced NfcPermissions.enforceUserPermissions (android.permission.NFC) plus NFC/reader-option state checks (isPresent had only the state checks) and then looked up the TagEndpoint by the caller-supplied nativeHandle via findObject. Nothing tied the active tag session to the application the tag had been dispatched to, and nothing required that a tag be currently active (mCookieUpToDate was not consulted). Per the commit message, background apps holding android.permission.NFC could make raw INfcTag Binder calls against active NFC tag sessions.
How the fix works
- NfcNci/src/com/android/nfc/NfcService.java: new field int mDispatchedUid = Process.INVALID_UID next to mCookieUpToDate.
- NfcService.java:dispatchTagEndpoint (tag discovery path): inside the readerParams.callback != null branch the fix sets mDispatchedUid = readerParams.uid; if mNfcDispatcher.dispatchTag(tag) returns NfcDispatcher.DISPATCH_FAIL, mDispatchedUid is reset to Process.INVALID_UID.
- NfcService.java: onTagDisconnected callback now also resets mDispatchedUid = Process.INVALID_UID alongside mCookieUpToDate = -1.
- NfcService.java:TagService.isTagAccessAllowed (new private helper): returns false if mCookieUpToDate == -1 (no active tag); otherwise compares Binder.getCallingUid() with mDispatchedUid and returns false if mDispatchedUid is set (not INVALID_UID) and differs from the caller; logs a debug line when DBG.
- NfcService.java:TagService.connect and reconnect: after enforceUserPermissions, return ErrorCodes.ERROR_DISCONNECT if !isTagAccessAllowed().
- NfcService.java:TagService.ndefWrite, ndefMakeReadOnly, formatNdef: after enforceUserPermissions, return ErrorCodes.ERROR_IO if !isTagAccessAllowed().
- NfcService.java:TagService.getTechList, isPresent, isNdef, transceive, ndefRead, rediscover: the separate isNfcEnabled / isReaderOptionEnabled / checkAndHandleRemovalDetectionMode(true) checks are folded into one condition with !isTagAccessAllowed() inserted after isNfcEnabled, returning null or false as before; local tag variables are declared at the findObject assignment (no logic change).
- NfcNci/tests/unit/src/com/android/nfc/NfcServiceTest.java: existing TagService tests now set mCookieUpToDate = 12345L and mDispatchedUid = Process.INVALID_UID so they pass the new gate; new test testTagService_unauthorizedCallingUid_blocksTagOperations sets mDispatchedUid to a UID different from the caller and asserts all eleven patched methods are rejected with the expected return value.
Completeness
- Covers all eleven TagService methods visible in the diff: connect, reconnect, getTechList, isPresent, isNdef, transceive, ndefRead, ndefWrite, ndefMakeReadOnly, formatNdef, rediscover. Any other INfcTag.Stub methods in TagService are not shown in the diff and are unchanged by this commit.
- The UID binding is only established on the reader-mode path (readerParams.callback != null, mDispatchedUid = readerParams.uid). The commit does not set mDispatchedUid for tags dispatched through mNfcDispatcher.dispatchTag; when it is INVALID_UID, isTagAccessAllowed only enforces that a tag is active (mCookieUpToDate != -1) and any UID holding android.permission.NFC passes.
- The no-active-tag gate (mCookieUpToDate == -1) is new and applies to every caller, including the legitimate dispatched app.
- mDispatchedUid and mCookieUpToDate are plain fields (no volatile in the declarations shown) written on the tag discovery/disconnect path and read in binder methods, with no synchronization added in the diff.
- The Android 16 commit does not reset mDispatchedUid at the start of dispatchTagEndpoint; the Android 17 commit adds that reset right after mCookieUpToDate is regenerated. In 16 the field is only cleared by onTagDisconnected or DISPATCH_FAIL.
- isPresent still has no NfcPermissions.enforceUserPermissions call (pre-existing, unchanged); it is now gated by isTagAccessAllowed and the NFC state checks only.
Behavior changes
- connect/reconnect return ErrorCodes.ERROR_DISCONNECT, ndefWrite/ndefMakeReadOnly/formatNdef return ErrorCodes.ERROR_IO, getTechList/transceive/ndefRead/rediscover return null, and isPresent/isNdef return false when the caller UID differs from a set mDispatchedUid.
- The same rejections now also apply whenever no tag is active (mCookieUpToDate == -1), regardless of caller.
- New debug log 'Tag access denied for UID ..., active UID is ...' when DBG is on.
- For getTechList, isPresent, isNdef, transceive, ndefRead and rediscover the access check runs after isNfcEnabled but before isReaderOptionEnabled and checkAndHandleRemovalDetectionMode(true), so for a rejected caller checkAndHandleRemovalDetectionMode is no longer invoked.
Per major
- Android 14: Bulletin lists 14 as affected but the fix is announced-not-published; platform/packages/modules/Nfc is not present in android-security-14.0.0_r31 security tags. The 14 fix is not in the material.
- Android 15: Bulletin lists 15 as affected but the fix is announced-not-published; project not present in android-security-15.0.0_r19 security tags. The 15 fix is not in the material.
- Android 16: Same fix: commit 2f38b5e109a9 (Change-Id I9c24261c2ae81f93083fa628f19462549e8abefb, cherry-pick of 2a8b421b1d5c) in android-security-16.0.0_r10; 8/8 lines of the patched region present. Tests use mNfcService.mState = NfcAdapter.STATE_ON.
- Android 17: Adapted fix: commit e7985be68775 in android-security-17.0.0_r3; 8/8 lines present. Same TagService changes plus an extra reset mDispatchedUid = Process.INVALID_UID in dispatchTagEndpoint right after mCookieUpToDate is regenerated; tests use mNfcService.mState.set(NfcAdapter.STATE_ON). Surrounding context differs (e.g. onTagDisconnected also calls executeReaderModeOnTagLostCallback, pre-existing).
Unknowns
- Whether INfcTag/TagService has further methods (not shown in the diff) that remain without the isTagAccessAllowed check.
- What the Android 14 and 15 fixes look like (announced-not-published, project absent from those security tags).
- Whether, on Android 16, a new tag can be dispatched without an intervening onTagDisconnected such that a stale mDispatchedUid persists (17 adds an explicit reset; the 16 commit does not).