🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17046

Re: [PATCH net] vhost/vsock: Fix socket state constant

#17046
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 10:35
166 lines
13697 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] Writing TCP_CLOSE plus sk_err = ECONNRESET in
  vhost_vsock_reset_orphans() (drivers/vhost/vsock.c:792-793) brings…
- [Medium] vhost_vsock_reset_orphans() now moves every orphaned connected
  socket to TCP_CLOSE unconditionally, after setting SOCK_DONE, even…

--

vhost/vsock: Fix socket state constant

This patch replaces SS_UNCONNECTED with TCP_CLOSE in
vhost_vsock_reset_orphans(). SS_UNCONNECTED has the value 1, which is the
same as TCP_ESTABLISHED. So far, orphaned sockets have been left in the
established state after the vhost device was released.

> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> index 88a310390eb0a..fd224f7681d92 100644
> --- a/drivers/vhost/vsock.c
> +++ b/drivers/vhost/vsock.c
> @@ -789,7 +789,7 @@ static void vhost_vsock_reset_orphans(struct sock *sk)
>  
>  	sock_set_flag(sk, SOCK_DONE);
>  	vsk->peer_shutdown = SHUTDOWN_MASK;
> -	sk->sk_state = SS_UNCONNECTED;
> +	sk->sk_state = TCP_CLOSE;

[Severity: High]
Can this let connect() reset a socket that is still linked in
vsock_connected_table? Commit 4f6ac74fa594 ("vsock: treat TCP_CLOSING as
once-established") fixed that problem for the other close paths.

vhost_vsock_reset_orphans() runs without lock_sock(). Suppose it runs
after virtio_transport_recv_connecting() has handled a RESPONSE, but
before the waiter in vsock_connect() gets the socket lock back:

vhost TX worker
virtio_transport_recv_connecting()
    sk->sk_state = TCP_ESTABLISHED;
    sk->sk_socket->state = SS_CONNECTED;
    vsock_insert_connected(vsk);

vhost_vsock_dev_release()
  vhost_vsock_reset_orphans()
    sk->sk_state = TCP_CLOSE;
    sk->sk_err = ECONNRESET;

The waiter then fails the TCP_ESTABLISHED/TCP_CLOSING check and ends up
here:

net/vmw_vsock/af_vsock.c:vsock_connect() {
    ...
	err = sock_error(sk);
	if (err) {
		sk->sk_state = TCP_CLOSE;
		sock->state = SS_UNCONNECTED;
	}
    ...
}

connect() returns -ECONNRESET, but the socket is still in the connected
table. With the old value (1 == TCP_ESTABLISHED), connect() returned 0 and
the socket stayed SS_CONNECTED.

After that, ordinary API calls seem to be enough to insert the socket a
second time:

1. A second connect(): sock->state is SS_UNCONNECTED, so it does not get
   -EISCONN. vsock_assign_transport() returns early because the transport
   is the same. That skips both vsock_remove_sock() and
   sock_reset_flag(sk, SOCK_DONE).

2. shutdown() while the socket is SS_CONNECTING: vsock_shutdown() calls
   sock_reset_flag(sk, SOCK_DONE). Without that flag,
   virtio_transport_recv_pkt() no longer drops the incoming RESPONSE.

3. A RESPONSE from a guest with that CID reaches
   virtio_transport_recv_connecting() in TCP_SYN_SENT. It calls
   vsock_insert_connected() a second time.

__vsock_insert_connected() then does an unconditional sock_hold() and
list_add() on a node that is already linked, which corrupts the bucket.

Any later walk of that bucket under vsock_table_lock can then loop forever,
for example in vsock_find_connected_socket() or
vsock_for_each_connected_socket(). With CONFIG_DEBUG_LIST it hits the
list_add double add BUG instead. One socket reference is also leaked.

Only the first step depends on timing, a race with VM teardown. The rest
is normal use of the socket API.

> +	sk->sk_state = TCP_CLOSE;

[Severity: Medium]
Does this drop data that is still queued in the socket's rx_queue?

vhost_vsock_reset_orphans() now sets SOCK_DONE and then moves the socket
to TCP_CLOSE unconditionally. __vsock_connectible_recvmsg() then returns
early without dequeuing anything:

net/vmw_vsock/af_vsock.c:__vsock_connectible_recvmsg() {
    ...
	if (!transport || sk->sk_state != TCP_ESTABLISHED) {
		...
		if (sock_flag(sk, SOCK_DONE))
			err = 0;
		else
			err = -ENOTCONN;

		goto out;
	}
    ...
}

So recv() returns 0 (EOF), and sk_err is not reported there.

The other close paths only leave the readable state when no data is
pending:

net/vmw_vsock/virtio_transport_common.c:virtio_transport_do_close() {
    ...
	if (vsock_stream_has_data(vsk) <= 0)
		sk->sk_state = TCP_CLOSING;
    ...
}

hvs_do_close_lock_held() in hyperv_transport.c has the same check.
vmci_transport_handle_detach() skips the check only on the host side,
where queue-pair data can't be read once the VM detaches. With vhost, the
data is still in host-kernel skbs and can be read.

One way to hit this:

1. The guest writes data and sends SHUTDOWN.
   virtio_transport_recv_connected() keeps the socket TCP_ESTABLISHED
   because data is pending.

2. The VM exits, or the VMM closes the vhost fd.
   vhost_vsock_dev_release() calls vhost_vsock_reset_orphans().

3. The host application's next recv() returns 0, and the end of the
   stream is lost.

With the old value the socket stayed TCP_ESTABLISHED, so the application
could read the remaining data before seeing EOF.

On the guest side, virtio_vsock_reset_sock() also sets TCP_CLOSE
unconditionally on a transport reset, so this may be the intended reset
behaviour. It is still different from the RST path, which keeps queued
data readable.

Should vhost_vsock_reset_orphans() check vsock_stream_has_data() the way
the other transports do?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112-transport-reset-state-fix-v1-1-5698375f52a9%40rbox.co
Technical Details
Message-ID: <179482535544.3136.14958523425614003338@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364193-linux-kernel-netdev=dewy.ru
References: <20261112-transport-reset-state-fix-v1-1-5698375f52a9@rbox.co>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364193-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] vhost/vsock: Fix socket state constant
Date: Mon, 16 Nov 2026 10:35:55 +0000
Organization: Usenet Network
Message-ID: <179482535544.3136.14958523425614003338@kernel.org>
References: <20261112-transport-reset-state-fix-v1-1-5698375f52a9@rbox.co>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2035415"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Y9e8yDCivhEPxjA1PpHVUKAl8vA= sha256:71qYYNZcqaKjEQhZVAeyDxhjknJ2CHl3EwYD5JaUJTg=
	sha1:vaBiCp+OtmT6qDJqk7wIL9jIu5w= sha256:AVKAD8JizdNabhYVKCsDHdZRM1goVWtLndzaMvfFZZE=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 8507C114B9B; Mon, 16 Nov 2026 13:36:15 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.5
