[BUG] net/nfc: nci_add_rx_data_frag() hands a NULL skb to the nfc core when the reassembly cannot grow

From: Piyus Kedia

Date: Sun Nov 22 2026 - 21:35:24 EST


Hello,

nci_add_rx_data_frag() frees the skb and sets the local pointer to NULL when
it cannot make room for the data accumulated so far, and then falls through
to the exit path it shares with the success case. In target mode that NULL
is passed to nfc_tm_data_received(), and the LLCP receive path dereferences
it.

Reproduced on net.git main at af6737b90668 ("net: af_key: fix use-after-free
in dump_sp()"), 7.4.0-rc3-01164, with KASAN. A patch is in the next mail of
this thread.


1. Root cause

net/nfc/nci/data.c, nci_add_rx_data_frag():

if (ndev->rx_data_reassembly) {
reassembly_len = ndev->rx_data_reassembly->len;

/* first, make enough room for the already accumulated data */
if (skb_cow_head(skb, reassembly_len)) {
pr_err("error adding room for accumulated rx data\n");

kfree_skb(skb);
skb = NULL; <-- cleared here

kfree_skb(ndev->rx_data_reassembly);
ndev->rx_data_reassembly = NULL;

err = -ENOMEM;
goto exit; <-- and carried into the exit path
}
...
exit:
if (ndev->nfc_dev->rf_mode == NFC_RF_TARGET) {
/* Data received in Target mode, forward to nfc core */
err = nfc_tm_data_received(ndev->nfc_dev, skb);
if (err)
pr_err("unable to handle received data\n");
} else {
nci_data_exchange_complete(ndev, skb, conn_id, err);
}

nfc_tm_data_received() does not test the skb (its only NULL test is on
dev->dep_link_up), nfc_llcp_data_received() tests the LLCP local and not the
skb, and __nfc_llcp_recv() then dereferences it:

static void __nfc_llcp_recv(struct nfc_llcp_local *local, struct sk_buff *skb)
{
if (!pskb_may_pull(skb, LLCP_HEADER_SIZE)) {

pskb_may_pull() reads skb->len, which is offset 0x70 on this build - the
address in the report below.

The other branch is already correct: nci_data_exchange_complete() accepts a
NULL skb (it prints "len %d" as `skb ? skb->len : 0` and passes it to the
callback with the error), which is how the pending data exchange learns the
fragment was lost.


2. How the failing branch is reached

skb_cow_head() has to fail, and the length it is asked for is the
accumulated reassembly:

reassembly_len = ndev->rx_data_reassembly->len;
if (skb_cow_head(skb, reassembly_len)) {

A peer controls that length. Each PBF_CONT fragment is appended to
ndev->rx_data_reassembly, and the next fragment's head must then be expanded
by the whole accumulated size with a GFP_ATOMIC allocation inside
pskb_expand_head(). Growing the reassembly to a few hundred KiB with
PBF_CONT fragments and then sending one more makes the expansion fail
reliably rather than occasionally - the reproducer does exactly this, with
64 KiB fragments, and faults on the first run every time.


3. KASAN report

net.git main, 7.4.0-rc3-01164-gaf6737b90668, KASAN (full log attached as
kasan-nfc-nci-null-skb-mainline-7.4-rc3.txt):

BUG: KASAN: null-ptr-deref in nfc_llcp_data_received+0x93
Read of size 4 at addr 0000000000000070 by task kworker/u8:0/13
Workqueue: nfc2_nci_rx_wq nci_rx_work
skb_headlen include/linux/skbuff.h:2527
pskb_may_pull_reason include/linux/skbuff.h:2860
pskb_may_pull include/linux/skbuff.h:2875
__nfc_llcp_recv net/nfc/llcp_core.c:1625
nfc_llcp_data_received net/nfc/llcp_core.c:1657
nfc_tm_data_received
nci_add_rx_data_frag
nci_rx_work

The same reproducer on 7.3.1 gives the same fault named one frame deeper
(null-ptr-deref in skb_headlen, kasan-nfc-nci-null-skb-7.3.1.txt), because
net/ is built there without inlining.


4. Impact

A NULL dereference in the NCI receive workqueue: an oops that kills the
worker and, with panic_on_oops, the machine. It is a denial of service, not
a corruption - address 0x70 is not mappable on any supported configuration.

Reachable by whoever can deliver NCI target-mode data to the device: an NFC
peer over the air, or a local process owning an NFC device. The only extra
condition is memory pressure the same peer creates by choosing the
reassembly length.


5. Reproducer

nfc_nci_reassembly_null_skb.c in this directory (sent off-list on request).
It brings up a virtual NCI device, activates target mode, accumulates a
large reassembly with PBF_CONT fragments and then sends the final fragment.


6. Suggested fix

Test the skb before forwarding it, leaving the other branch alone:

+ if (skb) {
+ err = nfc_tm_data_received(ndev->nfc_dev, skb);
+ if (err)
+ pr_err("unable to handle received data\n");
+ }

Returning early from the failure site instead would be smaller, but it would
skip nci_data_exchange_complete() in initiator mode and leave a pending data
exchange uncompleted, so the test belongs in the target-mode branch.

The patch follows in this thread. Checkpatch is clean.


7. What was and was not checked

Checked: the fault reproduces on net.git main under KASAN; the patched
kernel is clean on the same reproducer; nci_data_exchange_complete() handles
a NULL skb on every path (verified by reading it, not by inference);
ordinary NCI fragment reassembly still delivers with the patch applied;
net/nfc/nci/data.c is byte-identical between 7.3.1 and af6737b90668.

Not checked: real hardware; an over-the-air peer. We also did not audit the
other callers of nfc_tm_data_received() (pn533, pn544, st21nfca, microread,
digital_dep) for the same pattern - they pass skbs they own, but we have not
tested them.

No Fixes: tag is given: the NULL assignment dates from the NCI reassembly
support and our clone of net.git does not reach that commit. Happy to add
the exact tag if you would like one.

This was found by AI-driven fuzzing built on top of syzkaller; its analysis
was then checked by hand against the code and every claim above was
reproduced.

Kapil Vaswani
Piyus Kedia