* [PATCH v2] nfc: llcp: Fix nfc_dev refcount leak in connect
@ 2026-07-20 19:37 Shuangpeng Bai
0 siblings, 0 replies; only message in thread
From: Shuangpeng Bai @ 2026-07-20 19:37 UTC (permalink / raw)
To: david, oe-linux-nfc
Cc: davem, edumazet, kuba, pabeni, horms, netdev, linux-kernel,
Shuangpeng Bai
llcp_sock_connect() takes a reference to the NFC device and keeps it
while a connection is active. For a nonblocking connection,
sock_wait_state() returns -EINPROGRESS while the socket remains in
LLCP_CONNECTING.
If the socket is released before reaching LLCP_CONNECTED,
llcp_sock_destruct() does not drop the reference because it only handles
connected sockets.
Drop the device reference in llcp_sock_release() when unlinking a
connecting socket. At this point llcp_sock->dev is still valid, unlike
after a failed blocking connection has cleared it.
Fixes: b4011239a08e ("NFC: llcp: Fix non blocking sockets connections")
Link: https://lore.kernel.org/r/20260707183518.1888697-1-shuangpeng.kernel@gmail.com
Signed-off-by: Shuangpeng Bai <shuangpeng.kernel@gmail.com>
---
Changes in v2:
- Move the device put from llcp_sock_destruct() to llcp_sock_release()
to avoid dereferencing a NULL llcp_sock->dev after a failed blocking
connect.
- Add Fixes and Link tags.
net/nfc/llcp_sock.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
index feab29fc62f4..0a3d87c2c9b3 100644
--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -633,10 +633,12 @@ static int llcp_sock_release(struct socket *sock)
if (sock->type == SOCK_RAW)
nfc_llcp_sock_unlink(&local->raw_sockets, sk);
- else if (sk->sk_state == LLCP_CONNECTING)
+ else if (sk->sk_state == LLCP_CONNECTING) {
nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
- else
+ nfc_put_device(llcp_sock->dev);
+ } else {
nfc_llcp_sock_unlink(&local->sockets, sk);
+ }
if (llcp_sock->reserved_ssap < LLCP_SAP_MAX)
nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-20 19:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 19:37 [PATCH v2] nfc: llcp: Fix nfc_dev refcount leak in connect Shuangpeng Bai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox