* [PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close
@ 2026-11-30 4:59 Hu Xinyao
2026-11-30 13:23 ` Michal Luczaj
0 siblings, 1 reply; 2+ messages in thread
From: Hu Xinyao @ 2026-11-30 4:59 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella
Cc: Bobby Eshleman, Michael S. Tsirkin, Jason Wang, Eugenio Perez,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
virtualization, kvm, netdev, linux-kernel
virtio_transport_close() takes a socket reference and schedules
vsk->close_work with vsk->close_work_scheduled set.
Once a worker dequeues close_work, WORK_STRUCT_PENDING_BIT is cleared
before virtio_transport_close_timeout() acquires lock_sock(sk). If a
peer RST or SHUTDOWN arrives while close_timeout is waiting for the
socket lock, virtio_transport_do_close(vsk, true) sets SOCK_DONE and
calls virtio_transport_cancel_close_work(vsk, true), where
cancel_delayed_work() returns false and skips releasing the close_work
socket reference and removing the socket.
When virtio_transport_close_timeout() then acquires lock_sock(sk), it
sees SOCK_DONE already set, skips virtio_transport_do_close(vsk, false),
and clears vsk->close_work_scheduled, permanently leaking the socket
reference (and on OP_RST, leaving the socket in the connected table).
Call virtio_transport_cancel_close_work(vsk, false) when SOCK_DONE is
already set so whichever side runs last completes the cleanup.
Found during a GLM-5.4-assisted code audit and verified manually against
mainline; compile-tested only (not triggered at runtime).
Fixes: 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")
Cc: stable@vger.kernel.org
Signed-off-by: Hu Xinyao <huxinyao@kylinsec.com.cn>
---
net/vmw_vsock/virtio_transport_common.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 1e762a4..9dade6e 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -1411,10 +1411,10 @@ static void virtio_transport_close_timeout(struct work_struct *work)
(void)virtio_transport_reset(vsk, NULL);
virtio_transport_do_close(vsk, false);
+ } else {
+ virtio_transport_cancel_close_work(vsk, false);
}
- vsk->close_work_scheduled = false;
-
release_sock(sk);
sock_put(sk);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close
2026-11-30 4:59 [PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close Hu Xinyao
@ 2026-11-30 13:23 ` Michal Luczaj
0 siblings, 0 replies; 2+ messages in thread
From: Michal Luczaj @ 2026-11-30 13:23 UTC (permalink / raw)
To: Hu Xinyao, Stefan Hajnoczi, Stefano Garzarella
Cc: Bobby Eshleman, Michael S. Tsirkin, Jason Wang, Eugenio Perez,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
virtualization, kvm, netdev, linux-kernel
On 11/30/26 05:59, Hu Xinyao wrote:
> virtio_transport_close() takes a socket reference and schedules
> vsk->close_work with vsk->close_work_scheduled set.
>
> Once a worker dequeues close_work, WORK_STRUCT_PENDING_BIT is cleared
> before virtio_transport_close_timeout() acquires lock_sock(sk). If a
> peer RST or SHUTDOWN arrives while close_timeout is waiting for the
> socket lock, virtio_transport_do_close(vsk, true) sets SOCK_DONE and
> calls virtio_transport_cancel_close_work(vsk, true), where
> cancel_delayed_work() returns false and skips releasing the close_work
> socket reference and removing the socket.
>
> When virtio_transport_close_timeout() then acquires lock_sock(sk), it
> sees SOCK_DONE already set, skips virtio_transport_do_close(vsk, false),
> and clears vsk->close_work_scheduled, permanently leaking the socket
> reference (and on OP_RST, leaving the socket in the connected table).
Right, the leak is real. And netdev bot reported it some time ago [1].
Not sure what's the status of that series, though.
[1]
https://lore.kernel.org/netdev/179003303663.2160803.2038691427232135222@kernel.org/
> Call virtio_transport_cancel_close_work(vsk, false) when SOCK_DONE is
> already set so whichever side runs last completes the cleanup.
>
> Found during a GLM-5.4-assisted code audit and verified manually against
> mainline; compile-tested only (not triggered at runtime).
I'm really curious: did you/GLM try to trigger the leak (and fail), or you
just didn't try triggering it in the first place?
thanks,
Michal
> Fixes: 06a8fc78367d ("VSOCK: Introduce virtio_vsock_common.ko")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hu Xinyao <huxinyao@kylinsec.com.cn>
> ---
> net/vmw_vsock/virtio_transport_common.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
> index 1e762a4..9dade6e 100644
> --- a/net/vmw_vsock/virtio_transport_common.c
> +++ b/net/vmw_vsock/virtio_transport_common.c
> @@ -1411,10 +1411,10 @@ static void virtio_transport_close_timeout(struct work_struct *work)
> (void)virtio_transport_reset(vsk, NULL);
>
> virtio_transport_do_close(vsk, false);
> + } else {
> + virtio_transport_cancel_close_work(vsk, false);
> }
>
> - vsk->close_work_scheduled = false;
> -
> release_sock(sk);
> sock_put(sk);
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 13:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 4:59 [PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close Hu Xinyao
2026-11-30 13:23 ` Michal Luczaj
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox