Article View: linux.kernel.netdev
Article #20364Re: [PATCH] net/nfc: fix skb ownership on data exchange errors
From: netdev-bot+sashiko
Date: Sun, 22 Nov 2026 08:30
Date: Sun, 22 Nov 2026 08:30
238 lines
15854 bytes
15854 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 1 (2) ยท 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 skb leaks that users can hit, but it has no
`Fixes:` tag and no `Cc: stable@vger.kernel.org`.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it runs
through the rawsock error branch that the patch modifies.
- [High] This problem wasn't introduced by this patch, but it is in the
function the patch changes.
--
net/nfc: fix skb ownership on data exchange errors
This patch 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 and
LLCP error paths and on the NCI loopback lookup failure, and clears the
Digital DEP response pointer after the callback is 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]
With this rule the callback owns a non-NULL skb whatever err is. Are
there other data_exchange_cb_t implementations that still return early
on error without freeing it?
In drivers/nfc/st21nfca/dep.c, st21nfca_im_recv_atr_res_cb() and
st21nfca_im_recv_dep_res_cb() both start with:
if (err != 0)
return;
They are registered as the callback to nfc_hci_send_cmd_async() from
st21nfca_im_send_atr_req() and st21nfca_im_send_dep_req(). When the chip
answers with a non-OK HCI result, the path is:
nfc_hci_resp_received()
__nfc_hci_cmd_completion(hdev, nfc_hci_result_to_errno(result), skb)
st21nfca_im_recv_atr_res_cb(ctx, skb, err) /* or _dep_res_cb */
return;
Nothing on that path seems to free the response skb. Is it leaked on
every failed ATR_REQ or DEP_REQ? In the DEP_REQ case the upper layer also
never gets a completion.
In net/nfc/nci/hci.c, nci_hci_data_received_cb() has:
if (err) {
nci_req_complete(ndev, err);
return;
}
nci_add_rx_data_frag() can hand the original skb plus a non-zero err to
nci_data_exchange_complete() through its "if (status) { err = status;
goto exit; }" path. This needs NCI_DATA_EXCHANGE to be set when the frame
arrives, because nci_data_exchange_complete() only calls the callback
after test_and_clear_bit(NCI_DATA_EXCHANGE) succeeds.
Should this branch call kfree_skb(skb) as well?
The HCI wrapper callbacks hci_transceive_cb() in net/nfc/hci/core.c,
pn544_hci_data_exchange_cb(), st21nfca_hci_data_exchange_cb() and
microread_im_transceive_cb() all have a default branch like:
default:
if (err == 0)
kfree_skb(skb);
break;
That branch only runs with an unexpected async_cb_type. Under the new
rule, though, wouldn't it leak the skb when err is non-zero?
The subject says this fixes skb ownership on data exchange errors.
Should these callbacks be converted too?
> 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;
[Severity: Low]
This fixes skb leaks that users can reach: rawsock_data_exchange_complete()
and nfc_llcp_recv() on NCI or HCI error completions, and
nci_nfcc_loopback_cb() when the connection lookup fails. Should the
commit carry Fixes: tags and Cc: stable@vger.kernel.org?
The hunks also depend on each other. Before this patch, the exit: path
in digital_in_recv_dep_res() with rc != 0 freed resp after the callback:
if (rc)
kfree_skb(resp);
A backport that took only the rawsock and LLCP hunks would turn Digital
error paths into a double free, for example the NACK bit case
(rc = -EIO; goto exit;).
Could the commit message say that the resp = NULL change has to go
together with the rawsock and LLCP frees?
>
> error:
> kfree(data_exch);
[Severity: High]
This is a pre-existing issue and wasn't introduced by this patch, but it
is in the function being changed. Several error paths in
digital_in_recv_dep_res() jump straight to error: and free data_exch
without ever calling data_exch->cb(). For example:
if (resp->len < size || dep_res->dir != DIGITAL_NFC_DEP_FRAME_DIR_IN ||
dep_res->cmd != DIGITAL_CMD_DEP_RES) {
rc = -EIO;
goto error;
}
The CRC failure path does the same once the NACK retries run out, or
when the frame is shorter than 4 bytes:
PROTOCOL_ERR("14.4.1.6");
goto error;
Other cases:
- the DID bit is set
- the I-PDU PNI does not match
- digital_in_send_nack(), digital_in_send_atn(),
digital_in_send_dep_req(), digital_in_send_saved_skb() or
digital_in_send_rtox() fails
- the ATN/NACK count or the RTOX value is invalid
Take a raw socket connected to an NFC_DEP target on a Digital driver.
rawsock_tx_work() does:
sock_hold(sk);
rc = nfc_data_exchange(dev, target_idx, skb,
rawsock_data_exchange_complete, sk);
Only rawsock_data_exchange_complete() drops that reference and clears
tx_work_scheduled. If the callback never runs, does the socket reference
leak? If so, rawsock_destruct() never calls nfc_deactivate_target() or
nfc_put_device(), the target stays active, and later
nfc_activate_target() calls fail with -EBUSY.
tx_work_scheduled would also stay true, so later sendmsg() calls queue
data that is never sent.
A remote peer can reach these paths by sending a malformed DEP_RES. The
resp = NULL added here sits between exit: and error: and does not cover
them.
[ ... ]
> diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c
> index f7d7a599fade7..3bf65b1fbe255 100644
> --- a/net/nfc/rawsock.c
> +++ b/net/nfc/rawsock.c
> @@ -156,8 +156,11 @@ static void rawsock_data_exchange_complete(void *context, struct sk_buff *skb,
>
> pr_debug("sk=%p err=%d\n", sk, err);
>
> - if (err)
> + if (err) {
> + if (skb)
> + kfree_skb(skb);
> goto error;
> + }
[Severity: High]
This is a pre-existing issue and wasn't introduced by this patch, but
this error branch can get a positive err from the NCI path.
nci_rx_data_packet() does:
nci_add_rx_data_frag(ndev, skb, pbf, conn_id, nci_to_errno(status));
but nci_add_rx_data_frag() declares the last parameter as __u8:
static void nci_add_rx_data_frag(struct nci_dev *ndev,
struct sk_buff *skb,
__u8 pbf, __u8 conn_id, __u8 status)
So a negative errno is truncated to a positive byte. For example,
-ETIMEDOUT (-110) becomes 146 and is passed on as err.
rawsock_report_error() then does:
sk->sk_err = -err;
That leaves sk_err at -146, so sock_error() returns +146. In
rawsock_recvmsg() that value comes back as rc:
skb = skb_recv_datagram(sk, flags, &rc);
if (!skb)
return rc;
Doesn't this make an error look like a 146-byte read with no data
copied?
This affects MIFARE, Jewel, FeliCa and ISO15693 targets on NCI
controllers whenever the frame status byte is non-zero, for example when
the tag leaves the field.
Should the status parameter of nci_add_rx_data_frag() be an int?
>
> err = rawsock_add_header(skb);
> if (err)
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118081341.1514-1-luob87709%40gmail.com
Technical Details
Message-ID:
<179533624147.3135.15529520698659254387@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368608-linux-kernel-netdev=dewy.ruReferences:
<20261118081341.1514-1-luob87709@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368608-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH] net/nfc: fix skb ownership on data exchange errors Date: Sun, 22 Nov 2026 08:30:41 +0000 Organization: Usenet Network Message-ID: <179533624147.3135.15529520698659254387@kernel.org> References: <20261118081341.1514-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="3598947"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:mzMCqNLXqGHewwZsRL+6YY667Zk= sha256:Xm0Do964pw3/ecEjhwbBnhqGTOWmDmT5mMInX89+XUI= sha1:02uf84Mt4ShMDmETKD1YOT4cvZY= sha256:tBJc3IJyZW5vLA/+jUoD+1Oi9QkAgHJM1JPEHsQhV80= 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 A3B3B125D71; Sun, 22 Nov 2026 11:31:04 +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 G9tR6Woq5ZNd; Sun, 22 Nov 2026 11:30:56 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-368608-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 31A2F125D6E; Sun, 22 Nov 2026 11:30:45 +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 B65382AB97; Sun, 22 Nov 2026 08:30:43 +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=1795336243; b=xuCWAFSDTmBlrCxkYRbKihCoc3qWPzqKl2M98O4cFqPlt9C8F6IuKEPVhoXIVDq/+tb7 fpKhuaDCAvp+sd3QGf2wm5Btrm1wIYZBtr/v6J13oeqVO5LJSR0EImBH1b1xNr8xofhR9 3eDHUJZaojhUIDnLWwvCg0rFpsQSb9AEtZxbJbl3y9hMJF5v4vMlF0dLwp9YLdsHocA6u CesStoK1kfPIHtdRJLUcRwv6LlGrCeD0YSQDrdAqZbFujaXKubtIIuqDd23YUX7lKjIFS O5hAUJhC9cJxtP4ikOmG0VDpJRDSQJHtwOpEQAv1qo+HzWZQDatFu8RUqGfNlL7Uc4w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795336243; 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=QghZHONbcC8cXlUHYrkvEWHCcbkwipOQI37JigyXCY4=; b=aE2kxwURgfd8miv+O0Gh9nqEMLKPobW8gNLsgWMp5bGLQLCQLHT1sdizt6vur622EN9e RAnF4kpf7vWKwLQPNFQ1IOv2V4mEj3maoz+V2QS0RH+ZohoUoUuzvm1LAFCPBKMpOBj7J gnQskeBKw9saBU+UzyvsKUIFk3T3psYptJtOgmLVv3K5cZ4Wstpwgt+jDQSW2Shyl0b13 +RolPA2H7FZ/XarUBbvYH2Mt20qWH1aQwwk1o3uZZSKVEPIz/wZu9/fDwqlwb5OYT3zQ4 hjzo/nABW5K2UyxoElQTPdTOO8aMrP8hRgzNFKbIGzZQrGqROkh3w3B9U+bm21Drhfg== 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=iLq5cGQc; 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 671B7606A335; Sun, 22 Nov 2026 08:30:43 +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=iLq5cGQc 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=1795336242; b=mW4N73JjqVODJ+6xJj2iWGEnSRiHh/Ycns7a703/QM2jFursWWtxLe1OKzP0ctUrV2q1 7P3/VGRdU4fDLr/vfqw4/ngAtvRqD7dY2fC2BYCtMs8j4HNRuAON4EknfdQnHNJ7pKHQi gkEcaOCjzQs3aBUuh6gpTaE/5PaWN4S2CI1C5lCkv8gVjk38UoxDfZPyak7/OufLGTlyK 4s9AI2xam+OXKJwtH34k3xDsBGVlIfXz/++ABp/VRvThPVjfHlAcUVAhPOMyqn39zJ3on wmXMnO5864tFsIXApSLQzonQNUrp0fb/yCez+BdFF2k+1/aQfzfS3P2rkxJiEUORFng== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795336242; 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=QghZHONbcC8cXlUHYrkvEWHCcbkwipOQI37JigyXCY4=; b=cl8dnhNuW8Qr+JYsinmteI3NRwhcbUUssimmQK4y8GtfoQZ5TCk5p0wPiJKjqQt7ad9T h/Q8Jet7IfeLVoAiuGpImahGVDPIxeIdHjlFjA97IpFj34YKSTswBkdwypUOjANXbt9xm fNJicX8NAnBEulk6D+sFdMAbX5SdVs6VRzAs5JsEKG9jtyL4ljiFc2c/1Nu12biRffeTm 7jUtHyPr7AbN3YQX9NrqwWXtk/tCzBygUWxouuEhuwsMzKS/VXK6uErddY0tLBMaNQUPD d/etFWQDWjrYJj7KDOyqCBXgKsQ3R5SKWI9ABTqkRLUhXHCA3Mo48crTW+fv/SfNxGQ== 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=iLq5cGQc; 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 8465C606A330; Sun, 22 Nov 2026 08:30:42 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3F8A1F000C4; Sun, 22 Nov 2026 08:30:41 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795336242; bh=QghZHONbcC8cXlUHYrkvEWHCcbkwipOQI37JigyXCY4=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=iLq5cGQc/vWiTcdo4ee7/AsWiieeWDKdVAvRIW8QInXxgsM2G/SkfO6vWhLfO2szX QQM/DkM/bCFN4ppMdjxSP+47NFIt/W3A3rqKFDbuIvxIUD/lfQ74aKPMXyXC/KlSuL HkIfJ3ExOHv4nY/0gnCNGbaB3Q27HqLL4k7BsuCojxg1IJdYnbh1liInuqU0mUOI8h We3n/c50sXSD1QvXjVz1Ee59Ja5u6TCxbgGIUXQAIyAISNtPdo9eq60AKtErYluED9 I7T5sT0MPymg8sGEbO+sacpjo7ZtX64M8c5GVeMNM2zT1sODezzo5VIlZQ2rQx79MJ yeOxKhw1c5OEQ== 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: <20261118081341.1514-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