From: netdev-bot+sashiko@kernel.org
To: bobbyeshleman@meta.com
Cc: sgarzare@redhat.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, corbet@lwn.net,
skhan@linuxfoundation.org, stefanha@redhat.com, mst@redhat.com,
jasowangio@gmail.com, xuanzhuo@linux.alibaba.com,
eperezma@redhat.com, shuah@kernel.org, rdunlap@infradead.org,
donald.hunter@gmail.com, edumazet@kernel.org,
georgezhang@vmware.com, acking@vmware.com, dtor@vmware.com,
willemb@google.com, virtualization@lists.linux.dev,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org, sargun@sargun.me,
jlinbox@meta.com, bobbyeshleman@gmail.com
Subject: Re: [PATCH net-next v8 5/7] vsock/virtio: support guest device network namespace
Date: Wed, 02 Dec 2026 19:07:15 +0000 [thread overview]
Message-ID: <179623843543.3146.15809986398511576502@kernel.org> (raw)
In-Reply-To: <20261130-vsock-guest-ns-v8-5-5fff852d325b@meta.com>
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 3 · Low: 2
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] vsock: race between vsock_maybe_set_connected() and netns reset
corrupts connect()
- [Medium] Documentation/admin-guide/sysctl/net.rst says: "A connection
still being set up when the device moves is refused with a reset once…
- [Medium] Packets that a socket put on vsock->send_pkt_queue before a
VSOCK_CMD_DEV_NETNS_SET are still sent to the host after the device…
- [Medium] With .netns_assign_allow = true, VSOCK_CMD_DEV_NETNS_SET can
move a live virtio-vsock device.
- [Low] The patch changes which namespaces' vsockmon taps see virtio-
vsock traffic, and the commit message does not say so.
- [Low] The reachability check added to virtio_transport_send_pkt_info()
runs once, before the skb allocation/transmit loop, and nothing…
--
vsock/virtio: support guest device network namespace
This patch makes the virtio-vsock device assignable to a network namespace
by setting .netns_assign_allow. Stream and seqpacket sockets from any netns
that can reach the device are now allowed to use it. The rx worker re-reads
the assigned namespace per packet, the listen and connecting receive paths
go through vsock_maybe_set_connected(), and
virtio_transport_send_pkt_info() refuses to send when the socket's netns
cannot reach the device.
> diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c
> index 1ddb6839a8fbe..ba90815362120 100644
> --- a/net/vmw_vsock/virtio_transport.c
> +++ b/net/vmw_vsock/virtio_transport.c
> @@ -150,7 +150,9 @@ static int virtio_transport_send_skb(struct sk_buff *skb, struct virtqueue *vq,
> if (ret < 0)
> return ret;
>
> - virtio_transport_deliver_tap_pkt(skb, NULL);
> + rcu_read_lock();
> + virtio_transport_deliver_tap_pkt(skb, vsock_g2h_net_rcu());
> + rcu_read_unlock();
> return 0;
> }
[Severity: Low]
This changes which vsockmon devices see virtio-vsock traffic. Before this
patch, both this TX tap and the RX tap in virtio_transport_rx_work() passed
net == NULL. vsock_net_mode() treats NULL as global, so every global-mode
vsockmon device, including the one in init_net, saw all guest vsock
traffic.
Now the assigned netns is passed, and __vsock_deliver_tap() filters on it:
net/vmw_vsock/af_vsock_tap.c:__vsock_deliver_tap() {
...
list_for_each_entry_rcu(tmp, &vsock_tap_all, list) {
if (!vsock_net_check_mode(dev_net(tmp->dev), net))
continue;
...
}
Once the device is assigned to a local namespace, taps in init_net and in
other global namespaces stop seeing guest vsock traffic. Only taps in the
assigned namespace see it.
This looks intentional, given the v7 review feedback. However, the only
mention of it is the changelog line "Tap with the assigned netns", and that
line is dropped when the patch is applied.
Could the commit message describe the new tap behaviour?
[Severity: Medium]
Can this tap packets into a namespace other than the one whose socket
produced them?
virtio_transport_send_pkt_info() checks reachability only when it builds
the skb. If the skb can't go out straight away, it waits on
vsock->send_pkt_queue. It is sent later through
virtio_transport_send_pkt_work()->virtio_transport_send_skb(), which reads
the device's netns at that point.
The sweep run by vsock_g2h_net_assign() only changes socket state. It
doesn't purge skbs that are already queued:
net/vmw_vsock/af_vsock.c:vsock_g2h_reset_unreachable_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);
}
Suppose a socket in global namespace A has payload queued, and the device
is then assigned to local namespace L. send_pkt_work still sends A's skbs
to the host after the move, and taps them with net == L, so only L's
vsockmon devices see A's payload. The reverse happens when the device moves
back from L to a global namespace.
The host controls how fast the TX virtqueue drains, so this window can be
long.
Socket-originated skbs already carry their owner in skb->sk, because
virtio_transport_alloc_skb() calls skb_set_owner_w(). Would tapping with
sock_net(skb->sk) avoid this? Purging the queued skbs of the sockets the
sweep resets would be another option.
[ ... ]
> @@ -587,6 +589,7 @@ static struct virtio_transport virtio_transport = {
> .seqpacket_has_data = virtio_transport_seqpacket_has_data,
>
> .msgzerocopy_allow = virtio_transport_msgzerocopy_allow,
> + .netns_assign_allow = true,
>
> .notify_poll_in = virtio_transport_notify_poll_in,
> .notify_poll_out = virtio_transport_notify_poll_out,
[Severity: Medium]
With this set, VSOCK_CMD_DEV_NETNS_SET can move a live device.
vsock_g2h_reset_unreachable_sk() then marks connected guest sockets
TCP_CLOSE with ECONNRESET. Is the host ever told that those connections
are gone?
The sweep queues nothing to the device. After the sweep, the new check in
virtio_transport_send_pkt_info() returns -ENETUNREACH for OP_SHUTDOWN from
shutdown(), for credit updates, and for virtio_transport_reset(vsk, ...).
virtio_transport_close() also returns early, because sk_state is already
TCP_CLOSE:
if (!(sk->sk_state == TCP_ESTABLISHED ||
sk->sk_state == TCP_CLOSING))
return true;
The comments and the admin guide compare this to removing the device
("Nothing is sent to the peer"). On a real removal or a
VIRTIO_VSOCK_EVENT_TRANSPORT_RESET, the host side is torn down as well.
Here the device stays live.
A host peer only learns of the reset if it sends something. That reaches
virtio_transport_reset_no_sock() after the lookup fails in the new
namespace. An idle host peer, or one waiting on the guest, stays
established indefinitely.
There is also a 4-tuple problem. The bound table lookup is namespace
filtered, so a socket in the new namespace can bind the same local port and
connect to the same host (cid, port). Its OP_REQUEST then reaches a host
that still holds an established connection for that 4-tuple, and the
host's recv_connected() drops it in its default case.
Should the sweep send an OP_RST to the device for each socket it resets?
[ ... ]
> @@ -680,12 +688,16 @@ static void virtio_transport_rx_work(struct work_struct *work)
> if (payload_len)
> virtio_vsock_skb_put(skb, payload_len);
>
> - virtio_transport_deliver_tap_pkt(skb, NULL);
> -
> - /* Force virtio-transport into global mode since it
> - * does not yet support local-mode namespacing.
> + /* Only grab a reference if the net changes underneath
> + * us.
> */
> - virtio_transport_recv_pkt(&virtio_transport, skb, NULL);
> + if (unlikely(!vsock_g2h_net_eq(net))) {
> + put_net_track(net, &ns_tracker);
> + net = vsock_g2h_net_get(&ns_tracker);
> + }
> +
> + virtio_transport_deliver_tap_pkt(skb, net);
> + virtio_transport_recv_pkt(t, skb, net);
> }
> } while (!virtqueue_enable_cb(vq));
[Severity: Medium]
Documentation/admin-guide/sysctl/net.rst says:
"A connection still being set up when the device moves is refused with
a reset once the peer answers it."
Does that hold in the common case?
A virtio socket in TCP_SYN_SENT is only in the bound table. The
vsock_g2h_net_assign() sweep walks only the connected table, so it never
touches that socket.
After the swap, this per-packet re-read means the host's OP_RESPONSE is
looked up with the new namespace B. vsock_find_connected_socket_net() and
__vsock_find_bound_socket_net() both filter with
vsock_net_check_mode(sock_net(sk), net). If old namespace A cannot reach B,
the socket in A is not found:
virtio_transport_rx_work()
virtio_transport_recv_pkt(t, skb, B)
vsock_find_connected_socket_net() -> NULL
vsock_find_bound_socket_net() -> NULL
virtio_transport_reset_no_sock()
virtio_transport_recv_connecting() never runs. The local socket stays in
TCP_SYN_SENT with sk_err == 0 until connect_timeout expires, and then
connect() fails with ETIMEDOUT. connect_timeout is user settable and can be
very large.
The new abort path in virtio_transport_recv_connecting() only gives
ECONNRESET when the swap lands between this net check and
vsock_maybe_set_connected(). The same event can therefore return two
different errnos.
Should the sweep also reset SYN_SENT sockets in unreachable namespaces?
Otherwise, should the documentation describe the timeout behaviour?
[ ... ]
> 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
[ ... ]
> @@ -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;
> +
> src_cid = t_ops->transport.get_local_cid();
> src_port = vsk->local_addr.svm_port;
> if (!info->remote_cid) {
[Severity: Low]
Is this check enough to stop a socket that an assign has reset from
sending?
It runs once, before the allocation and transmit loop, and nothing
serializes it against vsock_g2h_net_assign(). The swap runs under
vsock_register_mutex and the sweep under vsock_table_lock. Neither waits
for a sender that holds lock_sock().
A sendmsg that passed this check just before the swap keeps calling
t_ops->send_pkt() for every skb in the do/while loop, up to the peer
credit. This continues after the sweep has set TCP_CLOSE and ECONNRESET on
the socket, and after the netlink assign has returned success to
userspace.
That narrows, but doesn't fully deliver, what the commit message promises:
"A socket reset by an assign can still try to send, e.g. a credit
update from setsockopt(SO_RCVLOWAT) or a shutdown. To stop that,
virtio_transport_send_pkt_info() now returns -ENETUNREACH ..."
These packets are also tapped into the new namespace by
virtio_transport_send_skb(), as noted above.
[ ... ]
> @@ -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;
> case VIRTIO_VSOCK_OP_INVALID:
[Severity: High]
Can the assign sweep land after this insert but before the thread in
vsock_connect() wakes up?
vsock_maybe_set_connected() sets TCP_ESTABLISHED and links vsk into
vsock_connected_table under vsock_table_lock, then drops the lock. At
that point the connecting thread is still asleep in schedule_timeout()
and has not retaken lock_sock(sk).
If vsock_g2h_net_assign() runs in that window, its sweep finds vsk in
the connected table. vsock_g2h_reset_unreachable_sk() sets TCP_CLOSE
and ECONNRESET without lock_sock(), and leaves vsk linked:
virtio_transport_recv_connecting()
vsock_maybe_set_connected()
sk_state = TCP_ESTABLISHED, vsk linked in vsock_connected_table
vsock_g2h_net_assign()
vsock_g2h_reset_unreachable_sk()
sk_state = TCP_CLOSE, sk_err = ECONNRESET, vsk still linked
vsock_connect() retakes lock_sock(sk)
sk_state is neither TCP_ESTABLISHED nor TCP_CLOSING
sock_error() -> ECONNRESET
sock->state = SS_UNCONNECTED
The wait loop in vsock_connect() only treats TCP_ESTABLISHED and
TCP_CLOSING as a finished handshake. A peer RST on an established
socket goes through virtio_transport_do_close(), which leaves it in
TCP_ESTABLISHED or TCP_CLOSING, so that case is handled. The sweep
writes TCP_CLOSE instead.
After this, the fd looks unconnected to userspace, but vsk is still in
vsock_connected_table and still holds the reference taken by
__vsock_insert_connected(). A second connect() on the same fd is
accepted. It overwrites vsk->remote_addr in place without
vsock_table_lock, which leaves vsk in the bucket for the old 4-tuple.
vsock_assign_transport() can also swap vsk->transport while vsk is
still linked.
If that second connect() succeeds, __vsock_insert_connected() links
vsk->connected_table a second time. That corrupts the connected table
(or trips CONFIG_DEBUG_LIST) and leaks a socket reference.
virtio_vsock_reset_sock() already writes TCP_CLOSE the same way, but
only when the device itself resets. Here a netlink command on a live
device can hit exactly the handshake window that
vsock_maybe_set_connected() was added to close.
Should the sweep unlink the sockets it resets from the connected
table? Alternatively, could it leave them in TCP_CLOSING, so that
vsock_connect() takes its existing established path?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130-vsock-guest-ns-v8-0-5fff852d325b%40meta.com
next prev parent reply other threads:[~2026-12-02 19:07 UTC|newest]
Thread overview: 16+ 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 19:26 ` Michal Luczaj
2026-12-02 19:07 ` netdev-bot+sashiko
2026-12-01 1:06 ` [PATCH net-next v8 5/7] vsock/virtio: support guest device network namespace Bobby Eshleman
2026-12-02 19:07 ` netdev-bot+sashiko [this message]
2026-12-01 1:06 ` [PATCH net-next v8 6/7] selftests/vsock: test the guest vsock " Bobby Eshleman
2026-12-02 19:07 ` netdev-bot+sashiko
2026-12-01 1:06 ` [PATCH net-next v8 7/7] selftests/vsock: test the netns assign privilege checks Bobby Eshleman
2026-12-02 19:07 ` netdev-bot+sashiko
2026-12-02 18:15 ` [PATCH net-next v8 0/7] vsock: assign the guest vsock device to a network namespace Stefano Garzarella
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=179623843543.3146.15809986398511576502@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=acking@vmware.com \
--cc=bobbyeshleman@gmail.com \
--cc=bobbyeshleman@meta.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dtor@vmware.com \
--cc=edumazet@kernel.org \
--cc=eperezma@redhat.com \
--cc=georgezhang@vmware.com \
--cc=horms@kernel.org \
--cc=jasowangio@gmail.com \
--cc=jlinbox@meta.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=sargun@sargun.me \
--cc=sgarzare@redhat.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=willemb@google.com \
--cc=xuanzhuo@linux.alibaba.com \
/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