From: netdev-bot+sashiko@kernel.org
To: piyus@iiitd.ac.in
Cc: david@ixit.cz, davem@davemloft.net, edumazet@kernel.org,
kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
horms@kernel.org, oe-linux-nfc@lists.linux.dev,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
kapil@presceralabs.ai
Subject: Re: [PATCH net v2 2/3] net/nfc: llcp: take the skb reference before queueing it to the socket
Date: Tue, 01 Dec 2026 02:15:40 +0000 [thread overview]
Message-ID: <179609134094.3146.6272369139078752616@kernel.org> (raw)
In-Reply-To: <20261130012208.1962491-3-piyus@iiitd.ac.in>
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 1 · High: 0 · 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).
- [Critical] The patch does not close the teardown use-after-free that
the commit message names ('a concurrent recvmsg() - or the socket's…
- [Low] The sign-off chain does not match the authorship.
--
net/nfc: llcp: take the skb reference before queueing it to the socket
This patch moves the skb_get() in nfc_llcp_recv_ui() and
nfc_llcp_recv_hdlc() so it runs before sock_queue_rcv_skb(). It also drops
the extra reference with kfree_skb() when queueing fails. The goal is to
stop a concurrent recvmsg() or socket teardown from freeing the skb before
the reference is taken.
Link: https://lore.kernel.org/netdev/20261123023519.3350997-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 is the sign-off chain right here?
Piyus Kedia is the author and the submitter, so his Signed-off-by is
correctly last. Kapil Vaswani's Signed-off-by comes before it, and there is
no Co-developed-by tag.
Documentation/process/submitting-patches.rst makes two points here:
- SoBs that follow the author's SoB come from people who handled and
transported the patch.
- Every Co-developed-by must be immediately followed by that co-author's
Signed-off-by.
If Kapil Vaswani co-developed the fix, could a "Co-developed-by: Kapil
Vaswani <kapil@presceralabs.ai>" line go right before his Signed-off-by?
If he found or analysed the bug instead, would Reported-by or Suggested-by
fit better?
> diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
> index 74bf817007cf2..e988c95cc1722 100644
> --- a/net/nfc/llcp_core.c
> +++ b/net/nfc/llcp_core.c
> @@ -922,14 +922,16 @@ static void nfc_llcp_recv_ui(struct nfc_llcp_local *local,
>
> /* There is no sequence with UI frames */
> skb_pull(skb, LLCP_HEADER_SIZE);
> - if (!sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
> - /*
> - * UI frames will be freed from the socket layer, so we
> - * need to keep them alive until someone receives them.
> - */
> - skb_get(skb);
> - } else {
> + /*
> + * UI frames will be freed from the socket layer, so we need to keep
> + * them alive until someone receives them. Take the reference before
> + * the skb is queued: once it is on the receive queue a concurrent
> + * recvmsg() may already have freed it.
> + */
> + skb_get(skb);
> + if (sock_queue_rcv_skb(&llcp_sock->sk, skb)) {
> pr_err("Receive queue is full\n");
> + kfree_skb(skb);
> }
>
> nfc_llcp_sock_put(llcp_sock);
[Severity: Critical]
Is there still a use-after-free here, now on the struct sock instead of the
skb?
After skb_get() the skb has two users. sock_queue_rcv_skb() then calls
skb_set_owner_r() from __sock_queue_rcv_skb():
net/core/sock.c:__sock_queue_rcv_skb() {
...
skb->dev = NULL;
skb_set_owner_r(skb, sk);
...
}
skb_set_owner_r() sets skb->sk = sk and skb->destructor = sock_rfree, and
charges truesize to sk_rmem_alloc. It does not take a reference on sk.
The rx path keeps its own skb reference. It drops that reference only
after the handler has already called nfc_llcp_sock_put():
nfc_llcp_rx_work()
nfc_llcp_rx_skb()
nfc_llcp_recv_ui()
skb_get(skb)
sock_queue_rcv_skb()
nfc_llcp_sock_put()
...
kfree_skb(local->rx_pending)
nfc_llcp_recv_agf() follows the same pattern, calling kfree_skb(new_skb)
after nfc_llcp_rx_skb(). A remote peer can repeat this for every sub-frame
in one AGF PDU.
Suppose close() runs at the same time. llcp_sock_release() calls
sock_orphan() and then sock_put(). When the last socket reference is
dropped, sk_free() runs __sk_destruct() -> llcp_sock_destruct():
net/nfc/llcp_sock.c:llcp_sock_destruct() {
...
skb_queue_purge(&sk->sk_receive_queue);
...
}
The purge only takes the skb from two users to one, so sock_rfree() does
not run. __sk_destruct() then goes on to sk_prot_free(). sk_free() waits
only on sk_wmem_alloc, not on sk_rmem_alloc.
Later the rx path calls kfree_skb() on its reference. That drops the last
reference, and sock_rfree() runs on the freed socket:
net/core/sock.c:sock_rfree() {
struct sock *sk = skb->sk;
unsigned int len = skb->truesize;
atomic_sub(len, &sk->sk_rmem_alloc);
sk_mem_uncharge(sk, len);
}
nfc_llcp_recv_ui() never takes lock_sock(). close() can therefore finish
at any point between nfc_llcp_sock_get() and nfc_llcp_sock_put().
The I frame path in nfc_llcp_recv_hdlc() has the same shape. The window
opens there once the handler calls release_sock() and
nfc_llcp_sock_put(), while nfc_llcp_rx_work() or nfc_llcp_recv_agf() still
holds the skb.
A second ordering ends the same way. recvmsg() dequeues and frees the skb
(two users down to one, so no destructor runs), and close() then frees the
socket.
The commit message cites the raw-socket path as the model:
if (sock_queue_rcv_skb(sk, nskb))
kfree_skb(nskb);
In that path nskb is a private skb_clone() and the caller keeps no
reference to it, so the queue really owns it. Here the caller keeps a
second reference to an skb that is now owned by the socket.
Would queueing a clone avoid this? Another option would be to hand the
single reference to the queue and not free it in the caller.
The commit message says it closes the race with "the socket's own
teardown" and that "the patched kernel is clean". Yet the same teardown
race still seems to reach freed memory through sock_rfree().
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130012208.1962491-1-piyus%40iiitd.ac.in
next prev parent reply other threads:[~2026-12-01 2:15 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 [this message]
2026-11-30 1:22 ` [PATCH net v2 3/3] net/nfc: nci: do not hand a NULL skb to the nfc core Piyus Kedia
2026-12-01 2:15 ` 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=179609134094.3146.6272369139078752616@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--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=piyus@iiitd.ac.in \
--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