From: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
To: david@ixit.cz, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com
Cc: horms@kernel.org, oe-linux-nfc@lists.linux.dev,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org,
syzbot+ci3c472c63e196fe9e@syzkaller.appspotmail.com,
Aldo Ariel Panzardo <qwe.aldo@gmail.com>,
Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH net v3] nfc: llcp: prevent resource leak on repeated connect after DM
Date: Mon, 28 Sep 2026 00:57:49 -0300 [thread overview]
Message-ID: <20260928035749.2305913-1-qwe.aldo@gmail.com> (raw)
In-Reply-To: <20260925184857.357926-1-qwe.aldo@gmail.com>
A rejected asynchronous connect leaves a local reference, SAP allocation,
service name and device reference on a closed socket. Release them before
retrying connect.
The device pointer alone does not prove ownership: bind() puts its
temporary device reference while retaining the pointer. When device
teardown closes a bound socket, the retry cleanup would put that device
again. Clear the pointer when a bound or listening socket becomes closed,
and after a connected socket's device reference is put. Do the same when
DM closes a bound or listening socket. A DM rejected connect keeps its
device reference until the retry cleanup, so retain that put there.
Fixes: d646960f7986 ("NFC: Initial LLCP support")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://ci.syzbot.org/findings/64002827-5231-4183-bfca-0d91bded8543/syz_repro
Cc: stable@vger.kernel.org
Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@gmail.com>
---
v3: Clear non-owning or already released device pointers on close, while
preserving the device put for rejected asynchronous connects.
net/nfc/llcp_core.c | 12 +++++++++++-
net/nfc/llcp_sock.c | 17 +++++++++++++++++
2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/net/nfc/llcp_core.c b/net/nfc/llcp_core.c
index 199543c47eef..6382aacca69a 100644
--- a/net/nfc/llcp_core.c
+++ b/net/nfc/llcp_core.c
@@ -95,8 +95,14 @@
nfc_llcp_socket_purge(llcp_sock);
- if (sk->sk_state == LLCP_CONNECTED)
+ if (sk->sk_state == LLCP_CONNECTED) {
nfc_put_device(llcp_sock->dev);
+ llcp_sock->dev = NULL;
+ } else if (sk->sk_state == LLCP_BOUND ||
+ sk->sk_state == LLCP_LISTEN) {
+ /* bind() already dropped its temporary device reference. */
+ llcp_sock->dev = NULL;
+ }
if (sk->sk_state == LLCP_LISTEN) {
struct nfc_llcp_sock *lsk, *n;
@@ -1330,6 +1336,10 @@
if (connecting)
nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
+ /* Bound and listening sockets do not own a device reference. */
+ if (sk->sk_state == LLCP_BOUND || sk->sk_state == LLCP_LISTEN)
+ llcp_sock->dev = NULL;
+
sk->sk_err = ENXIO;
sk->sk_state = LLCP_CLOSED;
sk->sk_state_change(sk);
diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
index 1e5ee4bcde68..9d76c12aee01 100644
--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -713,6 +713,23 @@
if (sk->sk_state == LLCP_CONNECTING) {
ret = -EINPROGRESS;
goto error;
+ }
+
+ if (sk->sk_state == LLCP_CLOSED) {
+ /* Release resources retained by a previous failed connection. */
+ if (llcp_sock->local) {
+ if (llcp_sock->reserved_ssap < LLCP_SAP_MAX)
+ nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
+ nfc_llcp_local_put(llcp_sock->local);
+ }
+ if (llcp_sock->dev)
+ nfc_put_device(llcp_sock->dev);
+ kfree(llcp_sock->service_name);
+ llcp_sock->local = NULL;
+ llcp_sock->dev = NULL;
+ llcp_sock->service_name = NULL;
+ llcp_sock->service_name_len = 0;
+ llcp_sock->reserved_ssap = LLCP_SAP_MAX;
}
dev = nfc_get_device(addr->dev_idx);
--
2.43.0
next prev parent reply other threads:[~2026-09-28 3:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 18:48 [PATCH net v2] " Aldo Ariel Panzardo
2026-09-27 22:32 ` [syzbot ci] " syzbot ci
2026-09-28 3:57 ` Aldo Ariel Panzardo [this message]
2026-09-28 9:53 ` [PATCH net v2] " 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=20260928035749.2305913-1-qwe.aldo@gmail.com \
--to=qwe.aldo@gmail.com \
--cc=davem@davemloft.net \
--cc=david@ixit.cz \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--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=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
--cc=syzbot+ci3c472c63e196fe9e@syzkaller.appspotmail.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
all inboxes | Powered by JetHome®