Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [SECURITY] nfc: llcp: slab-out-of-bounds read in nfc_llcp_recv_dm()
@ 2026-12-04 21:52 Tanuj Sharma
  0 siblings, 0 replies; only message in thread
From: Tanuj Sharma @ 2026-12-04 21:52 UTC (permalink / raw)
  To: security; +Cc: david, Tanuj Sharma, stable

Hi,

I'm reporting a slab-out-of-bounds read in the NFC LLCP stack,
triggerable over NFC contactless without authentication.

## Bug

In net/nfc/llcp_core.c, nfc_llcp_recv_dm() reads the DM reason code
from skb->data[2]:

    reason = skb->data[2];

However, the entry point __nfc_llcp_recv() only guarantees
LLCP_HEADER_SIZE (2) bytes via pskb_may_pull(skb, LLCP_HEADER_SIZE).
When a 2-byte LLCP PDU arrives with DM ptype, the read at offset 2
is 1 byte past the guaranteed length, causing a slab-out-of-bounds
read.

The same bug is also reachable through the AGF (Aggregated Frame)
code path at line 1499: a 2-byte sub-PDU within an AGF frame passes
the `pdu_len >= LLCP_HEADER_SIZE` check and is dispatched to
nfc_llcp_recv_dm(), triggering the same OOB read.

## Remote trigger

An attacker with an NFC-capable device within contactless range
(~10 cm) can send a 2-byte LLCP PDU with DM ptype (or embed a
2-byte DM sub-PDU inside an AGF frame). No authentication or
pairing is required — this is reachable during the NFC-DEP/LLCP
link activation phase.

## Impact

- 1-byte kernel heap information leak (slab-out-of-bounds read)
- Reachable over NFC contactless, pre-authentication
- The leaked reason byte influences socket state machine decisions
  (LLCP_DM_NOBOUND/LLCP_DM_REJ path selection), potentially
  causing unexpected socket state transitions

## Affected versions

All kernels since commit 5c0560b7a5c6 ("NFC: Handle LLCP
Disconnected Mode frames"), 2012-06-26 — approximately 14 years.
Confirmed still vulnerable in mainline v7.4-rc5.

## KASAN proof

Tested on both x86_64 (kernel 7.3.6) and aarch64 (kernel 7.4-rc5)
with CONFIG_KASAN_GENERIC=y, CONFIG_KASAN_INLINE=y:

  BUG: KASAN: slab-out-of-bounds in trigger_llcp_dm_oob+0x1bc/0x220 [nfc_llcp_dm_oob_poc]
  Read of size 1 at addr ffff0000ce959442 by task insmod/1814

  Allocated by task 1814:
  [stack trace showing 2-byte allocation (kmalloc-8)]

The PoC allocates a 2-byte buffer simulating a DM PDU with only the
LLCP header (ptype=DM, no reason byte), then reads buf[2]. KASAN
reports a 1-byte read past the allocation.

## Fix

Add a length check requiring LLCP_HEADER_SIZE + 1 (3) bytes at the
top of nfc_llcp_recv_dm(), before accessing the reason field:

---
 net/nfc/llcp_core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
index XXXXXXX..XXXXXXX 100644
--- a/net/nfc/llcp_core.c
+++ b/net/nfc/llcp_core.c
@@ -1283,6 +1283,9 @@ static void nfc_llcp_recv_dm(struct nfc_llcp_local *local,
 	u8 dsap, ssap, reason;
 	bool connecting = false;

+	if (skb->len < LLCP_HEADER_SIZE + 1)
+		return;
+
 	dsap = nfc_llcp_dsap(skb);
 	ssap = nfc_llcp_ssap(skb);
 	reason = skb->data[2];
--
2.43.0

Fixes: 5c0560b7a5c6 ("NFC: Handle LLCP Disconnected Mode frames")
Cc: stable@vger.kernel.org

Regards,
Tanuj Sharma

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-04 21:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 21:52 [SECURITY] nfc: llcp: slab-out-of-bounds read in nfc_llcp_recv_dm() Tanuj Sharma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox