Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: Tanuj Sharma <ertanuj96@gmail.com>
Cc: security@kernel.org, david@ixit.cz, stable@vger.kernel.org
Subject: Re: [SECURITY] nfc: llcp: slab-out-of-bounds read in nfc_llcp_recv_dm()
Date: Sat, 5 Dec 2026 15:55:46 +0100	[thread overview]
Message-ID: <axQl8n7FN19H1isD@1wt.eu> (raw)
In-Reply-To: <20261204215253.33907-1-ertanuj96@gmail.com>

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

      reply	other threads:[~2026-12-05 14:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=axQl8n7FN19H1isD@1wt.eu \
    --to=w@1wt.eu \
    --cc=david@ixit.cz \
    --cc=ertanuj96@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox