* [PATCH net] nfc: llcp: prevent resource leak on repeated connect after DM
@ 2026-09-25 2:35 Aldo Ariel Panzardo
0 siblings, 0 replies; only message in thread
From: Aldo Ariel Panzardo @ 2026-09-25 2:35 UTC (permalink / raw)
To: david, davem, edumazet, kuba, pabeni
Cc: horms, netdev, linux-kernel, stable, Aldo Lacuku, Sashiko
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-09-25 2:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-25 2:35 [PATCH net] nfc: llcp: prevent resource leak on repeated connect after DM Aldo Ariel Panzardo
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®