Skip to content

Commit 8f01093

Browse files
markovicbudimirgregkh
authored andcommitted
vsock: Do not allow binding to VMADDR_PORT_ANY
commit aba0c94 upstream. 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 fcdd224 (vsock: Keep the binding until socket destruction). Modify the check in __vsock_bind_connectible() to also prevent binding to VMADDR_PORT_ANY. Fixes: d021c34 ("VSOCK: Introduce VM Sockets") Reported-by: Budimir Markovic <markovicbudimir@gmail.com> Signed-off-by: Budimir Markovic <markovicbudimir@gmail.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Link: https://patch.msgid.link/20250807041811.678-1-markovicbudimir@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e50ccfa commit 8f01093

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

net/vmw_vsock/af_vsock.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ static int __vsock_bind_connectible(struct vsock_sock *vsk,
689689
unsigned int i;
690690

691691
for (i = 0; i < MAX_PORT_RETRIES; i++) {
692-
if (port <= LAST_RESERVED_PORT)
692+
if (port == VMADDR_PORT_ANY ||
693+
port <= LAST_RESERVED_PORT)
693694
port = LAST_RESERVED_PORT + 1;
694695

695696
new_addr.svm_port = port++;

0 commit comments

Comments
 (0)