From: Piyus Kedia <piyus@iiitd.ac.in>
To: David Heidelberg <david@ixit.cz>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Willem de Bruijn <willemb@google.com>,
Simon Horman <horms@kernel.org>
Cc: oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
Kapil Vaswani <kapil@presceralabs.ai>
Subject: [PATCH net v2 3/3] net/nfc: nci: do not hand a NULL skb to the nfc core
Date: Mon, 30 Nov 2026 06:52:08 +0530 [thread overview]
Message-ID: <20261130012208.1962491-4-piyus@iiitd.ac.in> (raw)
In-Reply-To: <20261130012208.1962491-1-piyus@iiitd.ac.in>
nci_add_rx_data_frag() frees the skb and clears the local pointer when it
cannot make room for the data accumulated so far, then falls through to the
exit path shared with the success case:
if (skb_cow_head(skb, reassembly_len)) {
pr_err("error adding room for accumulated rx data\n");
kfree_skb(skb);
skb = NULL;
...
err = -ENOMEM;
goto exit;
}
...
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);
In target mode that NULL reaches nfc_llcp_data_received(), whose own NULL
test is on the LLCP local and not on the skb, and __nfc_llcp_recv() then
dereferences it in pskb_may_pull():
BUG: KASAN: null-ptr-deref in nfc_llcp_data_received
Read of size 4 at addr 0000000000000070 by task kworker/u8:0/13
skb_headlen
pskb_may_pull_reason
pskb_may_pull
__nfc_llcp_recv
nfc_llcp_data_received
nfc_tm_data_received
Test the skb before forwarding it. The other branch,
nci_data_exchange_complete(), already accepts a NULL skb and reports the
error to the pending data exchange, so only the target-mode call needs it -
and returning early instead would leave that exchange uncompleted.
A peer reaches the failing branch by growing the reassembly with PBF_CONT
fragments until the GFP_ATOMIC head expansion for the accumulated length
cannot be satisfied.
How this was found: by AI-driven fuzzing built on top of syzkaller. Its
analysis was then checked by hand against the code, the fault was
reproduced on net.git main under KASAN, and the patched kernel is clean on
the same reproducer with ordinary NFC LLCP traffic unaffected.
Fixes: 122c195872e9 ("NFC: NCI: Forward data received in Target mode to nfc core")
Link: https://lore.kernel.org/netdev/20261123023446.3350387-1-piyus@iiitd.ac.in/
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
net/nfc/nci/data.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/net/nfc/nci/data.c b/net/nfc/nci/data.c
index 4253edea5c8d..d7597fbd2a64 100644
--- a/net/nfc/nci/data.c
+++ b/net/nfc/nci/data.c
@@ -258,10 +258,17 @@ static void nci_add_rx_data_frag(struct nci_dev *ndev,
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");
+ /*
+ * Data received in Target mode, forward to nfc core. skb is
+ * NULL when the reassembly above could not make room for the
+ * accumulated data; there is nothing left to forward and the
+ * core would dereference it.
+ */
+ if (skb) {
+ 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);
}
--
2.34.1
next prev parent reply other threads:[~2026-11-30 1:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 1:22 [PATCH net v2 0/3] net/nfc: three peer-reachable skb bugs in LLCP and NCI Piyus Kedia
2026-11-30 1:22 ` [PATCH net v2 1/3] net/nfc: llcp: fix the 16-bit truncation that overruns the SNL response skb Piyus Kedia
2026-12-01 2:15 ` netdev-bot+sashiko
2026-11-30 1:22 ` [PATCH net v2 2/3] net/nfc: llcp: take the skb reference before queueing it to the socket Piyus Kedia
2026-12-01 2:15 ` netdev-bot+sashiko
2026-11-30 1:22 ` Piyus Kedia [this message]
2026-12-01 2:15 ` [PATCH net v2 3/3] net/nfc: nci: do not hand a NULL skb to the nfc core netdev-bot+sashiko
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=20261130012208.1962491-4-piyus@iiitd.ac.in \
--to=piyus@iiitd.ac.in \
--cc=davem@davemloft.net \
--cc=david@ixit.cz \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kapil@presceralabs.ai \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oe-linux-nfc@lists.linux.dev \
--cc=pabeni@redhat.com \
--cc=willemb@google.com \
/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
all inboxes | Powered by JetHome®