🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
1 messages
1 total messages Started by Henry Martin Wed, 25 Nov 2026 08:07
[PATCH nfc v3] nfc: llcp: reject bind and connect while the socket is still linked
#22377
Author: Henry Martin
Date: Wed, 25 Nov 2026 08:07
81 lines
13812 bytes
llcp_sock_connect() only rejects LLCP_CONNECTED and LLCP_CONNECTING, so a
socket that is still linked in local->sockets can be linked a second time
into local->connecting_sockets.  That covers bound and listening sockets,
and sockets that a peer moved to LLCP_CLOSED with DISC or DM.

Both lists use sk->sk_node.  When the peer answers with CC,
nfc_llcp_recv_cc() removes the node from the connecting list and links it
back into local->sockets, where the stale bind-time entry makes the node
point to itself.  Every later sk_for_each() over local->sockets then spins
forever with the read lock held, which pins the CPU and stalls RCU, and
the socket is never freed.

The same stale-link case reaches llcp_sock_bind(): nfc_llcp_recv_disc()
and the non-connecting branch of nfc_llcp_recv_dm() move a socket to
LLCP_CLOSED without unlinking it, and bind() only checked sk_state, so
it would link sk_node into local->sockets a second time.

Reject connect() and bind() while sk_node is still linked.  A socket
has to be closed before it can be connected or bound again.

Reproduced on v7.4-rc3 as uid 1000: a soft lockup / RCU stall in
nfc_llcp_sock_from_sn() while walking local->sockets.

This issue was discovered by Tencent CodeBuddy Security.

Link: https://lore.kernel.org/all/20261009092338.3146149-1-bsdhenrymartin@gmail.com/
Fixes: a69f32af86e3 ("NFC: Socket linked list")
Cc: stable@vger.kernel.org
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
v2 -> v3: apply the same sk_hashed() guard to llcp_sock_bind(): a socket
          that a peer moved to LLCP_CLOSED with DISC or DM stays linked
          in local->sockets, and bind() only checked sk_state, so it
          could link sk_node a second time (reported by sashiko's
          review of v2).
v1 -> v2: reject any socket that is still hashed (sk_hashed) instead of only
          LLCP_BOUND, covering bind()+listen()+connect() and sockets left
          linked after DISC/DM.
---
 net/nfc/llcp_sock.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
index 1e5ee4bcde684..c12170dde8401 100644
--- a/net/nfc/llcp_sock.c
+++ b/net/nfc/llcp_sock.c
@@ -86,6 +86,15 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr_unsized *addr, in
 		goto error;
 	}
 
+	/* A peer can move a connected socket to LLCP_CLOSED with DISC or
+	 * DM while it stays linked in local->sockets.  Binding such a
+	 * socket would link sk_node a second time and corrupt the list.
+	 */
+	if (sk_hashed(sk)) {
+		ret = -EBADFD;
+		goto error;
+	}
+
 	dev = nfc_get_device(llcp_addr.dev_idx);
 	if (dev == NULL) {
 		ret = -ENODEV;
@@ -714,6 +723,15 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr_unsized *_addr
 		ret = -EINPROGRESS;
 		goto error;
 	}
+	/* A socket that is still linked in local->sockets must not be linked
+	 * into local->connecting_sockets as well: both lists use sk_node, and
+	 * the CC handler links the node back into local->sockets, which turns
+	 * the stale entry into a self-loop.
+	 */
+	if (sk_hashed(sk)) {
+		ret = -EISCONN;
+		goto error;
+	}
 
 	dev = nfc_get_device(addr->dev_idx);
 	if (dev == NULL) {
-- 
2.53.0
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads