All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tanuj Sharma <ertanuj96@gmail.com>
To: security@kernel.org
Cc: david@ixit.cz, Tanuj Sharma <ertanuj96@gmail.com>,
	stable@vger.kernel.org
Subject: [SECURITY] nfc: llcp: slab-out-of-bounds read in nfc_llcp_recv_dm()
Date: Sat,  5 Dec 2026 03:22:52 +0530	[thread overview]
Message-ID: <20261204215253.33907-1-ertanuj96@gmail.com> (raw)

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

             reply	other threads:[~2026-12-04 21:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 21:52 Tanuj Sharma [this message]
2026-12-05 14:55 ` [SECURITY] nfc: llcp: slab-out-of-bounds read in nfc_llcp_recv_dm() Willy Tarreau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204215253.33907-1-ertanuj96@gmail.com \
    --to=ertanuj96@gmail.com \
    --cc=david@ixit.cz \
    --cc=security@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.