Skip to content

Commit 9b01a51

Browse files
mmhalNipaLocal
authored andcommitted
vsock: Fix transport_{h2g,g2h} TOCTOU
Checking transport_{h2g,g2h} != NULL may race with vsock_core_unregister(). Make sure pointers remain valid. KASAN: null-ptr-deref in range [0x0000000000000118-0x000000000000011f] RIP: 0010:vsock_dev_do_ioctl.isra.0+0x58/0xf0 Call Trace: __x64_sys_ioctl+0x12d/0x190 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 157335d commit 9b01a51

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/vmw_vsock/af_vsock.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,8 @@ static long vsock_dev_do_ioctl(struct file *filp,
25412541

25422542
switch (cmd) {
25432543
case IOCTL_VM_SOCKETS_GET_LOCAL_CID:
2544+
mutex_lock(&vsock_register_mutex);
2545+
25442546
/* To be compatible with the VMCI behavior, we prioritize the
25452547
* guest CID instead of well-know host CID (VMADDR_CID_HOST).
25462548
*/
@@ -2549,6 +2551,8 @@ static long vsock_dev_do_ioctl(struct file *filp,
25492551
else if (transport_h2g)
25502552
cid = transport_h2g->get_local_cid();
25512553

2554+
mutex_unlock(&vsock_register_mutex);
2555+
25522556
if (put_user(cid, p) != 0)
25532557
retval = -EFAULT;
25542558
break;

0 commit comments

Comments
 (0)