Skip to content

Commit 82af5e0

Browse files
committed
vsock: fix lock inversion in vsock_assign_transport()
jira VULN-80680 cve-bf CVE-2025-38461 commit-author Michal Luczaj <[email protected]> commit f7c877e upstream-diff | Adjusted context due to missing SEQPACKET support Syzbot reported a potential lock inversion deadlock between vsock_register_mutex and sk_lock-AF_VSOCK when vsock_linger() is called. The issue was introduced by commit 687aa0c ("vsock: Fix transport_* TOCTOU") which added vsock_register_mutex locking in vsock_assign_transport() around the transport->release() call, that can call vsock_linger(). vsock_assign_transport() can be called with sk_lock held. vsock_linger() calls sk_wait_event() that temporarily releases and re-acquires sk_lock. During this window, if another thread hold vsock_register_mutex while trying to acquire sk_lock, a circular dependency is created. Fix this by releasing vsock_register_mutex before calling transport->release() and vsock_deassign_transport(). This is safe because we don't need to hold vsock_register_mutex while releasing the old transport, and we ensure the new transport won't disappear by obtaining a module reference first via try_module_get(). Reported-by: [email protected] Tested-by: [email protected] Fixes: 687aa0c ("vsock: Fix transport_* TOCTOU") Cc: [email protected] Cc: [email protected] Signed-off-by: Stefano Garzarella <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]> (cherry picked from commit f7c877e) Signed-off-by: Roxana Nicolescu <[email protected]>
1 parent dd056f7 commit 82af5e0

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

net/vmw_vsock/af_vsock.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -472,12 +472,26 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
472472
goto err;
473473
}
474474

475-
if (vsk->transport) {
476-
if (vsk->transport == new_transport) {
477-
ret = 0;
478-
goto err;
479-
}
475+
if (vsk->transport && vsk->transport == new_transport) {
476+
ret = 0;
477+
goto err;
478+
}
480479

480+
/* We increase the module refcnt to prevent the transport unloading
481+
* while there are open sockets assigned to it.
482+
*/
483+
if (!new_transport || !try_module_get(new_transport->module)) {
484+
ret = -ENODEV;
485+
goto err;
486+
}
487+
488+
/* It's safe to release the mutex after a successful try_module_get().
489+
* Whichever transport `new_transport` points at, it won't go away until
490+
* the last module_put() below or in vsock_deassign_transport().
491+
*/
492+
mutex_unlock(&vsock_register_mutex);
493+
494+
if (vsk->transport) {
481495
/* transport->release() must be called with sock lock acquired.
482496
* This path can only be taken during vsock_stream_connect(),
483497
* where we have already held the sock lock.
@@ -497,20 +511,6 @@ int vsock_assign_transport(struct vsock_sock *vsk, struct vsock_sock *psk)
497511
vsk->peer_shutdown = 0;
498512
}
499513

500-
/* We increase the module refcnt to prevent the transport unloading
501-
* while there are open sockets assigned to it.
502-
*/
503-
if (!new_transport || !try_module_get(new_transport->module)) {
504-
ret = -ENODEV;
505-
goto err;
506-
}
507-
508-
/* It's safe to release the mutex after a successful try_module_get().
509-
* Whichever transport `new_transport` points at, it won't go away until
510-
* the last module_put() below or in vsock_deassign_transport().
511-
*/
512-
mutex_unlock(&vsock_register_mutex);
513-
514514
ret = new_transport->init(vsk, psk);
515515
if (ret) {
516516
module_put(new_transport->module);

0 commit comments

Comments
 (0)