CVE-2026-55292 AI-generated analysis
platform/packages/modules/Nfc, libnfc-nci reader/writer (RW) Chinese ID card (CI) tag handler
Adds response-length validation in rw_ci_data_cback (libnfc-nci rw_ci.cc) for the RW_CI_STATE_ATTRIB and RW_CI_STATE_UID states so that short or zero-length tag responses are rejected with NFC_STATUS_BAD_RESP instead of being parsed past the end of the buffer.
Root cause
rw_ci_data_cback in libnfc-nci/src/nfc/tags/rw_ci.cc trusted the length of the received R-APDU (p_r_apdu->len). In RW_CI_STATE_ATTRIB it copied sizeof(p_ci->attrib_res) bytes from the payload pointer p without checking that the buffer held that many bytes. In RW_CI_STATE_UID it did p_r_apdu->len -= 1 and then computed p_sw = payload + (p_r_apdu->len - T4T_RSP_STATUS_WORDS_SIZE); with a zero or very short payload the length underflows (wraps), so p_sw and subsequent parsing point outside the GKI buffer, producing an out-of-bounds read.
How the fix works
- libnfc-nci/src/nfc/tags/rw_ci.cc:rw_ci_data_cback, case RW_CI_STATE_ATTRIB: before the memcpy, if p_r_apdu->len < sizeof(p_ci->attrib_res) the function logs an error, frees p_r_apdu with GKI_freebuf, calls rw_ci_handle_error(NFC_STATUS_BAD_RESP, 0, 0) and breaks out of the switch.
- libnfc-nci/src/nfc/tags/rw_ci.cc:rw_ci_data_cback, case RW_CI_STATE_UID: before the 'p_r_apdu->len -= 1' decrement, if p_r_apdu->len < 1 + T4T_RSP_STATUS_WORDS_SIZE the function logs an error, frees the buffer, calls rw_ci_handle_error(NFC_STATUS_BAD_RESP, 0, 0) and breaks. This guarantees the decrement cannot wrap and that (len - T4T_RSP_STATUS_WORDS_SIZE) is non-negative, so p_sw stays inside the payload.
- libnfc-nci/tests/src/rw_ci_test.cc (new): adds RwCiTest.AttribResponseTooShort (len = 1) and RwCiTest.UidResponseTooShort (len = 2) which drive the NFC_RF_CONN_ID data callback with NFC_DATA_CEVT and assert the error path is taken and the state returns to RW_CI_STATE_IDLE.
- rw_ci_handle_error (existing, shown in context) stops the quick timer and reports to rw_cb.p_cback; in the ATTRIB state a non-timeout error maps to RW_CI_INTF_ERROR_EVT, in the UID state a non-timeout error leaves the event at its initial value (0) with rw_data.status = NFC_STATUS_BAD_RESP, which is what the new test expects.
Completeness
- Covers the two states named in the commit (RW_CI_STATE_ATTRIB and RW_CI_STATE_UID) with a minimum-length check placed before any read or decrement.
- The ATTRIB check only guarantees sizeof(p_ci->attrib_res) bytes; the UID check only guarantees 1 + T4T_RSP_STATUS_WORDS_SIZE bytes. The material does not show the rest of the UID-state parsing (status word handling, UID extraction) so whether further per-field length checks exist or are needed after the status words cannot be judged from the diff.
- Other states handled by rw_ci_data_cback (for example RW_CI_STATE_PRESENCE_CHECK, which exists per rw_ci_handle_error) are not touched by this commit; their handling is not shown in the material.
- The generic preamble of rw_ci_data_cback (status checks, p computation) is not shown, so it is unknown whether any other length validation already existed before the switch.
Behavior changes
- Short ATTRIB responses (fewer than sizeof(p_ci->attrib_res) bytes) now abort the CI flow: buffer freed, LOG(ERROR) 'Invalid attrib response length', RW_CI_INTF_ERROR_EVT with NFC_STATUS_BAD_RESP delivered to the RW callback, state returns to RW_CI_STATE_IDLE (per the new test), and rw_ci_send_uid is not issued.
- Short UID responses (fewer than 1 + T4T_RSP_STATUS_WORDS_SIZE bytes) now abort: LOG(ERROR) 'Invalid uid response length', callback invoked with event 0 and status NFC_STATUS_BAD_RESP, state returns to idle.
- No change for well-formed responses.
Per major
- Android 14: not affected per the bulletin; platform/packages/modules/Nfc is not present in the Android 14 security tags, so no fix was applied there.
- Android 15: not affected per the bulletin; platform/packages/modules/Nfc is not present in the Android 15 security tags, so no fix was applied there.
- Android 16: same fix: commit 38cc06501f91 (cherry-pick of d61d8a670948, Change-Id I500f5e8b37376a233e95edc4471766f095cc1786) in android-security-16.0.0_r8; all 8 patched lines present at android-security-16.0.0_r10.
- Android 17: same fix: commit f8325e216e4f with an identical diff in android-security-17.0.0_r1; all 8 patched lines present at android-security-17.0.0_r3.
Unknowns
- The code of rw_ci_data_cback before and after the patched hunks (how p is derived, how the UID bytes are parsed after the status words) is not shown.
- Whether the other states handled by rw_ci_data_cback perform their own length validation.
- The exact value of T4T_RSP_STATUS_WORDS_SIZE and the size of p_ci->attrib_res are inferred only from test comments (attrib_res is 2 bytes; 1 + T4T_RSP_STATUS_WORDS_SIZE = 3, implying a status-word size of 2), not from headers in the material.
- Whether older trees carry rw_ci.cc in a different project location is not shown in the material.