All of lore.kernel.org
 help / color / mirror / Atom feed
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 5/7] vsock/virtio: support guest device network namespace
Date: Wed, 02 Dec 2026 01:08:07 +0000	[thread overview]
Message-ID: <sashiko-outbox-244569@kernel.org> (raw)
In-Reply-To: <20261130-vsock-guest-ns-v8-5-5fff852d325b@meta.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] vsock: race between vsock_maybe_set_connected() and netns reset
  corrupts connect()
- [Medium] vsock/virtio: swept sockets can still send packets after
  device reassign
--

commit 8a88d97e551b287b3bd8b7283a009a1e7f59f9be
Author: Bobby Eshleman <bobbyeshleman@meta.com>

vsock/virtio: support guest device network namespace

This commit allows assigning the guest virtio-vsock device to a network
namespace, updating socket reachability checks and handshake insertion in
virtio_transport.

> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
> index 027fe41c676aa..c8049dd80cbcd 100644
> --- a/net/vmw_vsock/virtio_transport_common.c
> +++ b/net/vmw_vsock/virtio_transport_common.c
> @@ -295,6 +295,9 @@ static struct sk_buff *virtio_transport_alloc_skb(struct virtio_vsock_pkt_info *
>   * since a socket assigned to a transport is required.
>   *
>   * Do not use on listener sockets!
> + *
> + * This checks that the socket can reach the g2h device, so device-only replies
> + * such as virtio_transport_reset_no_sock() must keep not using this path.
>   */
>  static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
>  					  struct virtio_vsock_pkt_info *info)
> @@ -317,6 +320,9 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
>  	if (unlikely(!t_ops))
>  		return -EFAULT;
>  
> +	if (!vsock_g2h_reachable_sk(vsk))
> +		return -ENETUNREACH;

[Severity: Medium]
Can a socket that was swept by VSOCK_CMD_DEV_NETNS_SET still send packets
if the device is later reassigned back to a reachable namespace?

vsock_g2h_reset_unreachable_sk() resets unreachable sockets to TCP_CLOSE
while leaving sock->state as SS_CONNECTED.  vsock_g2h_reachable_sk() only
checks whether sock_net(sk) can currently reach vsock_g2h_net, not whether
the socket itself was already closed by an earlier sweep.  If the device
moves back to a reachable namespace (such as init_net) before the socket
fd is closed, paths that do not check sk->sk_state, such as
vsock_shutdown() or virtio_transport_notify_set_rcvlowat(), pass this
check and transmit VIRTIO_VSOCK_OP_SHUTDOWN or
VIRTIO_VSOCK_OP_CREDIT_UPDATE from a dead TCP_CLOSE socket.

> @@ -1468,8 +1474,8 @@ void virtio_transport_release(struct vsock_sock *vsk)
>  EXPORT_SYMBOL_GPL(virtio_transport_release);
>  
>  static int
> -virtio_transport_recv_connecting(struct sock *sk,
> -				 struct sk_buff *skb)
> +virtio_transport_recv_connecting(struct sock *sk, struct sk_buff *skb,
> +				 struct virtio_transport *t)
>  {
>  	struct virtio_vsock_hdr *hdr = virtio_vsock_hdr(skb);
>  	struct vsock_sock *vsk = vsock_sk(sk);
> @@ -1478,9 +1484,18 @@ virtio_transport_recv_connecting(struct sock *sk,
>  
>  	switch (le16_to_cpu(hdr->op)) {
>  	case VIRTIO_VSOCK_OP_RESPONSE:
> -		sk->sk_state = TCP_ESTABLISHED;
> +		if (!vsock_maybe_set_connected(vsk)) {
> +			/* The net arg is required but unused: only g2h can fail
> +			 * vsock_maybe_set_connected(), and g2h
> +			 * virtio_transport_reset_no_sock() ignores the net arg.
> +			 */
> +			virtio_transport_reset_no_sock(t, skb, sock_net(sk));
> +			skerr = ECONNRESET;
> +			err = -ENETUNREACH;
> +			goto close;
> +		}
> +
>  		sk->sk_socket->state = SS_CONNECTED;
> -		vsock_insert_connected(vsk);
>  		sk->sk_state_change(sk);
>  		break;

[Severity: High]
Can a namespace assign sweep right after vsock_maybe_set_connected() leave
vsk in vsock_connected_table while vsock_connect() resets sock->state to
SS_UNCONNECTED?

CPU0 (client connect)             CPU1 (rx_work / netns assign)
vsock_connect()
  sk->sk_state = TCP_SYN_SENT
  sock->state = SS_CONNECTING
  release_sock(sk)
  schedule_timeout()
                                  virtio_transport_recv_connecting()
                                    vsock_maybe_set_connected(vsk)
                                      sk->sk_state = TCP_ESTABLISHED
                                      __vsock_insert_connected(list, 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)
  if (sk->sk_state == TCP_ESTABLISHED ||
      sk->sk_state == TCP_CLOSING) // false
  ...
  err = sock_error(sk) // -ECONNRESET
  sock->state = SS_UNCONNECTED  <-- vsk still in vsock_connected_table

Because vsock_g2h_reset_unreachable_sk() runs under vsock_table_lock
without lock_sock(sk) and sets sk->sk_state to TCP_CLOSE rather than
TCP_CLOSING, vsock_connect() does not recognize that the socket was
already established and inserted into vsock_connected_table.  Resetting
sock->state to SS_UNCONNECTED allows a second connect() on the same fd to
call __vsock_insert_connected() again on the already-linked
vsk->connected_table node, corrupting vsock_connected_table and leaking a
socket reference.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261130-vsock-guest-ns-v8-0-5fff852d325b@meta.com?part=5

  reply	other threads:[~2026-12-02  1:08 UTC|newest]

Thread overview: 13+ 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
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 [this message]
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
2026-12-02  1:08 ` [PATCH net-next v8 0/7] vsock: assign the guest vsock device to a network namespace sashiko-bot

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-244569@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.