Skip to content

Commit aba0c94

Browse files
markovicbudimirkuba-moo
authored andcommitted
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 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 <[email protected]> Signed-off-by: Budimir Markovic <[email protected]> Reviewed-by: Stefano Garzarella <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5f1d1d1 commit aba0c94

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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)