* [PATCH net] vsock: Do not allow binding to VMADDR_PORT_ANY
@ 2025-08-07 4:18 Budimir Markovic
2025-08-07 8:02 ` Stefano Garzarella
2025-08-08 20:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Budimir Markovic @ 2025-08-07 4:18 UTC (permalink / raw)
To: netdev; +Cc: sgarzare, 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.
Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
Reported-by: Budimir Markovic <markovicbudimir@gmail.com>
Signed-off-by: Budimir Markovic <markovicbudimir@gmail.com>
---
net/vmw_vsock/af_vsock.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index ead6a3c14..bebb355f3 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -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++;
--
2.49.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] vsock: Do not allow binding to VMADDR_PORT_ANY
2025-08-07 4:18 [PATCH net] vsock: Do not allow binding to VMADDR_PORT_ANY Budimir Markovic
@ 2025-08-07 8:02 ` Stefano Garzarella
2025-08-08 20:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Stefano Garzarella @ 2025-08-07 8:02 UTC (permalink / raw)
To: Budimir Markovic; +Cc: netdev
On Thu, Aug 07, 2025 at 04:18:11AM +0000, Budimir Markovic 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).
>
>Modify the check in __vsock_bind_connectible() to also prevent binding
>to VMADDR_PORT_ANY.
>
>Fixes: d021c344051a ("VSOCK: Introduce VM Sockets")
>Reported-by: Budimir Markovic <markovicbudimir@gmail.com>
>Signed-off-by: Budimir Markovic <markovicbudimir@gmail.com>
>---
> net/vmw_vsock/af_vsock.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
Thanks for the fix!
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
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
>
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index ead6a3c14..bebb355f3 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -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++;
>--
>2.49.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] vsock: Do not allow binding to VMADDR_PORT_ANY
2025-08-07 4:18 [PATCH net] vsock: Do not allow binding to VMADDR_PORT_ANY Budimir Markovic
2025-08-07 8:02 ` Stefano Garzarella
@ 2025-08-08 20:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-08 20:10 UTC (permalink / raw)
To: Budimir Markovic; +Cc: netdev, sgarzare
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-08 20:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07 4:18 [PATCH net] vsock: Do not allow binding to VMADDR_PORT_ANY Budimir Markovic
2025-08-07 8:02 ` Stefano Garzarella
2025-08-08 20:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).