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, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
Aldo Lacuku <qwe.aldo@gmail.com>,
Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH net] nfc: llcp: prevent resource leak on repeated connect after DM
Date: Thu, 24 Sep 2026 23:35:27 -0300 [thread overview]
Message-ID: <20260925023527.3065197-1-qwe.aldo@gmail.com> (raw)
From: Aldo Lacuku <qwe.aldo@gmail.com>
A nonblocking connect can return while the socket is still connecting.
If the peer rejects the connection with a DM PDU, nfc_llcp_recv_dm()
changes the socket state to LLCP_CLOSED. A subsequent connect() on that
socket currently overwrites the previous local, SAP and service name
without releasing them. Repeated retries therefore leak local references
and SAP allocations until no SAPs remain.
Release any resources left on the socket before obtaining resources for a
new connection. A closed socket can also retain the device reference held
by an asynchronous connect, so drop that reference as well. Bound sockets
do not hold the device reference, so release it only when reconnecting from
LLCP_CLOSED.
Fixes: d646960f7986 ("NFC: Initial LLCP support")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/all/20260923133339.2518641-1-qwe.aldo@gmail.com/
Cc: stable@vger.kernel.org
Signed-off-by: Aldo Lacuku <qwe.aldo@gmail.com>
---
net/nfc/llcp_sock.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
index 5558d8a..e76361e 100644
--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -690,6 +690,23 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr_unsized *_addr
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);
if (dev == NULL) {
ret = -ENODEV;
--
2.43.0
reply other threads:[~2026-09-25 2:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260925023527.3065197-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=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=stable@vger.kernel.org \
/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®