Skip to contentSkip to conversation

vsock: Do not allow binding to VMADDR_PORT_ANY

PATCH Applied Budimir Markovic 3 participants 3 messages Aug 7, 2025 – Aug 8, 2025

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

PATCH 1/1 vsock: Do not allow binding to VMADDR_PORT_ANY

It is possible for a vsock to autobind to VMADDR_PORT_ANY. This can cause a use-after-free when a connection is made to the bound socket. The socket returned by accept() also has port VMADDR_PORT_ANY but is not on the list of unbound sockets. Binding it will result in an extra refcount decrement similar to the one fixed in fcdd2242c023 (vsock: Keep the binding until socket destruction).

Modify the check in __vsock_bind_connectible() to also prevent binding to VMADDR_PORT_ANY.

Fixes d021c344051a ("VSOCK: Introduce VM Sockets")
---
 net/vmw_vsock/af_vsock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/vmw_vsock/af_vsock.c +2 -1
index ead6a3c14..bebb355f3 100644
@@ -689,7 +689,8 @@ static int __vsock_bind_connectible(struct vsock_sock *vsk,
 		unsigned int i;
 
 		for (i = 0; i < MAX_PORT_RETRIES; i++) {
-			if (port <= LAST_RESERVED_PORT)
+			if (port == VMADDR_PORT_ANY ||
+			    port <= LAST_RESERVED_PORT)
 				port = LAST_RESERVED_PORT + 1;
 
 			new_addr.svm_port = port++;
Signature · 1 line
2.49.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Budimir Markovic

It is possible for a vsock to autobind to VMADDR_PORT_ANY. This can cause a use-after-free when a connection is made to the bound socket. The socket returned by accept() also has port VMADDR_PORT_ANY but is not on the list of unbound sockets. Binding it will result in an extra refcount decrement similar to the one fixed in fcdd2242c023 (vsock: Keep the binding until socket destruction).

Modify the check in __vsock_bind_connectible() to also prevent binding to VMADDR_PORT_ANY.

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

---
net/vmw_vsock/af_vsock.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)

Thanks for the fix!

Please next time use ./scripts/get_maintainer.pl to cc all the maintainers and mailing lists.

If this patch will not be merged, resend it (with my R-b) to all the maintainers/list. I'll be offline for the next 2 weeks, so remember to carry my R-b.

Thanks,
Stefano

Quoted 18 lines
net/vmw_vsock/af_vsock.c +2 -1
index ead6a3c14..bebb355f3 100644
@@ -689,7 +689,8 @@ static int __vsock_bind_connectible(struct vsock_sock *vsk,
 		unsigned int i;
 
 		for (i = 0; i < MAX_PORT_RETRIES; i++) {
-			if (port <= LAST_RESERVED_PORT)
+			if (port == VMADDR_PORT_ANY ||
+			    port <= LAST_RESERVED_PORT)
 				port = LAST_RESERVED_PORT + 1;
 
 			new_addr.svm_port = port++;
Signature · 1 line
2.49.1
#2 lore raw
In reply to Budimir Markovic
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

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

Quoted 8 lines · On Thu, 7 Aug 2025 04:18:11 +0000 you wrote:

It is possible for a vsock to autobind to VMADDR_PORT_ANY. This can cause a use-after-free when a connection is made to the bound socket. The socket returned by accept() also has port VMADDR_PORT_ANY but is not on the list of unbound sockets. Binding it will result in an extra refcount decrement similar to the one fixed in fcdd2242c023 (vsock: Keep the binding until socket destruction).

[...]

Here is the summary with links:
- [net] vsock: Do not allow binding to VMADDR_PORT_ANY

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

You are awesome, thank you!

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