Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] vsock/virtio: swept sockets can still send and receive after device reassign - [Medium] vsock/virtio: bytes_unsent not decremented in virtio_transport_purge_skbs() --
commit 9aa3064a70d9c211d00810f1b687d67543df5469 Author: Bobby Eshleman <[email protected]> vsock/virtio: support guest device network namespace This commit allows assigning the virtio-vsock guest device to a network namespace and updates connection setup, packet reception, and packet transmission to check whether sockets can reach the assigned namespace. > 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 [ ... ] > @@ -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] Does purging queued packets on an established socket leave vvs->bytes_unsent elevated? Previously, virtio_transport_cancel_pkt() was only called on TCP_SYN_SENT sockets, whose queued packets have zero payload length. With .netns_assign_allow enabled, vsock_g2h_reset_unreachable() now calls t->cancel_pkt(vsk) -> virtio_transport_cancel_pkt() -> virtio_transport_purge_skbs() on TCP_ESTABLISHED sockets that may have data SKBs queued in vsock->send_pkt_queue. virtio_transport_get_credit() already added those payload bytes to vvs->bytes_unsent, and normally virtio_transport_consume_skb_sent() subtracts skb->len on TX completion, but virtio_transport_purge_skbs() frees matching SKBs with __skb_queue_purge(&freeme) without decrementing vvs->bytes_unsent. As a result, SIOCOUTQ reports stale unsent bytes on the reset socket, and a concurrent close() sleeping in vsock_linger() stalls until sk_lingertime expires because virtio_transport_unsent_bytes() never reaches zero. > 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; > + > src_cid = t_ops->transport.get_local_cid(); > src_port = vsk->local_addr.svm_port; > if (!info->remote_cid) { [Severity: Medium] Can a socket swept by vsock_g2h_reset_unreachable() still send packets to the host if the device is reassigned back to a reachable namespace before the file descriptor is closed? vsock_g2h_reachable_sk(vsk) only checks whether sock_net(sk_vsock(vsk)) can currently reach vsock_g2h_net, not whether vsk was already terminated by an earlier namespace assignment. When vsock_g2h_reset_unreachable() sweeps a connected socket, it sets SOCK_DONE and vsk->peer_shutdown = SHUTDOWN_MASK, leaves the socket in vsock_connected_table, and keeps sk->sk_state as TCP_CLOSING (or TCP_ESTABLISHED if unread RX data remains). If the device is later moved back to a reachable namespace such as init_net, vsock_g2h_reachable_sk() returns true again: - close() -> virtio_transport_close() checks (vsk->peer_shutdown & SHUTDOWN_MASK) == SHUTDOWN_MASK before SOCK_DONE and sends VIRTIO_VSOCK_OP_RST to the host. - recvmsg() or setsockopt(SO_RCVLOWAT) sends VIRTIO_VSOCK_OP_CREDIT_UPDATE. - shutdown() -> vsock_shutdown() sends VIRTIO_VSOCK_OP_SHUTDOWN and clears SOCK_DONE via sock_reset_flag(sk, SOCK_DONE), which also allows the socket in vsock_connected_table to pass the SOCK_DONE check in virtio_transport_recv_pkt() again. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=5
