🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
4 messages
4 total messages Started by Hu Xinyao Mon, 30 Nov 2026 04:59
[PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close
#24404
Author: Hu Xinyao
Date: Mon, 30 Nov 2026 04:59
49 lines
10761 bytes
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
Re: [PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close
#24628
Author: Michal Luczaj
Date: Mon, 30 Nov 2026 13:23
60 lines
11579 bytes
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);
>  }
Re: [PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close
#25110
Author: Hu Xinyao
Date: Tue, 01 Dec 2026 09:10
35 lines
10688 bytes
On Mon, Nov 30, 2026 at 02:23:11PM +0100, Michal Luczaj wrote:
> 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/
>
> > 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?

Hi Michal,

Thanks for checking this and for the pointer to [1]!

To answer your question honestly: we didn't try triggering it at runtime
before sending v1 -- GLM-5.4 flagged the window between work dequeue
(clearing WORK_STRUCT_PENDING_BIT) and lock_sock(sk) during a static
audit pass, and we manually traced virtio_transport_close_timeout() vs
virtio_transport_do_close(vsk, true) against mainline and compile-tested
the patch.

Looking at current net / net-next, virtio_transport_common.c still skips
cleanup in virtio_transport_close_timeout() when SOCK_DONE is already
set, so virtio / vsock_loopback / vhost-vsock remain affected. We also
booted a QEMU kernel with CONFIG_VSOCKETS_LOOPBACK=y, CONFIG_KASAN=y,
and CONFIG_PROVE_LOCKING=y to verify the close paths with the fix
applied. Happy to follow up with a regression test under
tools/testing/vsock/ if that would be useful.

Best regards,
Hu Xinyao
Re: [PATCH net] vsock/virtio: Fix sock leak on close_timeout race with peer close
#25593
Author: Hu Xinyao
Date: Wed, 02 Dec 2026 03:29
44 lines
10965 bytes
On Tue, Dec 01, 2026 at 06:05:30PM +0100, Stefano Garzarella wrote:
> >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;
>
> Why we are removing this?

Hi Stefano,

With the else branch added, both branches now call
virtio_transport_cancel_close_work(vsk, false) (the !SOCK_DONE branch
via virtio_transport_do_close(vsk, false), and the SOCK_DONE branch
directly).

In virtio_transport_cancel_close_work(vsk, false), !cancel_timeout is
unconditionally true, so whenever vsk->close_work_scheduled is set it
already clears vsk->close_work_scheduled = false (along with calling
virtio_transport_remove_sock(vsk) and sock_put(sk)), and if it was
already false it remains false. Previously, the trailing assignment only
had an effect when SOCK_DONE was already set and do_close() was skipped,
clearing the flag without releasing the socket reference or removing the
socket.

Sorry for not spelling that out in the commit message (since
virtio_transport_cancel_close_work() is outside the diff context).
Alternatively, we could avoid the else branch and just replace
"vsk->close_work_scheduled = false;" with an unconditional
"virtio_transport_cancel_close_work(vsk, false);" after the if
(!sock_flag(sk, SOCK_DONE)) block, which is a no-op if do_close()
already ran. Happy to send a v2 whichever way you prefer.

Thanks,
Hu Xinyao
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads