Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Piyus Kedia
Mon, 30 Nov 2026 01:22
[PATCH net v2 1/3] net/nfc: llcp: fix the 16-bit truncation that overruns the SNL response skb
Author: Piyus Kedia
Date: Mon, 30 Nov 2026 01:22
Date: Mon, 30 Nov 2026 01:22
67 lines
12815 bytes
12815 bytes
nfc_llcp_allocate_snl() accumulates the allocation size in a u16 while the
length it is given is a size_t:
u16 size = 0;
...
size += tlv_length;
skb = alloc_skb(size, GFP_KERNEL);
nfc_llcp_recv_snl() builds one SDRES TLV for every SDREQ TLV of a received
SNL PDU and passes the total as tlv_length. Each inbound SDREQ costs
three bytes - type, length, tid - and each SDRES it produces is four, so
the total is four thirds of the PDU and about 48 KiB of SDREQs drives it
past 65535. The sum then wraps, alloc_skb() reserves a fraction of what
is needed, and nfc_llcp_send_snl_sdres() puts every entry of the list
into it anyway:
hlist_for_each_entry_safe(sdp, n, tlv_list, node) {
skb_put_data(skb, sdp->tlv, sdp->tlv_len);
skb_put() runs out of tailroom and trips skb_over_panic(). With 16400
SDREQs the accumulated length is 65600, which truncates to 64:
skbuff: skb_over_panic: text:... len:382 put:4 head:... data:... tail:0
kernel BUG at net/core/skbuff.c:215!
RIP: 0010:skb_over_panic+0xcd/0xd0
skb_put
skb_put_data
nfc_llcp_send_snl_sdres
nfc_llcp_recv_snl
nfc_llcp_rx_skb
nfc_llcp_rx_work
process_scheduled_works
Hold the size in a size_t so the value that reaches alloc_skb() is the one
the caller computed. A request that large may now fail the allocation
instead, which the existing IS_ERR() path in both callers already handles.
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: e0ae7bac06cc ("NFC: llcp: Service Name Lookup SDRES aggregation")
Link: https://lore.kernel.org/netdev/20261123023548.3351531-1-piyus@iiitd.ac.in/
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
net/nfc/llcp_commands.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c
index 80a00938c869..0a3d66e6cd59 100644
--- a/net/nfc/llcp_commands.c
+++ b/net/nfc/llcp_commands.c
@@ -542,7 +542,7 @@ static struct sk_buff *nfc_llcp_allocate_snl(struct nfc_llcp_local *local,
{
struct sk_buff *skb;
struct nfc_dev *dev;
- u16 size = 0;
+ size_t size = 0;
if (local == NULL)
return ERR_PTR(-ENODEV);
--
2.34.1
Re: [PATCH net v2 1/3] net/nfc: llcp: fix the 16-bit truncation that overruns the SNL response skb
Author: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 02:15
Date: Tue, 01 Dec 2026 02:15
118 lines
12221 bytes
12221 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch leaves a remotely triggerable leak on the path it now
relies on.
- [Low] The Signed-off-by chain does not match the recorded authorship.
--
net/nfc: llcp: fix the 16-bit truncation that overruns the SNL response skb
This commit changes the size accumulator in nfc_llcp_allocate_snl() from
u16 to size_t. The SDRES length that nfc_llcp_recv_snl() computes is then
no longer truncated before it reaches alloc_skb(). This prevents the
skb_over_panic() in nfc_llcp_send_snl_sdres() when a peer sends an SNL PDU
with enough SDREQ TLVs to push the total past 65535.
Link: https://lore.kernel.org/netdev/20261123023548.3351531-1-piyus@iiitd.ac.in/
> Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
> Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
[Severity: Low]
This isn't a bug, but the Signed-off-by chain doesn't match the recorded
authorship. The author is Piyus Kedia, but Kapil Vaswani's Signed-off-by
comes first and there is no Co-developed-by tag.
Documentation/process/submitting-patches.rst says the order of the
Signed-off-by tags should reflect the chronological history of the patch.
It also says every Co-developed-by must be immediately followed by the
co-author's Signed-off-by.
If Kapil Vaswani co-developed this, should there be a Co-developed-by tag
for him immediately before his Signed-off-by? If not, should the tags be
reordered, or that one dropped?
> diff --git a/net/nfc/llcp_commands.c b/net/nfc/llcp_commands.c
> index 80a00938c8696..0a3d66e6cd59f 100644
> --- a/net/nfc/llcp_commands.c
> +++ b/net/nfc/llcp_commands.c
> @@ -542,7 +542,7 @@ static struct sk_buff *nfc_llcp_allocate_snl(struct nfc_llcp_local *local,
> {
> struct sk_buff *skb;
> struct nfc_dev *dev;
> - u16 size = 0;
> + size_t size = 0;
[Severity: High]
With size held in a size_t, the full peer-controlled tlv_length now
reaches alloc_skb(size, GFP_KERNEL). The commit message says:
A request that large may now fail the allocation instead, which the
existing IS_ERR() path in both callers already handles.
Is that true for the SDRES caller? If the allocation fails, does
nfc_llcp_send_snl_sdres() leak every entry on tlv_list?
net/nfc/llcp_commands.c:nfc_llcp_send_snl_sdres() {
...
skb = nfc_llcp_allocate_snl(local, tlvs_len);
if (IS_ERR(skb))
return PTR_ERR(skb);
hlist_for_each_entry_safe(sdp, n, tlv_list, node) {
skb_put_data(skb, sdp->tlv, sdp->tlv_len);
hlist_del(&sdp->node);
nfc_llcp_free_sdp_tlv(sdp);
}
...
}
That loop is the only place the entries are freed, and it only runs when
the allocation succeeds.
The caller ignores the return value. llc_sdres_list is a stack-local
HLIST_HEAD, so it goes out of scope with the entries still linked:
net/nfc/llcp_core.c:nfc_llcp_recv_snl() {
...
exit:
...
if (!hlist_empty(&llc_sdres_list))
nfc_llcp_send_snl_sdres(local, &llc_sdres_list, sdres_tlvs_len);
}
nfc_llcp_build_sdres_tlv() builds each entry. It allocates the
nfc_llcp_sdp_tlv struct with kzalloc_obj() and the TLV buffer with
nfc_llcp_build_tlv().
For the commit message's 16400-SDREQ example, that is two slab objects per
SDREQ, or roughly 1 MB per failed response. The 65600-byte skb head is a
costly-order allocation that can fail when memory is fragmented. A remote
peer can also send such SNL PDUs repeatedly.
The SDREQ caller does clean up. nfc_genl_llc_sdreq() in net/nfc/netlink.c
calls nfc_llcp_free_sdp_tlv_list() unconditionally at its free_list label,
after nfc_llcp_send_snl_sdreq() returns.
None of the later patches in this series change this path.
Could the IS_ERR() path in nfc_llcp_send_snl_sdres() free tlv_list?
Alternatively, nfc_llcp_recv_snl() could call
nfc_llcp_free_sdp_tlv_list(&llc_sdres_list) after the send. Either way, the
commit message would need updating to match.
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130012208.1962491-1-piyus%40iiitd.ac.in
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads