Skip to contentSkip to conversation

atm: svc: fix listen state corruption in svc_listen

PATCH In review Ren Wei 2 participants 2 messages Jun 10 – Jun 12 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Ren Wei

author
#1 lore raw

PATCH 1/1 atm: svc: fix listen state corruption in svc_listen

In reply to a message not in the archive

From: Zhao Zhang <[email protected]>

svc_listen() can corrupt the vcc_hash hlist by inserting the same socket twice. The function never validates that listen is only entered from the unconnected state, and it publishes listener state even when the signaling daemon reports an error. A connected socket is already hashed, so calling listen() on it re-adds the same sk_node and causes hlist corruption. A successful listener can also later flow into svc_connect() and get inserted again because listener state was not tracked correctly.

Fix the state machine in net/atm/svc.c. Reject listen on connected or otherwise invalid socket states, only mark the socket as listening after the signaling reply succeeds, record listener state on sk->sk_state, and reject connect on sockets already marked as listeners. This removes the double-insert list-corruption bug at its source.

Fixes 9301e320e98f ("[ATM]: track and close listen sockets when sigd exits")
Assisted-by Codex:GPT-5.4
---
 net/atm/svc.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
net/atm/svc.c +17 -1
index 005964250ecd..dfc4f3762bf8 100644
@@ -168,6 +168,10 @@ static int svc_connect(struct socket *sock, struct sockaddr_unsized *sockaddr,
 		error = -EINVAL;
 		goto out;
 	}
+	if (test_bit(ATM_VF_LISTEN, &vcc->flags)) {
+		error = -EINVAL;
+		goto out;
+	}
 
 	switch (sock->state) {
 	default:
@@ -302,6 +306,14 @@ static int svc_listen(struct socket *sock, int backlog)
 		error = -EADDRINUSE;
 		goto out;
 	}
+	if (sock->state == SS_CONNECTED) {
+		error = -EISCONN;
+		goto out;
+	}
+	if (sock->state != SS_UNCONNECTED) {
+		error = -EINVAL;
+		goto out;
+	}
 	set_bit(ATM_VF_WAITING, &vcc->flags);
 	sigd_enq(vcc, as_listen, NULL, NULL, &vcc->local);
 	for (;;) {
@@ -315,10 +327,14 @@ static int svc_listen(struct socket *sock, int backlog)
 		error = -EUNATCH;
 		goto out;
 	}
+	error = -sk->sk_err;
+	if (error)
+		goto out;
 	set_bit(ATM_VF_LISTEN, &vcc->flags);
+	sk->sk_state = TCP_LISTEN;
 	vcc_insert_socket(sk);
 	sk->sk_max_ack_backlog = backlog > 0 ? backlog : ATM_BACKLOG_DEFAULT;
-	error = -sk->sk_err;
+	error = 0;
 out:
 	release_sock(sk);
 	return error;
Signature · 1 line
2.47.3
maintainer
#2 lore raw

net/atm/svc.c

Quoted 2 lines · On Thu, 11 Jun 2026 01:33:27 +0800 Ren Wei wrote:
net/atm/svc.c +0 -0

I'm going to send a series to remove svc.c shortly.
Could y'all please steer more towards code that has been used in this decade?