Skip to contentSkip to conversation

vsock/vmci: fix sk_ack_backlog leak on failed handshake

PATCH Applied Raf Dickson 4 participants 6 messages May 26 – Jun 4

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vsock/vmci: fix sk_ack_backlog leak on failed handshake

When vmci_transport_recv_connecting_server() returns an error, vmci_transport_recv_listen() calls vsock_remove_pending() but never calls sk_acceptq_removed(). This leaves sk_ack_backlog incremented permanently.

Repeated handshake failures (malformed packets, queue pair alloc failure, event subscribe failure) cause sk_ack_backlog to climb toward sk_max_ack_backlog. Once it reaches the limit the listener permanently refuses all new connections with -ECONNREFUSED, a silent denial of service requiring a process restart to recover.

The two existing sk_acceptq_removed() calls in af_vsock.c do not cover this path: line 764 checks vsock_is_pending() which returns false after vsock_remove_pending(), and line 1889 is only reached on successful accept().

Fix by balancing sk_acceptq_added() with sk_acceptq_removed() on the error path.

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")
---
 net/vmw_vsock/vmci_transport.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/vmw_vsock/vmci_transport.c +3 -1
index d2579380f5..88ccc55455 100644
@@ -980,8 +980,10 @@ static int vmci_transport_recv_listen(struct sock *sk,
 			err = -EINVAL;
 		}
 
-		if (err < 0)
+		if (err < 0) {
 			vsock_remove_pending(sk, pending);
+			sk_acceptq_removed(sk);
+		}
 
 		release_sock(pending);
 		vmci_transport_release_pending(pending);
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 16 lines · Raf Dickson

When vmci_transport_recv_connecting_server() returns an error, vmci_transport_recv_listen() calls vsock_remove_pending() but never calls sk_acceptq_removed(). This leaves sk_ack_backlog incremented permanently.

Repeated handshake failures (malformed packets, queue pair alloc failure, event subscribe failure) cause sk_ack_backlog to climb toward sk_max_ack_backlog. Once it reaches the limit the listener permanently refuses all new connections with -ECONNREFUSED, a silent denial of service requiring a process restart to recover.

The two existing sk_acceptq_removed() calls in af_vsock.c do not cover this path: line 764 checks vsock_is_pending() which returns false after vsock_remove_pending(), and line 1889 is only reached on successful accept().

Quoted 6 lines

Fix by balancing sk_acceptq_added() with sk_acceptq_removed() on the error path.

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")

Waiting for Stefano's feedback - should be back in a couple of days.

Quoted 9 lines
---
 net/vmw_vsock/vmci_transport.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/vmw_vsock/vmci_transport.c +0 -0
index d2579380f5..88ccc55455 100644

net/vmw_vsock/vmci_transport.c static int vmci_transport_recv_listen(struct sock *sk, · line 985

Quoted 7 lines
net/vmw_vsock/vmci_transport.c +2 -1
@@ -980,8 +980,10 @@ static int vmci_transport_recv_listen(struct sock *sk,
 			err = -EINVAL;
 		}
 
-		if (err < 0)
+		if (err < 0) {
 			vsock_remove_pending(sk, pending);
+			sk_acceptq_removed(sk);

I'm wondering if sk_acceptq_removed() should be bounded in vsock_remove_pending() ? (even if that change would probably be net-next material).

/P

Quoted 4 lines
net/vmw_vsock/vmci_transport.c +1 -0
+		}
 
 		release_sock(pending);
 		vmci_transport_release_pending(pending);
#2 lore raw
Quoted 3 lines · Paolo Abeni

I'm wondering if sk_acceptq_removed() should be bounded in vsock_remove_pending() ? (even if that change would probably be net-next material).

Agreed, that would prevent this class of bug entirely. Happy to prepare a follow-up patch for net-next once this fix lands, if that would be useful.

Raf

#3 lore raw
Quoted 8 lines · Raf Dickson
Quoted 3 lines · Paolo Abeni

I'm wondering if sk_acceptq_removed() should be bounded in vsock_remove_pending() ? (even if that change would probably be net-next material).

Agreed, that would prevent this class of bug entirely. Happy to prepare a follow-up patch for net-next once this fix lands, if that would be useful.

And maybe sk_acceptq_added() calls moved in vsock_add_pending().
That said I was wondering about other transports, but it seems both virtio and hyperv have a simplier handshake that doesn't require the pending list, since the socket is moved directly in the accept list.

BTW if you are going to sent a follow up, maybe another improvement (unrelated so another patch) could be to use sk_acceptq_is_full() instead of sk->sk_ack_backlog >= sk->sk_max_ack_backlog. Discovered while comparing vmci with virtio.

Thanks,
Stefano

maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Raf Dickson
Quoted 19 lines · Raf Dickson

When vmci_transport_recv_connecting_server() returns an error, vmci_transport_recv_listen() calls vsock_remove_pending() but never calls sk_acceptq_removed(). This leaves sk_ack_backlog incremented permanently.

Repeated handshake failures (malformed packets, queue pair alloc failure, event subscribe failure) cause sk_ack_backlog to climb toward sk_max_ack_backlog. Once it reaches the limit the listener permanently refuses all new connections with -ECONNREFUSED, a silent denial of service requiring a process restart to recover.

The two existing sk_acceptq_removed() calls in af_vsock.c do not cover this path: line 764 checks vsock_is_pending() which returns false after vsock_remove_pending(), and line 1889 is only reached on successful accept().

Fix by balancing sk_acceptq_added() with sk_acceptq_removed() on the error path.

Quoted 6 lines
Fixes d021c344051a ("VSOCK: Introduce VM Sockets")

---
net/vmw_vsock/vmci_transport.c | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
#5 lore raw
In reply to Raf Dickson
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 5 lines · On Tue, 26 May 2026 10:43:56 +0000 you wrote:

When vmci_transport_recv_connecting_server() returns an error, vmci_transport_recv_listen() calls vsock_remove_pending() but never calls sk_acceptq_removed(). This leaves sk_ack_backlog incremented permanently.

Quoted 7 lines

Repeated handshake failures (malformed packets, queue pair alloc failure, event subscribe failure) cause sk_ack_backlog to climb toward sk_max_ack_backlog. Once it reaches the limit the listener permanently refuses all new connections with -ECONNREFUSED, a silent denial of service requiring a process restart to recover.

[...]

Here is the summary with links:
- vsock/vmci: fix sk_ack_backlog leak on failed handshake

    https://git.kernel.org/netdev/net/c/c05fa14db43e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html