X-Spam-Status: No, score=-3.5 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id VPcK9zfNFkDE;
	Mon, 16 Nov 2026 13:36:11 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-364193-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 92F95114B98; Mon, 16 Nov 2026 13:36:03 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sto.lore.kernel.org (Postfix) with ESMTP id A380E6030EF; Mon, 16 Nov 2026 10:36:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794825357;
	b=LDOYd6NunmrckbEVyoaQDZYz5lmGIFRCyXsJjj8uPrf4v4+tv1KZ4RcIRTYLyILgAhKs
	 YFoVQmhuAcIqYylXnuIhZWZtdOMR7uKX5wKaUKqhHsLvPfHQ6ETUWkzPvTBZZ/u8BQU2f
	 jCh54PgO66w/Go6DXrbkjJswDjbuu/aAagXprEJPT5fZY2uHfJRkp7t1AliuuQtrOXQF7
	 FC7FhnTdfuol7d1y1XehLf2MTAtodU6fXcQJlRHoS2sDQ2idf6jqRYJMJsO2bJRvSVjJl
	 sALJxWl6Gr2FJtbzcsgZHrD3SRydhrlw+oEtBz6sqxIr60izYCHTydgk2FQpQWNBXIw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794825357;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=yJIFDAZTBBUc/zWvcjI+JoSUsDm2VmZ4BHMBL+zYoOg=;
	b=jT3WW1xSvsrrPCEufUnrYKU0grQ6tKnx1fTia96yxOGybnKPtEVfD+Z33H4FHSTTFwJE
	 lRW3Wdf0osRCLQddTRN/PU1qu+9I8ezTcYizRd3XWsskq5QHQyFNPNJT6Nq08AsWGNLYh
	 7RmpUmTkIRY4T/+a2QgoG6hZywCHv1M2LmIhe91jYil0JCawDBFo+k6GxROJ7V3MBdzLM
	 IQQ2k6EGXtPK3FqMyIoyKEKAgyzKJHCJIkd2rHAg0RHdO4qFouhq+gdyNvSrDFojD7hTR
	 FqfGZ5/9esuLSrrYK0r5rOwJkx8w+DaNUUCfkoc2lcLuRUIEMdWuq5gxvBluNhEgfVw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Zi9FfVIk;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id AEC7E606A893;
	Mon, 16 Nov 2026 10:35:57 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Zi9FfVIk
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794825356;
	b=5NKj+8kCT0vVfxxp+jXRnHYNtMrC/2XwvRuqeu+nccOjmGevAxSExuCbIfSuhKMTIr21
	 9fj7Jksfwuo2gApXjuwm4toa4apB0gokciHEWR0WWPaqVDgWS/evK/6qbg25IOK6hw4ai
	 E08mdew5nwNPsdRuLFJXJOV9Bf1tApzbxCih3jTp10GEzmFHaUjix5QA7ugCnzS7xWOu7
	 lwHuhOFv4DRCRYRlbglYXsNt0fltCwlfm/Scp9G9ZSfxcwfunOXgyeny/9OxSGXKOKLKQ
	 VPrQO9JfH6kUhXin26Am7N8KfxPQf8al4eu8qoNa+YplnjhF5Tfu01nMkiwt+Y1l2Pg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794825356;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=yJIFDAZTBBUc/zWvcjI+JoSUsDm2VmZ4BHMBL+zYoOg=;
	b=JlzsWN0aYZb+Uu/J4Bb3pkxxvS5/oE4kXRb6wGNZHi4ctl8sTAZOlbp6nCTxes5pKnll
	 523k8g4Upd3qWJBvvJhP2r9A8+sEJcdIkd2G8fda0NMXnh01M9wzv5GEQuiMd6TPvIg0T
	 xbFjGNqJyuIe40/eRSO0WAIB5tliwOPhHxFbyz0cs74/imrJlUu51PHaF800bLdYJqPF8
	 AOFA+8qpxycPuzd2eKTuDmQIzanfsY+ks/Ov8WD4NtRFtYHIydL4qs/xDfNcDKuNdMRcT
	 7G8vMD66m+5Vx2ucaHbU5z3yEUvpC3gLtgnm5FbPWh/aIG23uiKfCmLxvA4dmltdG1Q==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Zi9FfVIk;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD9E2606A330;
	Mon, 16 Nov 2026 10:35:56 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E732E1F000C4;
	Mon, 16 Nov 2026 10:35:55 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794825356;
	bh=yJIFDAZTBBUc/zWvcjI+JoSUsDm2VmZ4BHMBL+zYoOg=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=Zi9FfVIkSFfbDd7ubsUktRGMsIHDCNUtu3OnboGf8dkzTfs49fP0b0t5egcZr7qsl
	 FgA4oO2ko3m9qeqW79ZZQsdSpH+mKFLNJXxWXCgGvOFUVIRUN40XwJyyUW6zpoa7Fl
	 6S34lMcF5leGhdSQXICkEZ+lQOkiltt65hmsc5eRiBg/SlBDA0grcBIgrD7nl5JEfe
	 7J559ahYAea0l7MzcGcOVYrynXKwS3nFU08qGujnDW7or4fJpYwf9CgDdIHdGP8ljV
	 WJj6n/ndblsiL6B+v70t1tWG1KZsyump1VDDjlpWZCTrv6SGVrKYkhz91SmFLwfPB0
	 yENSLcOVbymag==
X-Cc: stefanha@redhat.com, sgarzare@redhat.com, bobbyeshleman@meta.com,
 mst@redhat.com, jasowangio@gmail.com, eperezma@redhat.com,
 davem@davemloft.net, kvm@vger.kernel.org, virtualization@lists.linux.dev,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kuba@kernel.org
X-In-Reply-To: <20261112-transport-reset-state-fix-v1-1-5698375f52a9@rbox.co>
X-sashiko-severity: High
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list