From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=67.231.153.30 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796399680; b=KKwAmeqOza0v+HTgZ3gGef+wh25yjvf7Rsstjeik5xBtfQfQ+5xYuCXQdZOzGfGrE9u4 Yec9fyNWXtb/qYQTrfBhpFUDaRvwL+PD2GpIl5KS7oGExKd8NMZAQSc58BSsWF7cFl3dz DS5lHrlfWG9yBJiEE+lvJ2x2w+QRXYGgxqseRBh4SSVHi0PbrHakHOq2w0CJThryepLpB kSytqcg9SviQU/9IERie9F7L/yF88PO5ZYxLjN4n/h/BzyGlCOB//t7M2VTnjqfNMJ35I n+ER0NJo8EV20bpEPuc677yOpLTjxPEBG2g40aI03hIAtleU3IyRp+kjK3Mwx4xjgkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796399680; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Date:From:To: CC:Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To: X-Originating-IP:X-Proofpoint-Spam-Info:X-Proofpoint-ORIG-GUID: X-Authority-Analysis:X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-Virus-Version; bh=F4nTXx3mRaX4xMVQ9q84LUiiPQRiW+zf0IUxFwFnjDM=; b=befRvmlK0H3FtIp9yO9oYRABN0+In2AztsRe+wi9LiwYktBCo3rTEa8GeOm/JGf/VA6b G2ezE9giLNVf1q5mocWC0szi/brLKPp8jQwBj3V5X5cyzNuekcqoGcr9b8/xKrklvUuSe ETkoKgbN65tSvuFyLvB12hNExgAnUmsKiw7CiNbXwwMrhbTUeuwZk6dZuhNgAmbTs0EGy Myk1W0+sOR0J6Q43Emszn7mwQogmMv74gmIdS5iICrQ0x4fh64qM9WdpUxg4FtrRqrskg WRDmaVTGA519ZhttthFH/zTSjSZ6PFKLtmy9B5Lqg+Ni99NJyQXbkvz7S+2YmXgS48Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass header.d=meta.com header.i=@meta.com header.a=rsa-sha256 header.s=pps82601-s2048-2026-q3 header.b="PzbwDPd/"; arc=none smtp.remote-ip=67.231.153.30 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E170606A338; Fri, 4 Dec 2026 15:54:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5E170606A338 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.a=rsa-sha256 header.s=pps82601-s2048-2026-q3 header.b=PzbwDPd/ Received: from pps.filterd (m0528004.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B4FX8cP222891; Fri, 4 Dec 2026 07:53:54 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= pps82601-s2048-2026-q3; bh=F4nTXx3mRaX4xMVQ9q84LUiiPQRiW+zf0IUxF wFnjDM=; b=PzbwDPd//Yn++1zDlxAZVP7Ibfgk+3fsvXWNDdXORyLGy+VGswwU9 ZwranG1bHaRxaA/1iHJ28humzecSxqaussf9ldBch1FLEsvQv2N3fr1/HUtElLQb 0a59DeLGsvzQJAOydyNoQe1uufKfeSprUGIAM5WchAcoIEbykokux7yEiPNaYqV2 yo0yep/VLUoWWQWRZVDyk46eb45a57e8tJoOYpf02pCW+Q0bZ6l0g7ka27ZCERtS Ql7msJyIGVlV1Nc4GoTngIdWy67uFqdC7f0/+cgarxl78cz6zSOJjCrVO+B7w2vi 8cfRi/xUcc0DavDI/Itr+iAllwXT3wqCw== Received: from mail.thefacebook.com ([163.114.134.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 4jbq7q38dq-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Fri, 04 Dec 2026 07:53:54 -0800 (PST) Received: from localhost (2620:10d:c085:208::7cb7) by mail.thefacebook.com (2620:10d:c08b:78::2ac9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.57; Fri, 4 Dec 2026 15:53:52 +0000 Date: Fri, 4 Dec 2026 07:53:51 -0800 From: Bobby Eshleman To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: Re: [PATCH net-next v8 4/7] vsock: add a netlink command to assign the g2h device to a netns Message-ID: References: <20261130-vsock-guest-ns-v8-4-5fff852d325b@meta.com> <179623843306.3146.12501387936973395451@kernel.org> X-Mailing-List: linux-doc@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <179623843306.3146.12501387936973395451@kernel.org> X-Proofpoint-Spam-Info: AW1haW4tMjYxMjA0MDA2MyBTYWx0ZWRfX9g6yr570iMdB sObgJkG5v8t55si+q59aJFvC96EjRvAVjc+cCnYP3qs/l/wJDNXDgyPU8td7c02iXuRyQako0dY FmHy+9+As8F+jfzBp6z62FI8tjXCZaU= X-Proofpoint-ORIG-GUID: QekUKIPBKUw-DN7ZMoVlaXJyfpLMuITB X-Authority-Analysis: v=2.4 cv=NvBE4MdJ c=1 sm=1 tr=0 ts=6b12e212 cx=c_pps a=CB4LiSf2rd0gKozIdrpkBw==:117 a=CB4LiSf2rd0gKozIdrpkBw==:17 a=8nJEP1OIZ-IA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7x6HtfJdh03M6CCDgxCd:22 a=GbPsI2Ihf5RTnMjR_gZv:22 a=VwQbUJbxAAAA:8 a=VabnemYjAAAA:8 a=H4RdS6Ye-A5bI8oXaJYA:9 a=3ZKOabzyN94A:10 a=wPNLvfGTeEIA:10 a=gKebqoRLp9LExxC7YDUY:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjA0MDA2MyBTYWx0ZWRfXwT3b4xudgZnA fbFIH53fHNSUcmMpLkixw78xst+aUVOsxgW0olFZ0WbiBI8Gpj3xm4tCQiqgMuqbAGCjRHK5JBE 5MOECNONOEtHO+KaqXOAWi99Vp+R/iXp2pqt02jn6HSyoFq2MNIiHQXqnheVNW8rN/foxGs4gVy H5Te3kZVX72XzjIhBN4SpyIFtvD2C647CJakQc27ySX2ihmr51NvKz5bAQUx7F/MtWo6dW+jPmB VNejzpTynmYhrCXrRAZ2DBw8td16RxWnPKNYRAcoMCB0bnyQgEC5+p/5+0m18XOttG6hoALC326 YWZB/SlTr1ernri+txGrtW3E2SXmFon76i5m/qr/X8Q0XGvbIxwr02kVWD3RjbrRnrkFpHrRFtr 9knkrOvNDriMe2gVA+WztDQMW1GEKCjtW0YZ9t7YxWVZDpGvswMurB7xlghDc9sOlu2+Qlio/zA 9gf64zn5KguBOZkTC2w== X-Proofpoint-GUID: QekUKIPBKUw-DN7ZMoVlaXJyfpLMuITB X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-04_03,2026-12-03_04,2025-10-01_01 On Wed, Dec 02, 2026 at 07:07:13PM +0000, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 4 potential > issue(s) to consider. > > Critical: 0 · High: 0 · Medium: 2 · 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). > > - [Medium] vsock: unsafe lockless TCP_CLOSE reset in > vsock_g2h_reset_unreachable_sk() > - [Medium] vsock: vsock_g2h_reset_unreachable_sk() TCP_CLOSE races with > vsock_connect() > - [Low] In the main use case, the VSOCK_CMD_DEV_NETNS_SET reply does not > say where the device went. > - [Low] Documentation/admin-guide/sysctl/net.rst says that assigning the > device to another namespace "is the only way to undo an assignment". > > -- > > vsock: add a netlink command to assign the g2h device to a netns > > This commit adds a vsock generic netlink family. VSOCK_CMD_DEV_NETNS_SET > moves the guest's G2H vsock device into a network namespace, and > VSOCK_CMD_DEV_NETNS_GET reads the assignment back as an nsid relative to > the caller. Connected sockets that can no longer reach the device after > a move are reset with ECONNRESET, and assignments that would cause a CID > collision are refused. > > Link: https://lore.kernel.org/all/20200427142518.uwssa6dtasrp3bfc@steredhat/ > > > diff --git a/Documentation/admin-guide/sysctl/net.rst b/Documentation/admin-guide/sysctl/net.rst > > index fe43e85959583..0d219d80e6741 100644 > > --- a/Documentation/admin-guide/sysctl/net.rst > > +++ b/Documentation/admin-guide/sysctl/net.rst > > @@ -529,6 +529,46 @@ their hosts. The behavior of VSOCK sockets in a network namespace is determined > > [ ... ] > > > +An assignment keeps the namespace alive, the same way an open socket does, so > > +deleting that namespace does not move the device. Assigning the device to > > +another namespace, such as init_net, is the only way to undo an assignment, and > > +releases the reference the assignment held on the previous namespace. > > [Severity: Low] > Is "the only way to undo an assignment" accurate? vsock_core_unregister() > also moves the device back to init_net when the g2h transport > unregisters, for example when rmmod of the virtio transport runs > virtio_vsock_exit(): Not worth a respin alone IMHO, but I can tighten the language there if we need a new rev. > > net/vmw_vsock/af_vsock.c:vsock_core_unregister() { > ... > if (transport_g2h == t) { > transport_g2h = NULL; > old = vsock_g2h_net_swap(&init_net, &old_tracker); > } > ... > } > > When the transport registers again, the device is in init_net, so every > global mode namespace can reach it again. Userspace is not told about > this, because the family has no multicast group. > > The comment in af_vsock.c covers this path ("on another assignment or when > the transport unregisters"), but the admin guide does not. Could the admin > guide also mention the unregister path? This text is unchanged at the end > of the series. > > [ ... ] > > > 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 > > [ ... ] > > > +static int vsock_nl_dev_netns_fill(struct sk_buff *msg, struct genl_info *info, > > + struct net *g2h) > > +{ > > + struct net *net = genl_info_net(info); > > + bool equal; > > + void *hdr; > > + s32 id; > > + > > + lockdep_assert_held(&vsock_register_mutex); > > + > > + equal = net_eq(net, g2h); > > + if (!equal) { > > + if (vsock_net_assignable(transport_g2h) && > > + !vsock_net_check_mode(net, g2h)) > > + id = NETNSA_NSID_NOT_ASSIGNED; > > + else > > + id = peernet2id_alloc(net, g2h, GFP_KERNEL); > > + } > > [Severity: Low] > Does this give a useful VSOCK_CMD_DEV_NETNS_SET reply when the target is > a local mode namespace? > > vsock_g2h_net_assign() builds the SET reply with the target namespace > passed as g2h. Here, net is genl_info_net(info), the caller's namespace. > vsock_net_check_mode() returns false whenever the two namespaces differ > and either one is in local mode. > > Consider an admin in init_net, or in any global namespace, who moves the > device into a local mode namespace with netns-fd or netns-pid: > > vsock_nl_dev_netns_set_doit() > vsock_g2h_net_assign() > vsock_nl_dev_netns_fill(msg, info, net) > net_eq(init_net, target) -> false > vsock_net_assignable(transport_g2h) -> true > vsock_net_check_mode(init_net, target) -> false > id = NETNSA_NSID_NOT_ASSIGNED > > vsock_net_assignable() returns true for virtio once the later commit > "vsock/virtio: support guest device network namespace" sets > .netns_assign_allow = true. > > The admin always gets NETNSA_NSID_NOT_ASSIGNED back in this case. That > is the main isolation use case for the feature. SET is GENL_ADMIN_PERM, > and the caller picked the target itself, so hiding the target from this > caller does not seem to protect anything. > > The commit message says: > > VSOCK_CMD_DEV_NETNS_SET > replies the same way for the namespace the device was moved to. > > That reads as if the reply identifies the new namespace, but it does not > in this case. > > The same rule also means a GET from init_net can never report which > local namespace holds the device. > > This reply format becomes uAPI once released. Could the SET reply skip > the mode check, so that it identifies the namespace the device was moved > to? The code is unchanged at the end of the series. > > > + > > + hdr = genlmsg_iput(msg, info); > > + if (!hdr) > > + return -EMSGSIZE; Yes, this is a good catch. Will change next rev. > > [ ... ] > > > +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); > > +} > > [ ... ] > > > + vsock_for_each_connected_socket(transport_g2h, > > + vsock_g2h_reset_unreachable_sk); > > [ ... ] > > [Severity: Medium] > Can this sweep turn a connect() that just succeeded into a failed one? > > vsock_connect() drops lock_sock() and sleeps in schedule_timeout(). > When the OP_RESPONSE arrives, virtio_transport_recv_connecting() calls > vsock_maybe_set_connected(). That sets TCP_ESTABLISHED and links vsk > into vsock_connected_table with a reference held, and sock->state > becomes SS_CONNECTED. > > If the assignment runs before the woken vsock_connect() looks at > sk_state, vsock_g2h_reset_unreachable_sk() stores TCP_CLOSE and > ECONNRESET. Since the sweep does not take lock_sock(), this can also > happen after vsock_connect() has taken the lock back. > > vsock_connect() only treats TCP_ESTABLISHED and TCP_CLOSING as > connected. It therefore falls into the failure path with a socket that > is still linked in vsock_connected_table. > > On a signal or timeout it calls vsock_transport_cancel_pkt() on what > are now data skbs of an established connection. That is the > bytes_unsent leak the v8 changelog removed cancel_pkt() from the sweep > to avoid. Otherwise it consumes sk_err with sock_error() and sets > sock->state back to SS_UNCONNECTED. > > A second connect() on that socket is then accepted: > > - To a CID served by another transport, vsock_assign_transport() > calls virtio_transport_release(), which does not linger because the > socket is TCP_CLOSE. vsock_deassign_transport() -> > virtio_transport_destruct() then frees vsk->trans. TX skbs queued > before the sweep are still in flight, so > virtio_transport_consume_skb_sent() then dereferences freed memory. > > - Through transport_g2h, once the device is reachable from the > socket's namespace again, the transport is unchanged, so release() > is skipped. The next vsock_maybe_set_connected() then calls > __vsock_insert_connected() on a node that is already on the list. > That corrupts vsock_connected_table and leaks a socket reference. > > v6 moved swept sockets to TCP_CLOSING because vsock_connect() handles > that state as established. v8 goes back to TCP_CLOSE to mirror an > unplug. Should the sweep keep a state that vsock_connect() recognises? > Or should vsock_connect() check for SS_CONNECTED before treating > sk_err as a failed connect? This goes away with this patch: https://lore.kernel.org/all/20261130-vsock-connect-close-v3-1-7a9abc4e3474@meta.com/ The vsock_transport_cancel_pkt() on signal/timeout is pre-existing, since TRANSPORT_RESET can land in the same window after another thread has already queued data. The bytes_unsent leak comes from virtio_transport_purge_skbs(), which does not account for bytes_unsent (I think it was originally for non-RW pkts). I'd rather fix that there (adjust bytes_unsent if pkt type is OP_RW) than work around the issue in this series. It doesn't really affect users either. bytes_unsent is only read by SIOCOUTQ and by SO_LINGER on close(). The socket is TCP_CLOSE after the failed connect(), so close() doesn't linger, and with the connect() fix above it can't be connected again and carry the stale count into a new connection. What's left is SIOCOUTQ reporting stale bytes on a socket whose connect() just failed. > > [Severity: Medium] > Is it safe to update sk_state and sk_err here without lock_sock()? > > The changelog cites virtio_vsock_reset_sock() as prior art, but there > the device is being removed and nothing more will be delivered for the > socket. Here the device stays live across vsock_g2h_net_assign(), so > virtio_transport_recv_pkt() can be working on the same socket under > lock_sock(sk) at the same time. If it looked the socket up before > vsock_g2h_net_swap(), virtio_transport_recv_connected() -> > virtio_transport_do_close() can store TCP_CLOSING after the sweep > stored TCP_CLOSE. The socket then ends up in a state the sweep did not > intend. > > The reset also leaves sk_shutdown and vsk->peer_shutdown untouched, so > sk_err is the only thing a sleeper can notice. In recvmsg(), > vsock_connectible_wait_data() breaks out on sk_err, RCV_SHUTDOWN or > the peer's SEND_SHUTDOWN, but never looks at sk_state. > > Another thread can consume sk_err with sock_error() first, for example > through getsockopt(SO_ERROR) or a woken vsock_connect(). The reader > then finds sk_err == 0 and peer_shutdown == 0, and goes back to sleep > on a TCP_CLOSE socket. Nothing else will wake it, so it blocks until > its receive timeout expires, or forever if none is set. > > The same unlocked TCP_CLOSE store also lets a sleeping vsock_connect() > treat an established socket as a failed connect. See the comment on > the sweep in vsock_g2h_net_assign(). > > Could the reset be done under lock_sock(), for example from a work > item? Or could the sweep mark the socket shut down, so that waiters > see a terminal condition that another thread cannot consume first? First, these aren't real bugs that impact users. If a peer RST races the sweep, the socket ends up TCP_CLOSING instead of TCP_CLOSE, still w/ ECONNRESET. poll() and close() treat those the same, so the only difference is recv() returning 0 instead of -ENOTCONN, which is also what you'd see if the RST had come in just before the netns move. I don't really see this as a problem. Second, these symptoms all show up on TRANSPORT_RESET and device unplug too, where contrary to what Sashiko writes above, the reset does happen on live devices with live sockets (see how qemu migration works... TRANSPORT_RESET + live sockets + live device). Even for virtio_vsock_vqs_del() we reset the sockets before truly shutting down the device by stopping rx_work. lock_sock() doesn't help with the sock_error() issue... getsockopt(SO_ERROR) consumes sk_err without the lock. It's also pre-existing. Connecting to a port with no listener gets an RST back, which only sets sk_err. If another thread reads SO_ERROR first, the thread in connect() goes back to sleep until connect_timeout. That happens today w/o this series, and any transport reset can do the same to a reader in recv(). Will respin for at least the API change though. pw-bot: cr Best, Bobby