Article View: linux.kernel.netdev
Article #20367Re: [PATCH v2] net/nfc: fix skb ownership on data exchange errors
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 08:39
Date: Sun, 22 Nov 2026 08:39
131 lines
12437 bytes
12437 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 fix is incomplete.
- [Low] The commit fixes a user-reachable skb leak in
rawsock_data_exchange_complete() (net/nfc/rawsock.c) and changes…
--
net/nfc: fix skb ownership on data exchange errors
The commit documents that a data_exchange_cb_t callback takes ownership
of a non-NULL skb regardless of err. It frees the skb on the rawsock,
LLCP and NCI loopback error paths. It also stops digital DEP from
freeing the response after the callback has been invoked.
> diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h
> index bcafab5c53e51..d3c2d67357f1b 100644
> --- a/include/net/nfc/nfc.h
> +++ b/include/net/nfc/nfc.h
> @@ -37,6 +37,8 @@ struct nfc_dev;
> *
> * When a rx or tx package is lost or corrupted or the target gets out
> * of the operating field, err is -EIO.
> + * If skb is non-NULL, ownership is transferred to the callback regardless
> + * of err. Providers must not access or free skb after invoking the callback.
> */
> typedef void (*data_exchange_cb_t)(void *context, struct sk_buff *skb,
> int err);
[Severity: High]
This rule now covers every data_exchange_cb_t implementer. Several
in-tree callbacks still return on error without freeing the skb. Is the
fix complete without them?
In net/nfc/nci/hci.c, nci_hci_data_received_cb() is installed as
conn_info->data_exchange_cb and does:
if (err) {
nci_req_complete(ndev, err);
return;
}
nci_rx_data_packet() strips a status byte for every conn_id, based on
the device-wide ndev->target_active_prot. That status ends up in:
nci_rx_data_packet()
nci_add_rx_data_frag(..., nci_to_errno(status))
nci_data_exchange_complete(ndev, skb, conn_id, err)
cb(cb_context, skb, err);
Suppose an NFCC sends an error-status data packet on the HCI conn_id
while a frame-I/F target is active and an RF transceive is pending.
Wouldn't that skb leak? This is the same provider path that was tested
for rawsock.
On the HCI side, nfc_hci_resp_received() calls:
__nfc_hci_cmd_completion(hdev, nfc_hci_result_to_errno(result), skb);
As a result, every non-OK HCI response reaches the callback registered
by nfc_hci_send_cmd_async() with both a non-NULL skb and a nonzero err.
In drivers/nfc/st21nfca/dep.c, st21nfca_im_recv_atr_res_cb() and
st21nfca_im_recv_dep_res_cb() are registered directly as that callback.
Both start with:
if (err != 0)
return;
Would every HCI error response during NFC-DEP leak the response skb
here? For example, a timeout when the peer leaves the field.
Separately, the ST21NFCA_CB_TYPE_READER_F success branch of
st21nfca_im_recv_atr_res_cb() never frees skb at all.
Four default branches only free on success:
default:
if (err == 0)
kfree_skb(skb);
break;
They are hci_transceive_cb() in net/nfc/hci/core.c,
pn544_hci_data_exchange_cb() in drivers/nfc/pn544/pn544.c,
st21nfca_hci_data_exchange_cb() in drivers/nfc/st21nfca/core.c and
microread_im_transceive_cb() in drivers/nfc/microread/microread.c. Under
the new contract, don't these leak skb when err != 0?
nfc_hci_execute_cb() already frees skb on error, so the in-tree
callbacks end up inconsistent with each other and with the documented
rule. Should these callbacks be updated in the same patch, or at least
mentioned in the commit message?
> diff --git a/net/nfc/digital_dep.c b/net/nfc/digital_dep.c
> index 968547c306a5d..c7f5378cd12e2 100644
> --- a/net/nfc/digital_dep.c
> +++ b/net/nfc/digital_dep.c
> @@ -882,6 +882,7 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
>
> exit:
> data_exch->cb(data_exch->cb_context, resp, rc);
> + resp = NULL;
>
> error:
> kfree(data_exch);
[Severity: Low]
This isn't a bug, but should this carry a Fixes: tag and Cc: stable? The
rawsock_data_exchange_complete() leak can be reached by an unprivileged
user through an NFC raw socket.
The hunks also depend on each other. The resp = NULL in
digital_in_recv_dep_res() stops the provider from freeing resp, and the
rawsock and LLCP hunks make the consumers free it.
A partial backport would either leak or double free the skb. Fixes:
tags would help stable take the change as one unit.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118081530.32-1-luob87709%40gmail.com
Technical Details
Message-ID:
<179533679278.3135.7201159366500267043@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368611-linux-kernel-netdev=dewy.ruReferences:
<20261118081530.32-1-luob87709@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368611-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH v2] net/nfc: fix skb ownership on data exchange errors Date: Sun, 22 Nov 2026 08:39:52 +0000 Organization: Usenet Network Message-ID: <179533679278.3135.7201159366500267043@kernel.org> References: <20261118081530.32-1-luob87709@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3600220"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:aANA0LJGV9URm9hpaXNGg+J0bsA= sha256:bzdOEujdeJ9GaM6/qUN2jlHk9t8VH/gVGE4KtvBH+E4= sha1:7+0L1oPm+zg5/V8SREBlUjJ1U8Q= sha256:X/1olEpkB0/a5JwO5lMjWupgD3oWOC85eW4KU6tjIvs= 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 288A8125D72; Sun, 22 Nov 2026 11:40:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 4JSL8Mf4U7lN; Sun, 22 Nov 2026 11:40:10 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368611-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 207C7125D6E; Sun, 22 Nov 2026 11:39:57 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 0AF4D32214; Sun, 22 Nov 2026 08:39:55 +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=1795336794; b=b1/h6sQh1EeLS6dPajPnKUUKaY5uT0K+M8gJSzLy5+ithRICCO8s3oBOJVGFfhxDlJ4A MtBKRR8oRraL045PwG650AjTr0pr2+mDDstjBW86c2hbBYF8RADd8GqCGDkmeqQ6eRtVi I06RQNSMedSHG3l1nnhOxkICPhAYBKMWtoaRUUVB8cta9mXkAzO1xaRBEk10HPvtVJOgB 1m773Zo6NZFHTNYc8iVXRy1ZkBXIf8IpOOIspcabGYG4Gwkpsa8Fea73Kds11PLw+I4Ha U1DnWfP9WOLS8G2oa15PvJ9nY1wUBl+ojN+cobQIPO0d+YaC0RYzIAFwUKPhJ10givQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795336794; 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=82tcMrGFYnv3COc/Y81tp4EqEYsTMRAGEcxNCdMHdRc=; b=S7feR4VhU3T48ACxi4aY/FFt2rpvZvcnyDjAhwb0ZTR5qeqs3SIiB+jnz2y4P0ulz5HZ hepYg8bUvcevDkirzdRZIK8KG6TjfCCOOhTi2LKrQKi0WCW7Rr05DFuohddhFTiWJEI7u 0V7S9VjVfJp8+BgS02/67SmMmZswrSv4F7IhsGJSuRJzzouaV8gqEPkzH11Rc3sGl8txg tBAqMmvgKMqNsGi1V2ra0hA0MQ5mlm2VRbZl+DjXxq5i0W/ro3pMONgVDbkewt7Llzzry KpTV0r0iNrmDeajf4g9Ibq5VVuqBp/5D7Gv/OruHtPCAu5+KoI9xQEESH0stX1jXJpw== 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=Qd8eb41b; 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 D4ED0606A331; Sun, 22 Nov 2026 08:39:54 +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=Qd8eb41b 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=1795336794; b=TKX/5uAgauGRAYS285JOnlp0DO5oQuXY01a2SqIFjXB1NFMsybV8nVL6Q5m0RAttGOkI LJUSYcqnuZDJ3Hnuz4tEAPA4gWJcQaRP8We2Dz9OXarA+sDhyWNfM9xIcBmdpBbpfzhDd r/vpZRFNt+TBtdzpHD2kDL4hnDKw6YVnGF+hgUUHy6oYcLHj2OG2uLq6VN6e8DHY3MXTE ewWGqPZIckc7g2T2bHM1PXOc8zW89X9nlvUOk/4/x2Xr2AaCtzonpcakInLHWkukSXOzi naV6n2yLMEQeWtUJnWGGJQ9lU6qDn1Pj4KHkmR8vBGXnBb6hFDFHh2os+2/lVldidGQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795336794; 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=82tcMrGFYnv3COc/Y81tp4EqEYsTMRAGEcxNCdMHdRc=; b=SkAAruU1vIoOPyLYrukNZ0eLpl0UJQ20IQAiIt8xwVYhwpXIHeYOjwvsABDl0uAArkAp fCvCvAMQJfsYrf6YQsGUNoSjv100ZdE9L79GCpdWmfN1mtn+SGDclwAD7gn/rQ6Y7jtAy G3rFUsHZxESTkq+5RkHSXR6do0huN0xLGNPT7jAAHDfrymWN8++0nJtDZ5ClCVK00cfbs 58DpzEXY1knMwPAMUYw/aoDtit34MfWiDkf0/1yYTUJrmk/2wIiybIG/uTygnH6aufuMQ 6Vx3vHEuAbJWdC/5CyyFW8V8TiQDctrq+a642X2dIGlKL4h8UYOEc2T6Jo5j7L/b0jA== 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=Qd8eb41b; 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 00EA7606A335; Sun, 22 Nov 2026 08:39:53 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40AB51F000C4; Sun, 22 Nov 2026 08:39:53 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795336793; bh=82tcMrGFYnv3COc/Y81tp4EqEYsTMRAGEcxNCdMHdRc=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Qd8eb41bJedj+mQUUvTaHt6REHI79qptfzrHrEd1wff4Qydzlbv2mRiTbHCjpNoF0 vGrBaUBc9LN3ietU9JGaIeCfTr7chKK5F8DIWztMidhwFUWGE4S55ndJPK0eG/umHd JRydsd62Psp6lmOSDiO8tc+DZwQ/KpA5ttU8lKROnhObZYQ9N3Vtg1MFBqn43MRSgV Lodhbot6dCi1LYHoKZBQC1gUXPYeqjiij5k/2lr8IgufbIk6UzMFvSmxX8dF4Mz1l4 9B5+Ycd/zS77dSSYLAgMLYFWLSGs8ClTy41mV954GSAZ/lyPzypnAmsGVx2AovFbSp qJjsSQIPfuUrw== X-Cc: oe-linux-nfc@lists.linux.dev, johan@kernel.org, david+nfc@ixit.cz, netdev@vger.kernel.org, kuba@kernel.org X-In-Reply-To: <20261118081530.32-1-luob87709@gmail.com> X-sashiko-severity: High 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