From: Bobby Eshleman <bobbyeshleman@gmail.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: "Shuah Khan" <shuah@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"K. Y. Srinivasan" <kys@microsoft.com>,
"Haiyang Zhang" <haiyangz@microsoft.com>,
"Wei Liu" <wei.liu@kernel.org>,
"Dexuan Cui" <decui@microsoft.com>,
"Bryan Tan" <bryan-bt.tan@broadcom.com>,
"Vishnu Dasa" <vishnu.dasa@broadcom.com>,
"Broadcom internal kernel review list"
<bcm-kernel-feedback-list@broadcom.com>,
virtualization@lists.linux.dev, netdev@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
kvm@vger.kernel.org, linux-hyperv@vger.kernel.org,
berrange@redhat.com, "Bobby Eshleman" <bobbyeshleman@meta.com>
Subject: Re: [PATCH net-next v8 04/14] vsock: add netns to vsock core
Date: Thu, 6 Nov 2025 18:03:10 -0800 [thread overview]
Message-ID: <aQ1TXjb8AWIzgAu4@devvm11784.nha0.facebook.com> (raw)
In-Reply-To: <zxy7e4xihxujtlcnqjdgfxaqckfurop77eukbose74nzaxyv64@7djyz3gv4eys>
On Thu, Nov 06, 2025 at 05:18:00PM +0100, Stefano Garzarella wrote:
> On Thu, Oct 23, 2025 at 11:27:43AM -0700, Bobby Eshleman wrote:
> > From: Bobby Eshleman <bobbyeshleman@meta.com>
> >
> > Add netns logic to vsock core. Additionally, modify transport hook
> > prototypes to be used by later transport-specific patches (e.g.,
> > *_seqpacket_allow()).
> >
> > Namespaces are supported primarily by changing socket lookup functions
> > (e.g., vsock_find_connected_socket()) to take into account the socket
> > namespace and the namespace mode before considering a candidate socket a
> > "match".
> >
> > Introduce a dummy namespace struct, __vsock_global_dummy_net, to be
> > used by transports that do not support namespacing. This dummy always
> > has mode "global" to preserve previous CID behavior.
> >
> > This patch also introduces the sysctl /proc/sys/net/vsock/ns_mode that
> > accepts the "global" or "local" mode strings.
> >
> > The transports (besides vhost) are modified to use the global dummy,
> > which makes them behave as if always in the global namespace. Vhost is
> > an exception because it inherits its namespace from the process that
> > opens the vhost device.
> >
> > Add netns functionality (initialization, passing to transports, procfs,
> > etc...) to the af_vsock socket layer. Later patches that add netns
> > support to transports depend on this patch.
> >
> > seqpacket_allow() callbacks are modified to take a vsk so that transport
> > implementations can inspect sock_net(sk) and vsk->net_mode when performing
> > lookups (e.g., vhost does this in its future netns patch). Because the
> > API change affects all transports, it seemed more appropriate to make
> > this internal API change in the "vsock core" patch then in the "vhost"
> > patch.
> >
> > Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>
> > ---
> > Changes in v7:
> > - hv_sock: fix hyperv build error
> > - explain why vhost does not use the dummy
> > - explain usage of __vsock_global_dummy_net
> > - explain why VSOCK_NET_MODE_STR_MAX is 8 characters
> > - use switch-case in vsock_net_mode_string()
> > - avoid changing transports as much as possible
> > - add vsock_find_{bound,connected}_socket_net()
> > - rename `vsock_hdr` to `sysctl_hdr`
> > - add virtio_vsock_alloc_linear_skb() wrapper for setting dummy net and
> > global mode for virtio-vsock, move skb->cb zero-ing into wrapper
> > - explain seqpacket_allow() change
> > - move net setting to __vsock_create() instead of vsock_create() so
> > that child sockets also have their net assigned upon accept()
> >
> > Changes in v6:
> > - unregister sysctl ops in vsock_exit()
> > - af_vsock: clarify description of CID behavior
> > - af_vsock: fix buf vs buffer naming, and length checking
> > - af_vsock: fix length checking w/ correct ctl_table->maxlen
> >
> > Changes in v5:
> > - vsock_global_net() -> vsock_global_dummy_net()
> > - update comments for new uAPI
> > - use /proc/sys/net/vsock/ns_mode instead of /proc/net/vsock_ns_mode
> > - add prototype changes so patch remains compilable
> > ---
> > drivers/vhost/vsock.c | 4 +-
> > include/linux/virtio_vsock.h | 21 ++++
> > include/net/af_vsock.h | 14 ++-
> > net/vmw_vsock/af_vsock.c | 264 ++++++++++++++++++++++++++++++++++++---
> > net/vmw_vsock/virtio_transport.c | 7 +-
> > net/vmw_vsock/vsock_loopback.c | 4 +-
> > 6 files changed, 288 insertions(+), 26 deletions(-)
> >
> > diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
> > index ae01457ea2cd..34adf0cf9124 100644
> > --- a/drivers/vhost/vsock.c
> > +++ b/drivers/vhost/vsock.c
> > @@ -404,7 +404,7 @@ static bool vhost_transport_msgzerocopy_allow(void)
> > return true;
> > }
> >
> > -static bool vhost_transport_seqpacket_allow(u32 remote_cid);
> > +static bool vhost_transport_seqpacket_allow(struct vsock_sock *vsk, u32 remote_cid);
> >
> > static struct virtio_transport vhost_transport = {
> > .transport = {
> > @@ -460,7 +460,7 @@ static struct virtio_transport vhost_transport = {
> > .send_pkt = vhost_transport_send_pkt,
> > };
> >
> > -static bool vhost_transport_seqpacket_allow(u32 remote_cid)
> > +static bool vhost_transport_seqpacket_allow(struct vsock_sock *vsk, u32 remote_cid)
> > {
> > struct vhost_vsock *vsock;
> > bool seqpacket_allow = false;
> > diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
> > index 7f334a32133c..29290395054c 100644
> > --- a/include/linux/virtio_vsock.h
> > +++ b/include/linux/virtio_vsock.h
> > @@ -153,6 +153,27 @@ static inline void virtio_vsock_skb_set_net_mode(struct sk_buff *skb,
> > VIRTIO_VSOCK_SKB_CB(skb)->net_mode = net_mode;
> > }
> >
> > +static inline struct sk_buff *
> > +virtio_vsock_alloc_rx_skb(unsigned int size, gfp_t mask)
> > +{
> > + struct sk_buff *skb;
> > +
> > + skb = virtio_vsock_alloc_linear_skb(size, mask);
> > + if (!skb)
> > + return NULL;
> > +
> > + memset(skb->head, 0, VIRTIO_VSOCK_SKB_HEADROOM);
> > +
> > + /* virtio-vsock does not yet support namespaces, so on receive
> > + * we force legacy namespace behavior using the global dummy net
> > + * and global net mode.
> > + */
> > + virtio_vsock_skb_set_net(skb, vsock_global_dummy_net());
> > + virtio_vsock_skb_set_net_mode(skb, VSOCK_NET_MODE_GLOBAL);
> > +
> > + return skb;
> > +}
>
> Why we are introducing this change in this patch?
>
> Where the net of the virtio's skb is read?
>
Oh good point, this is a weird place for this. I'll move this to where
it is actually used.
[...]
> >
> > +static int vsock_net_mode_string(const struct ctl_table *table, int write,
> > + void *buffer, size_t *lenp, loff_t *ppos)
> > +{
> > + char data[VSOCK_NET_MODE_STR_MAX] = {0};
> > + enum vsock_net_mode mode;
> > + struct ctl_table tmp;
> > + struct net *net;
> > + int ret;
> > +
> > + if (!table->data || !table->maxlen || !*lenp) {
> > + *lenp = 0;
> > + return 0;
> > + }
> > +
> > + net = current->nsproxy->net_ns;
> > + tmp = *table;
> > + tmp.data = data;
> > +
> > + if (!write) {
> > + const char *p;
> > +
> > + mode = vsock_net_mode(net);
> > +
> > + switch (mode) {
> > + case VSOCK_NET_MODE_GLOBAL:
> > + p = VSOCK_NET_MODE_STR_GLOBAL;
> > + break;
> > + case VSOCK_NET_MODE_LOCAL:
> > + p = VSOCK_NET_MODE_STR_LOCAL;
> > + break;
> > + default:
> > + WARN_ONCE(true, "netns has invalid vsock mode");
> > + *lenp = 0;
> > + return 0;
> > + }
> > +
> > + strscpy(data, p, sizeof(data));
> > + tmp.maxlen = strlen(p);
> > + }
> > +
> > + ret = proc_dostring(&tmp, write, buffer, lenp, ppos);
> > + if (ret)
> > + return ret;
> > +
> > + if (write) {
>
> Do we need to check some capability, e.g. CAP_NET_ADMIN ?
>
We get that for free via the sysctl_net registration, through this path
on open (CAP_NET_ADMIN is checked in net_ctl_permissions):
net_ctl_permissions+1
sysctl_perm+24
proc_sys_permission+117
inode_permission+217
link_path_walk+162
path_openat+152
do_filp_open+171
do_sys_openat2+98
__x64_sys_openat+69
do_syscall_64+93
Verified with:
cp /bin/echo /tmp/echo_netadmin
setcap cap_net_admin+ep /tmp/echo_netadmin
(non-root user fails with regular echo, succeeds with
/tmp/echo_netadmin)
Best regards,
Bobby
next prev parent reply other threads:[~2025-11-07 2:03 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-23 18:27 [PATCH net-next v8 00/14] vsock: add namespace support to vhost-vsock Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 01/14] vsock: a per-net vsock NS mode state Bobby Eshleman
2025-11-06 16:16 ` Stefano Garzarella
2025-11-07 1:09 ` Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 02/14] vsock/virtio: pack struct virtio_vsock_skb_cb Bobby Eshleman
2025-11-06 16:16 ` Stefano Garzarella
2025-10-23 18:27 ` [PATCH net-next v8 03/14] vsock: add netns to vsock skb cb Bobby Eshleman
2025-11-06 16:17 ` Stefano Garzarella
2025-10-23 18:27 ` [PATCH net-next v8 04/14] vsock: add netns to vsock core Bobby Eshleman
2025-11-06 16:18 ` Stefano Garzarella
2025-11-07 2:03 ` Bobby Eshleman [this message]
2025-11-07 13:53 ` Stefano Garzarella
2025-10-23 18:27 ` [PATCH net-next v8 05/14] vsock/loopback: add netns support Bobby Eshleman
2025-11-06 16:18 ` Stefano Garzarella
2025-11-07 2:17 ` Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 06/14] vsock/virtio: add netns to virtio transport common Bobby Eshleman
2025-11-06 16:20 ` Stefano Garzarella
2025-11-07 2:52 ` Bobby Eshleman
2025-11-07 14:30 ` Stefano Garzarella
2025-11-07 14:33 ` Bobby Eshleman
2025-11-07 15:07 ` Stefano Garzarella
2025-11-07 15:47 ` Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 07/14] vhost/vsock: add netns support Bobby Eshleman
2025-11-06 16:21 ` Stefano Garzarella
2025-11-07 3:07 ` Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 08/14] selftests/vsock: add namespace helpers to vmtest.sh Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 09/14] selftests/vsock: prepare vm management helpers for namespaces Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 10/14] selftests/vsock: add tests for proc sys vsock ns_mode Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 11/14] selftests/vsock: add namespace tests for CID collisions Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 12/14] selftests/vsock: add tests for host <-> vm connectivity with namespaces Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 13/14] selftests/vsock: add tests for namespace deletion and mode changes Bobby Eshleman
2025-10-23 18:27 ` [PATCH net-next v8 14/14] selftests/vsock: add tests for module loading order Bobby Eshleman
2025-10-27 13:28 ` [PATCH net-next v8 00/14] vsock: add namespace support to vhost-vsock Stefano Garzarella
2025-10-27 17:25 ` Bobby Eshleman
2025-11-06 16:23 ` Stefano Garzarella
2025-11-07 1:00 ` Bobby Eshleman
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=aQ1TXjb8AWIzgAu4@devvm11784.nha0.facebook.com \
--to=bobbyeshleman@gmail.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=berrange@redhat.com \
--cc=bobbyeshleman@meta.com \
--cc=bryan-bt.tan@broadcom.com \
--cc=davem@davemloft.net \
--cc=decui@microsoft.com \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=haiyangz@microsoft.com \
--cc=horms@kernel.org \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kys@microsoft.com \
--cc=linux-hyperv@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=sgarzare@redhat.com \
--cc=shuah@kernel.org \
--cc=stefanha@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=vishnu.dasa@broadcom.com \
--cc=wei.liu@kernel.org \
--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
all inboxes | Powered by JetHome®