All of lore.kernel.org
 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
  2026-12-05 14:55 ` Willy Tarreau
  0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread

* Re: [SECURITY] nfc: llcp: slab-out-of-bounds read in nfc_llcp_recv_dm()
  2026-12-04 21:52 [SECURITY] nfc: llcp: slab-out-of-bounds read in nfc_llcp_recv_dm() Tanuj Sharma
@ 2026-12-05 14:55 ` Willy Tarreau
  0 siblings, 0 replies; 2+ messages in thread
From: Willy Tarreau @ 2026-12-05 14:55 UTC (permalink / raw)
  To: Tanuj Sharma; +Cc: security, david, stable

Hello,

On Sat, Dec 05, 2026 at 03:22:52AM +0530, Tanuj Sharma wrote:
> 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

Please have a look at Documentation/process/submitting-patches.rst. It
explains what's needed in a patch. Above, yours is almost correct (in the
form, I'm not judging the contents not being a subsystem maintainer), but
it lacks a subject, a description and a signed-off-by, so a maintainer
will have to either spend time composing something from your description
and commit it themself, marking you only as reported-by, or ask you to
resubmit. Please always provide a patch in an applicable form (the output
of git format-patch), making sure it passes checkpatch.pl. This will save
some maintainers time and is the best way to see your work credited.

Thanks,
Willy

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05 14:55 UTC | newest]

Thread overview: 2+ messages (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
2026-12-05 14:55 ` Willy Tarreau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.