* [PATCH] net/nfc: fix skb ownership on data exchange errors
@ 2026-11-18 8:13 Bin Luo
2026-11-18 8:18 ` netdev-bot+sinfo
0 siblings, 1 reply; 2+ messages in thread
From: Bin Luo @ 2026-11-18 8:13 UTC (permalink / raw)
To: oe-linux-nfc; +Cc: johan, david+nfc, netdev, Bin Luo
NFC data exchange callbacks may receive a non-NULL response skb together
with an error. The ownership of the skb is not documented, causing the
rawsock and LLCP error paths to return without freeing it. Digital DEP
also frees the response after invoking the callback, which conflicts
with callback ownership.
Document that the callback takes ownership of a non-NULL skb regardless
of err. Free it on the rawsock and LLCP error paths, clear the Digital
DEP response pointer after the callback, and release the skb when the
NCI loopback connection lookup fails.
Signed-off-by: Bin Luo <luob87709@gmail.com>
---
include/net/nfc/nfc.h | 2 ++
net/nfc/digital_dep.c | 1 +
net/nfc/llcp_core.c | 2 ++
net/nfc/nci/core.c | 1 +
net/nfc/rawsock.c | 5 ++++-
5 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h
index bcafab5c5..d3c2d6735 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);
diff --git a/net/nfc/digital_dep.c b/net/nfc/digital_dep.c
index 968547c30..c7f5378cd 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);
diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
index 74bf81700..3619e12b3 100644
--- a/net/nfc/llcp_core.c
+++ b/net/nfc/llcp_core.c
@@ -1638,6 +1638,8 @@ void nfc_llcp_recv(void *data, struct sk_buff *skb, int err)
if (err < 0) {
pr_err("LLCP PDU receive err %d\n", err);
+ if (skb)
+ kfree_skb(skb);
return;
}
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index 73e3a9647..678f744a2 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -413,6 +413,7 @@ static void nci_nfcc_loopback_cb(void *context, struct sk_buff *skb, int err)
conn_info = nci_get_conn_info_by_conn_id(ndev, ndev->cur_conn_id);
if (!conn_info) {
+ kfree_skb(skb);
nci_req_complete(ndev, NCI_STATUS_REJECTED);
return;
}
diff --git a/net/nfc/rawsock.c b/net/nfc/rawsock.c
index f7d7a599f..3bf65b1fb 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;
+ }
err = rawsock_add_header(skb);
if (err)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] net/nfc: fix skb ownership on data exchange errors
2026-11-18 8:13 [PATCH] net/nfc: fix skb ownership on data exchange errors Bin Luo
@ 2026-11-18 8:18 ` netdev-bot+sinfo
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sinfo @ 2026-11-18 8:18 UTC (permalink / raw)
To: Bin Luo; +Cc: oe-linux-nfc, johan, david+nfc, netdev
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during
development, syzbot report, manual code inspection, LLM or static
analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical
(e.g. found by LLM and not proven at runtime). If it was triggered
please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-18 8:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 8:13 [PATCH] net/nfc: fix skb ownership on data exchange errors Bin Luo
2026-11-18 8:18 ` netdev-bot+sinfo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox