Skip to content

NFC: Fix stack buffer overflows in MFUL FAST_READ and DESFire file settings parsers#4369

Open
qp-x-qp wants to merge 1 commit into
flipperdevices:devfrom
qp-x-qp:fix/nfc-stack-overflow-mful-desfire
Open

NFC: Fix stack buffer overflows in MFUL FAST_READ and DESFire file settings parsers#4369
qp-x-qp wants to merge 1 commit into
flipperdevices:devfrom
qp-x-qp:fix/nfc-stack-overflow-mful-desfire

Conversation

@qp-x-qp
Copy link
Copy Markdown

@qp-x-qp qp-x-qp commented Apr 9, 2026

mf_ultralight_listener.c:171 — FAST_READ overflow (emulation path)
FAST_READ handler copies page_cnt * 4 bytes into a fixed pages[64]
stack buffer (256 bytes) without validating page_cnt <= 64. For any tag
with pages_total > 64 (NTAG215: 135 pages, NTAG216: 231 pages), a reader
sending FAST_READ with end_page = pages_total - 1 passes the existing
bounds check and triggers an overflow of up to 668 bytes of stack memory.
Fix: reject with NAK if page_cnt > COUNT_OF(pages).

mf_desfire_i.c:278 — access_rights overflow (reader path)
additional_access_rights_len (a count of entries) was checked against
MF_DESFIRE_MAX_KEYS * sizeof(MfDesfireFileAccessRights) (= 28) instead
of MF_DESFIRE_MAX_KEYS - 1 (= 13). A rogue DESFire tag returning
additional_access_rights_len = 28 passes the check but triggers a
memcpy of 56 bytes into a 26-byte stack slot (access_rights[1..13]),
overflowing by 30 bytes of tag-controlled data.
Fix: compare count against MF_DESFIRE_MAX_KEYS - 1.

# Verification
  • FAST_READ: confirmed crash on physical hardware (NTAG216 emulation,
    reader sends end_page=0xE6 — device hard-faults before fix, NAKs after)
  • DESFire: verified by code analysis, both files build clean

…ttings parsers

mf_ultralight_listener.c: FAST_READ handler wrote page_cnt*4 bytes into
a fixed pages[64] stack buffer without checking page_cnt <= 64. For tags
with pages_total > 64 (NTAG215: 135, NTAG216: 231) a reader could trigger
an overflow of up to 668 bytes. Fix: reject requests where page_cnt
exceeds COUNT_OF(pages) with NAK.

mf_desfire_i.c: additional_access_rights_len (a count) was validated
against MF_DESFIRE_MAX_KEYS * sizeof(MfDesfireFileAccessRights) (= 28)
instead of MF_DESFIRE_MAX_KEYS - 1 (= 13), allowing a rogue tag to write
up to 56 bytes into a 26-byte stack slot. Fix: compare count against
MF_DESFIRE_MAX_KEYS - 1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants