Skip to content

Commit 2586dcc

Browse files
mmhalNipaLocal
authored andcommitted
vsock: Fix transport_g2h TOCTOU
Function may race with vsock_core_unregister(): transport_g2h may become NULL after the NULL check. Protect from a potential null-ptr-deref. KASAN: null-ptr-deref in range [0x0000000000000118-0x000000000000011f] RIP: 0010:vsock_find_cid+0x47/0x90 Call Trace: __vsock_bind+0x4b2/0x720 vsock_bind+0x90/0xe0 __sys_bind+0x14d/0x1e0 __x64_sys_bind+0x6e/0xc0 do_syscall_64+0x92/0x1c0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 Fixes: c0cfa2d ("vsock: add multi-transports support") Signed-off-by: Michal Luczaj <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 6108736 commit 2586dcc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/vmw_vsock/af_vsock.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,10 @@ EXPORT_SYMBOL_GPL(vsock_assign_transport);
533533

534534
bool vsock_find_cid(unsigned int cid)
535535
{
536-
if (transport_g2h && cid == transport_g2h->get_local_cid())
537-
return true;
536+
scoped_guard(mutex, &vsock_register_mutex) {
537+
if (transport_g2h && cid == transport_g2h->get_local_cid())
538+
return true;
539+
}
538540

539541
if (transport_h2g && cid == VMADDR_CID_HOST)
540542
return true;

0 commit comments

Comments
 (0)