From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796238437; b=aG0Xz+ppLNSeUVOdaVs+40/lTQnR1qGcVSFSmbA59eHIDBWSZ3NgskzlTBxtBpKYtAlf PSC+daFNNiTDuwTHdb/DG8O+ed/ZCj060+cbGqTxUEr3DQ46aWvA5O4WmZ7rKyj22bjdk ioTHU0LGULXMcWqlb+UT6YL5fIEXWZ2gQM0IDbl03ZXJwdeL5nrb5aVb7gGsCPgL/jiiX g5rK7J0i1jLXXUd09qLtaCaDjaXvQSORuhao455M0zG09IbNg+HBFurv/NFH2JlFyvpqG e8QYqSEmmebqB3lxmYOgIACx+2ia86pyDMAUEFDJL+I/OZSOAIRk7m0N6JbRAYNG9BA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796238437; 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=4+aA/5A0xYUP96IAIV0TSPAGNOhoL99ItS9jBTMOOh0=; b=0s8U46KerKvVO8NAEvzGfTNH2NDkmi5CihQ3gSPNuTJkffVkCee7zh/ZnWfScqZuPSlw WuF9eOg2fvjlvLVm5omWyT73ixIOs8upSGEXxmR9N/1qZMBdaopZi49sM2FjIA3P86hyb nweG//aflffJAm1D9rkna6AT4ilvdLthRJneY7vojyUH3cXHUp/TK9Ba1oJen1LmB9OZk EARgNquTJehSviu9QsloaMkDxvyONZp3waUeGhgiqhs19w3K3KxXWq5a/cGaSaIbXD85T UV9igvbPdPcFRpj525uaLn/vrnEdCNB9vNWwANcjk+MqYtdX663WR1WcVbpxkUtMUBQ== 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="PFh1n2C/"; arc=none smtp.remote-ip=100.103.45.18 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 B56B0606A32D; Wed, 2 Dec 2026 19:07:17 +0000 (UTC) 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=PFh1n2C/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFAFC1F000C1; Wed, 2 Dec 2026 19:07:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796238437; bh=4+aA/5A0xYUP96IAIV0TSPAGNOhoL99ItS9jBTMOOh0=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=PFh1n2C/+91IqO1pPRfwKZLKXlKWMTehGzY1qaj6M4cEwrdZNvKJisfeUeMN0MgOb /KFj2T9hiTwIO1vxqKIkXp1CB5KWXFrTJHhcuvK5dOgg3Tsm5P6qcbKw/CBXlejhhQ /irmw+s6IzEfZmByN+wK84WDAdFNTVVqPOzGk5gokK8KGdaEMFKii3OhnrqQZ/MHJv CFxWnshkgiQCRU2ytJPpIfoPYspUEyQu3YKb9R9GOvih+yRaIjCURr33qiwaTRG7Vz s7us7Dwh/Ezxe7+QM0TMW5llZfWvsBGzepZ2UA0FlBUD30LTo/X9Si6ki0KuoKvmL2 WLvNn/m8ZxJEA== Subject: Re: [PATCH net-next v8 5/7] vsock/virtio: support guest device network namespace 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 Date: Wed, 02 Dec 2026 19:07:15 +0000 Message-ID: <179623843543.3146.15809986398511576502@kernel.org> In-Reply-To: <20261130-vsock-guest-ns-v8-5-5fff852d325b@meta.com> References: <20261130-vsock-guest-ns-v8-5-5fff852d325b@meta.com> X-sashiko-severity: High Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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