* [PATCH net v2] nfc: llcp: reject PDUs shorter than the LLCP header
@ 2026-07-13 15:58 Doruk Tan Ozturk
2026-07-13 21:15 ` David Laight
0 siblings, 1 reply; 2+ messages in thread
From: Doruk Tan Ozturk @ 2026-07-13 15:58 UTC (permalink / raw)
To: david; +Cc: vadim.fedorenko, horms, oe-linux-nfc, netdev, linux-kernel,
stable
Every LLCP PDU begins with a two-byte header (DSAP/SSAP + PTYPE), but the
receive path never checked that a frame is at least LLCP_HEADER_SIZE bytes
before parsing it.
A peer LLCP PDU travels: NFC-DEP frame -> nfc_tm_data_received() (target /
NCI path) or nfc_llcp_recv() (initiator data-exchange callback) ->
__nfc_llcp_recv() -> rx_work -> nfc_llcp_rx_skb() ->
nfc_llcp_recv_connect(). For a CONNECT (or CC) PDU nfc_llcp_recv_connect()
computes
tlv_array_len = skb->len - LLCP_HEADER_SIZE;
as a size_t and hands it to the TLV walk. When skb->len is 0 or 1 the
subtraction wraps to a huge value and the walk runs far past the skb,
causing an out-of-bounds read; nfc_llcp_ptype()/nfc_llcp_ssap() likewise
read pdu->data[1] for such a short frame.
A nearby NFC device can reach this without authentication; LLCP link
activation happens automatically after NFC-DEP.
Reject PDUs shorter than the LLCP header in __nfc_llcp_recv(), the common
choke point shared by both the target (nfc_llcp_data_received()) and
initiator (nfc_llcp_recv()) receive paths, so a short skb is freed before
the rx_work worker is scheduled.
Reproduced with a KFENCE out-of-bounds read via /dev/virtual_nci on
linux-next.
Found by 0sec (https://0sec.ai) using automated source analysis.
Fixes: d646960f7986 ("NFC: Initial LLCP support")
Cc: stable@vger.kernel.org
Assisted-by: 0sec:claude-opus-4-8
Signed-off-by: Doruk Tan Ozturk <doruk@0sec.ai>
---
v2: move the check into __nfc_llcp_recv() so a short skb is dropped
before the rx_work worker is scheduled (Vadim Fedorenko), which also
covers the initiator nfc_llcp_recv() path. Reword the commit message
(drop the "same guard as AGF" wording) and add a KFENCE reproduction
note.
net/nfc/llcp_core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
index aed5fe1afef0..72b6e707ad0c 100644
--- a/net/nfc/llcp_core.c
+++ b/net/nfc/llcp_core.c
@@ -1565,6 +1565,11 @@ static void nfc_llcp_rx_work(struct work_struct *work)
static void __nfc_llcp_recv(struct nfc_llcp_local *local, struct sk_buff *skb)
{
+ if (skb->len < LLCP_HEADER_SIZE) {
+ kfree_skb(skb);
+ return;
+ }
+
local->rx_pending = skb;
timer_delete(&local->link_timer);
schedule_work(&local->rx_work);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net v2] nfc: llcp: reject PDUs shorter than the LLCP header
2026-07-13 15:58 [PATCH net v2] nfc: llcp: reject PDUs shorter than the LLCP header Doruk Tan Ozturk
@ 2026-07-13 21:15 ` David Laight
0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2026-07-13 21:15 UTC (permalink / raw)
To: Doruk Tan Ozturk
Cc: david, vadim.fedorenko, horms, oe-linux-nfc, netdev, linux-kernel,
stable
On Mon, 13 Jul 2026 17:58:48 +0200
Doruk Tan Ozturk <doruk@0sec.ai> wrote:
> Every LLCP PDU begins with a two-byte header (DSAP/SSAP + PTYPE), but the
> receive path never checked that a frame is at least LLCP_HEADER_SIZE bytes
> before parsing it.
Is there a similar problem with non-linear skb?
Maybe they can't get into this code, but who knows what can happen
with unusual configs.
David
> A peer LLCP PDU travels: NFC-DEP frame -> nfc_tm_data_received() (target /
> NCI path) or nfc_llcp_recv() (initiator data-exchange callback) ->
> __nfc_llcp_recv() -> rx_work -> nfc_llcp_rx_skb() ->
> nfc_llcp_recv_connect(). For a CONNECT (or CC) PDU nfc_llcp_recv_connect()
> computes
>
> tlv_array_len = skb->len - LLCP_HEADER_SIZE;
>
> as a size_t and hands it to the TLV walk. When skb->len is 0 or 1 the
> subtraction wraps to a huge value and the walk runs far past the skb,
> causing an out-of-bounds read; nfc_llcp_ptype()/nfc_llcp_ssap() likewise
> read pdu->data[1] for such a short frame.
>
> A nearby NFC device can reach this without authentication; LLCP link
> activation happens automatically after NFC-DEP.
>
> Reject PDUs shorter than the LLCP header in __nfc_llcp_recv(), the common
> choke point shared by both the target (nfc_llcp_data_received()) and
> initiator (nfc_llcp_recv()) receive paths, so a short skb is freed before
> the rx_work worker is scheduled.
>
> Reproduced with a KFENCE out-of-bounds read via /dev/virtual_nci on
> linux-next.
>
> Found by 0sec (https://0sec.ai) using automated source analysis.
>
> Fixes: d646960f7986 ("NFC: Initial LLCP support")
> Cc: stable@vger.kernel.org
> Assisted-by: 0sec:claude-opus-4-8
> Signed-off-by: Doruk Tan Ozturk <doruk@0sec.ai>
> ---
> v2: move the check into __nfc_llcp_recv() so a short skb is dropped
> before the rx_work worker is scheduled (Vadim Fedorenko), which also
> covers the initiator nfc_llcp_recv() path. Reword the commit message
> (drop the "same guard as AGF" wording) and add a KFENCE reproduction
> note.
>
> net/nfc/llcp_core.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
> index aed5fe1afef0..72b6e707ad0c 100644
> --- a/net/nfc/llcp_core.c
> +++ b/net/nfc/llcp_core.c
> @@ -1565,6 +1565,11 @@ static void nfc_llcp_rx_work(struct work_struct *work)
>
> static void __nfc_llcp_recv(struct nfc_llcp_local *local, struct sk_buff *skb)
> {
> + if (skb->len < LLCP_HEADER_SIZE) {
> + kfree_skb(skb);
> + return;
> + }
> +
> local->rx_pending = skb;
> timer_delete(&local->link_timer);
> schedule_work(&local->rx_work);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-13 21:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-13 15:58 [PATCH net v2] nfc: llcp: reject PDUs shorter than the LLCP header Doruk Tan Ozturk
2026-07-13 21:15 ` David Laight
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox