Article View: linux.kernel.netdev
Article #24905Re: [PATCH net v2 2/3] net/nfc: llcp: take the skb reference before queueing it to the socket
From: netdev-bot+sashiko
Date: Tue, 01 Dec 2026 02:15
Date: Tue, 01 Dec 2026 02:15
169 lines
13951 bytes
13951 bytes
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
Technical Details
Message-ID:
<179609134094.3146.6272369139078752616@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374627-linux-kernel-netdev=dewy.ruReferences:
<20261130012208.1962491-3-piyus@iiitd.ac.in>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-374627-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev 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 Organization: Usenet Network Message-ID: <179609134094.3146.6272369139078752616@kernel.org> References: <20261130012208.1962491-3-piyus@iiitd.ac.in> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="1590632"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:q0P2rrVVejOcOb5QjmQtCHfDuXw= sha256:xylryOvxe8ezRfJVck3I093cvSq2PIMVP9kreEFCXRg= sha1:pGD5l6p5z8Mw7xucOtPs4Vj2GU0= sha256:B+DyeQ0jqbG+8LkDBoIA0f22MeNCoWHUsej5E4GI9WA= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 2DDDC1171F7; Tue, 1 Dec 2026 05:16:04 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j42RtGVmdS-G; Tue, 1 Dec 2026 05:16:00 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-374627-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 5C1BC117165; Tue, 1 Dec 2026 05:15:51 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id A21E3266D0; Tue, 1 Dec 2026 02:15:48 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796091348; b=L2QE/9LY/X9LUARq3Ma++FxTfn+sBTxu5HXyT+0RYoD+EWvN0aEZ2MAhJaM9rakGWX3m wnVGMdI1MOElDZTrmWW/2e0ptXDyOHkiy3jrJ32soQ2QoIDyV2m3AmGovlRYg1dPJeN2/ Zk8P+mzbbAgt8Vb3uNi+MSpk3cKVB60kzlO9l5QA5ZIaAXQHYefieu1es88Dh3NIVU/4z sOX0dDgk5Bxm9MHR6S9tm5X/fSltrehQv+cg/ZNaKpgYECzsKHQCbItpf8CJuft8HEDjL ApjAoyCdm5KJ2+kWRhGYs8zlRnDX873IJCE0FZw+V0ztA+9rOjqF+lSSxj2ctADgD0A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796091348; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=+FusaA5C/OnVYQZCeTSYVVoTorS3jehKTghZ5Ia3OEE=; b=abZ72K8SMIfBEBy8AOqlrxFD2ocVIuDGDS4ZYkZ5maA2r0+7HbHxoCZu4Mc4wmzpIBFg wwftfFj6lODLVLfsb16OH5+DvTucpGR8K8oPEqs9nbDDAThuwM7wPPOtu+5kCh2Y2y8Ai QCCB7RxloyUbMEB1nyutbWgkE7rH7ctN2iqqtMCyh1oZQ52T7kbGtwDJft2AOCCtuKkua ngqMsnxJt3AtzwNu9ch+NuH1J0j0EN3bqy3pstc4BY0m3KfAvaFJjdlnwvungNcKiGdye EmjZy/Lit9kWupXF8lF7m5C3PIOq8EyqdlYk0gYOZYSR4yl3PSYS0gdDiqU3MCufSeA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l+LURjeD; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 67077606A32D; Tue, 1 Dec 2026 02:15:48 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l+LURjeD X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796091342; b=PsRE4Dkruv0N5BUPNytxEwBshFYePZch+K9hWq8RzZEOxhdCCd0tFWnZHrDxUt3khkJ9 uGkJ5pCo9kOwJUUN9DDcQUXJEz8pLhAtuBRhRsyNQWIGkYryIUOfu70xTNp/QaAUtRPb8 chTTCu4DhGrfhfSTBCaFtTzkUZ2HBM4+kKjkfcudKuBEbcvo/LnEyF1hXpgUNszIo7fWx uv9tkImuCD/SQVPL9t+UvwcffIPocEPQGS+OTjvOcxUjzQCUXl83cQ2vuK52P+JRj0WAc trZ1qFX6sfertaSFQMNYGI4OqXd7lNxmoOvkaRAW2FORhh6ZligIbJps75GyStt9jUg== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796091342; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=+FusaA5C/OnVYQZCeTSYVVoTorS3jehKTghZ5Ia3OEE=; b=Zu4hI8vRlnAMh3kXq9OLLiiedTX5s/jAtwZFLpLFG+OhJDPdDNN/8XNaV9VDTl+ITtoC JXw00UdPVGimegL3omgOdlqHelfCpzjO6hb4bj1vleD0w6ai8WobXwjoZEWgZVb7SjqH1 nb5NOGatTN452BMGIqPSsnOzmYouBxRIJP7tKayUCTaZqe3/HkDF6DxMy8NfDqCYJEJyY 2IAwL2cIXwvHXzUSEEgODNymhB9Y2Dhk6zSqOOLS8SRxUj7XupDtciz/ThcHxLhqlidPL SZFmcEiD4E7rKro4RctdzjTn+av6dDbPn6EX7RFmyiAszJ3CBJdifU3hu/kqyp6WoGw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=l+LURjeD; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 84FDB606A337; Tue, 1 Dec 2026 02:15:42 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 697481F000C1; Tue, 1 Dec 2026 02:15:41 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796091342; bh=+FusaA5C/OnVYQZCeTSYVVoTorS3jehKTghZ5Ia3OEE=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=l+LURjeDFPEniIBC32x9K957dZLQ+FRCQJ6nrDuneLXstyqEHG+Ps8lyDsYaK0RGi zE+6wrMREYjPMNZMD+b1Y5cKZXW6rcvxDzkKZfUmukJpekxBsQaCMymUSh0GHGnm8U kP6TuO/6lwySY+BDVkBlcJram1deVDlFBw8xuAqbU+zzlk4NE8/Ozg5FCz3UYLDsXu fy5W1iAQC7plIfWaXM8bTfptsi9fU9s5zyfu2z41r8U63U4xUWV9A/MftRNY10pbJy YbF5Cwcqyv4uDs7nMF7dg/YxGlrnreT4So+C4YUvcEg+hLAVIDvfaucoCykwY8Qpz9 +CF/xyV0jsSoA== X-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 X-In-Reply-To: <20261130012208.1962491-3-piyus@iiitd.ac.in> X-sashiko-severity: Critical X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list