From: sashiko-bot@kernel.org
To: "Bobby Eshleman" <bobbyeshleman@meta.com>
Cc: virtualization@lists.linux.dev, kvm@vger.kernel.org,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH net-next v8 4/7] vsock: add a netlink command to assign the g2h device to a netns
Date: Wed, 02 Dec 2026 01:08:06 +0000 [thread overview]
Message-ID: <sashiko-outbox-244568@kernel.org> (raw)
In-Reply-To: <20261130-vsock-guest-ns-v8-4-5fff852d325b@meta.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] vsock: vsock_g2h_reset_unreachable_sk() TCP_CLOSE races with
vsock_connect()
- [Medium] vsock: unsafe lockless TCP_CLOSE reset in
vsock_g2h_reset_unreachable_sk()
--
commit 55c9fdf72367a24599ee9923aeab58ae5022b47c
Author: Bobby Eshleman <bobbyeshleman@meta.com>
vsock: add a netlink command to assign the g2h device to a netns
This commit adds a vsock generic netlink family with
VSOCK_CMD_DEV_NETNS_SET and VSOCK_CMD_DEV_NETNS_GET to assign the
guest-to-host vsock device to a network namespace and reset connected
sockets that can no longer reach it.
Link: https://lore.kernel.org/all/20200427142518.uwssa6dtasrp3bfc@steredhat/
> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
> index 649bdf48d03bd..a20446f2c6fbb 100644
> --- a/net/vmw_vsock/af_vsock.c
> +++ b/net/vmw_vsock/af_vsock.c
[ ... ]
> @@ -742,8 +837,236 @@ bool vsock_find_cid(unsigned int cid)
[ ... ]
> +/* Reset @sk if it can no longer reach the g2h device, as an unplug of the
> + * device does (see virtio_vsock_reset_sock()).
> + */
> +static void vsock_g2h_reset_unreachable_sk(struct sock *sk)
> +{
> + if (sk->sk_state == TCP_CLOSE || vsock_g2h_reachable_sk(vsock_sk(sk)))
> + return;
> +
> + sk->sk_state = TCP_CLOSE;
> + sk->sk_err = ECONNRESET;
> + sk_error_report(sk);
> +}
[Severity: Medium]
As reported by Michal Luczaj on v4 [1], can setting sk->sk_state to
TCP_CLOSE here cause a waking vsock_connect() to reset an already
connected socket back to SS_UNCONNECTED while vsk remains in
vsock_connected_table?
CPU0 CPU1
vsock_connect()
release_sock(sk)
schedule_timeout(timeout)
virtio_transport_recv_connecting()
sk->sk_state = TCP_ESTABLISHED
__vsock_insert_connected(..., vsk)
sock->state = SS_CONNECTED
vsock_g2h_net_assign()
vsock_g2h_reset_unreachable_sk(sk)
sk->sk_state = TCP_CLOSE
sk->sk_err = ECONNRESET
lock_sock(sk)
/* sk_state is TCP_CLOSE, misses
* TCP_ESTABLISHED / TCP_CLOSING
*/
err = sock_error(sk)
sock->state = SS_UNCONNECTED
net/vmw_vsock/af_vsock.c:vsock_connect() {
...
if (sk->sk_state == TCP_ESTABLISHED ||
sk->sk_state == TCP_CLOSING) {
err = 0;
goto out_wait;
}
...
err = sock_error(sk);
if (err) {
sk->sk_state = TCP_CLOSE;
sock->state = SS_UNCONNECTED;
}
...
}
Because sock->state is reset to SS_UNCONNECTED while vsk->connected_table
is still linked in vsock_connected_table, a subsequent connect() on the
same socket either calls __vsock_insert_connected() a second time on the
same list_head (corrupting vsock_connected_table and leaking a sock_hold()
reference) or switches transports in vsock_assign_transport() and frees
vsk->trans via virtio_transport_destruct() while TX skbs queued before the
sweep are still in flight for virtio_transport_consume_skb_sent().
[ ... ]
> +static int vsock_g2h_net_assign(struct net *net, struct sk_buff *msg,
> + struct genl_info *info)
> +{
[ ... ]
> + old = vsock_g2h_net_swap(net, &old_tracker);
> +
> + /* See vsock_maybe_set_connected() comment about synchronizing with
> + * connecting sockets.
> + */
> + vsock_for_each_connected_socket(transport_g2h,
> + vsock_g2h_reset_unreachable_sk);
[Severity: Medium]
As reported by Michal Luczaj on v4 [2], is it safe for
vsock_g2h_reset_unreachable_sk() to mutate sk->sk_state to TCP_CLOSE and
sk->sk_err without lock_sock(sk) while leaving vsk->peer_shutdown at 0?
In vsock_connectible_wait_data(), the recvmsg() wait loop only checks
sk->sk_err != 0, RCV_SHUTDOWN, and vsk->peer_shutdown & SEND_SHUTDOWN
without checking sk->sk_state != TCP_ESTABLISHED:
net/vmw_vsock/af_vsock.c:vsock_connectible_wait_data() {
...
if (sk->sk_err != 0 ||
(sk->sk_shutdown & RCV_SHUTDOWN) ||
(vsk->peer_shutdown & SEND_SHUTDOWN)) {
break;
}
...
}
If another thread consumes sk->sk_err via sock_error(sk) (for example via
getsockopt(SO_ERROR) or a waking vsock_connect()) before the sleeping
recvmsg() thread reacquires lock_sock(sk), vsock_connectible_wait_data()
sees sk->sk_err == 0 and vsk->peer_shutdown == 0 and goes back to sleep on
the TCP_CLOSE socket. In addition, unlike device removal, the g2h device
stays running across vsock_g2h_net_assign(), so an in-flight
virtio_transport_recv_pkt() holding lock_sock(sk) can concurrently run
virtio_transport_do_close() and overwrite sk->sk_state to TCP_CLOSING
after vsock_g2h_reset_unreachable_sk() sets it to TCP_CLOSE.
[1] https://lore.kernel.org/r/d946003a-8bec-4e8b-89a3-05eeb96780cc@rbox.co
[2] https://lore.kernel.org/r/d946003a-8bec-4e8b-89a3-05eeb96780cc@rbox.co
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-vsock-guest-ns-v8-0-5fff852d325b@meta.com?part=4
next prev parent reply other threads:[~2026-12-02 1:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 1:06 [PATCH net-next v8 0/7] vsock: assign the guest vsock device to a network namespace Bobby Eshleman
2026-12-01 1:06 ` [PATCH net-next v8 1/7] vsock: constify the transport in vsock_for_each_connected_socket() Bobby Eshleman
2026-12-01 1:06 ` [PATCH net-next v8 2/7] vsock: rename the vsock pernet operations Bobby Eshleman
2026-12-01 1:06 ` [PATCH net-next v8 3/7] vsock: pass the netns to ->has_remote_cid() Bobby Eshleman
2026-12-01 1:06 ` [PATCH net-next v8 4/7] vsock: add a netlink command to assign the g2h device to a netns Bobby Eshleman
2026-12-01 16:19 ` Michal Luczaj
2026-12-01 21:05 ` Bobby Eshleman
2026-12-02 1:08 ` sashiko-bot [this message]
2026-12-01 1:06 ` [PATCH net-next v8 5/7] vsock/virtio: support guest device network namespace Bobby Eshleman
2026-12-02 1:08 ` sashiko-bot
2026-12-01 1:06 ` [PATCH net-next v8 6/7] selftests/vsock: test the guest vsock " Bobby Eshleman
2026-12-01 1:06 ` [PATCH net-next v8 7/7] selftests/vsock: test the netns assign privilege checks Bobby Eshleman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-244568@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bobbyeshleman@meta.com \
--cc=eperezma@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=virtualization@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox