From: Bobby Eshleman <bobbyeshleman@meta.com>
To: "Stefano Garzarella" <sgarzare@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Shuah Khan" <shuah@kernel.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Donald Hunter" <donald.hunter@gmail.com>,
"Eric Dumazet" <edumazet@kernel.org>,
"George Zhang" <georgezhang@vmware.com>,
"Andy King" <acking@vmware.com>,
"Dmitry Torokhov" <dtor@vmware.com>,
"Eric Dumazet" <edumazet@kernel.org>
Cc: <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>,
Bobby Eshleman <bobbyeshleman@gmail.com>,
Bobby Eshleman <bobbyeshleman@meta.com>
Subject: [PATCH net-next v7 7/7] selftests/vsock: test the netns assign privilege checks
Date: Tue, 17 Nov 2026 17:54:50 -0800 [thread overview]
Message-ID: <20261117-vsock-guest-ns-v7-7-7e522ea9dd9b@meta.com> (raw)
In-Reply-To: <20261117-vsock-guest-ns-v7-0-7e522ea9dd9b@meta.com>
VSOCK_CMD_DEV_NETNS_SET refuses callers without CAP_NET_ADMIN in the
init user namespace.
Add two tests: one confirms that CAP_NET_ADMIN is required even by a
privileged user and the other confirms that CAP_NET_ADMIN in an
unprivileged user ns alone is insufficient.
CONFIG_USER_NS is needed to test the CAP_NET_ADMIN + unprivileged user
ns case.
Signed-off-by: Bobby Eshleman <bobbyeshleman@meta.com>
---
Changes in v6:
- Require setpriv only for the two privilege tests, not every ns_guest_
test (Sashiko)
Changes in v4:
- Require EPERM in the privilege tests, cli.py does print the errno, and
probe unshare -Urn so a setup failure skips (Sashiko)
Changes in v3:
- Require setpriv only for the ns_guest_ tests, not the whole script
Changes in v2:
- Assert only that the command fails, not EPERM: ynl's cli.py does not
report the errno (Sashiko)
- Use ynl cli.py for the assign
---
tools/testing/selftests/vsock/config | 1 +
tools/testing/selftests/vsock/vmtest.sh | 59 ++++++++++++++++++++++++++++++++-
2 files changed, 59 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/vsock/config b/tools/testing/selftests/vsock/config
index 5f0a4f17dfc9..4b31085558fa 100644
--- a/tools/testing/selftests/vsock/config
+++ b/tools/testing/selftests/vsock/config
@@ -109,3 +109,4 @@ CONFIG_FS_DAX=y
CONFIG_MEMORY_HOTPLUG=y
CONFIG_MEMORY_HOTREMOVE=y
CONFIG_ZONE_DEVICE=y
+CONFIG_USER_NS=y
diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selftests/vsock/vmtest.sh
index c771d0cb9268..248a4c6900f1 100755
--- a/tools/testing/selftests/vsock/vmtest.sh
+++ b/tools/testing/selftests/vsock/vmtest.sh
@@ -94,6 +94,8 @@ readonly TEST_NAMES=(
ns_guest_assign_g2h_netns_host_connect_ok
ns_guest_assign_g2h_netns_pins_ns_ok
ns_guest_assign_g2h_netns_old_conn_send_fails
+ ns_guest_assign_g2h_netns_no_cap_net_admin_fails
+ ns_guest_assign_g2h_netns_unpriv_user_ns_fails
)
readonly TEST_DESCS=(
# vm_server_host_client
@@ -191,6 +193,12 @@ readonly TEST_DESCS=(
# ns_guest_assign_g2h_netns_old_conn_send_fails
"Check connections made before the assign stop sending once they lose the device."
+
+ # ns_guest_assign_g2h_netns_no_cap_net_admin_fails
+ "Check assigning the guest's vsock device to a namespace needs CAP_NET_ADMIN."
+
+ # ns_guest_assign_g2h_netns_unpriv_user_ns_fails
+ "Check an unprivileged user cannot claim the guest's vsock device via a user ns."
)
readonly USE_SHARED_VM=(
@@ -204,6 +212,8 @@ readonly USE_SHARED_VM=(
ns_guest_assign_g2h_netns_host_connect_ok
ns_guest_assign_g2h_netns_pins_ns_ok
ns_guest_assign_g2h_netns_old_conn_send_fails
+ ns_guest_assign_g2h_netns_no_cap_net_admin_fails
+ ns_guest_assign_g2h_netns_unpriv_user_ns_fails
)
readonly NS_MODES=("local" "global")
@@ -367,13 +377,22 @@ check_deps() {
check_ns_guest_deps() {
local tname=$1
+ local deps="unshare python3"
local dep
if [[ ! "${tname}" =~ ^ns_guest_ ]]; then
return 0
fi
- for dep in unshare python3; do
+ # test-specific guest dep checks
+ case "${tname}" in
+ ns_guest_assign_g2h_netns_no_cap_net_admin_fails | \
+ ns_guest_assign_g2h_netns_unpriv_user_ns_fails)
+ deps="${deps} setpriv"
+ ;;
+ esac
+
+ for dep in ${deps}; do
if [[ ! -x $(command -v "${dep}") ]]; then
log_host "no ${dep} for test ${tname}"
return 1
@@ -1951,6 +1970,44 @@ test_ns_guest_assign_g2h_netns_pins_ns_ok() {
return "${KSFT_PASS}"
}
+check_assign_g2h_eperm() {
+ local wrapper=$1
+ local out
+
+ if out=$(vm_ssh "init_ns" -- "${wrapper}" python3 /root/ynl/cli.py \
+ --no-schema --spec /root/ynl/vsock.yaml \
+ --do dev-netns-set 2>&1); then
+ log_host "assign unexpectedly succeeded under '${wrapper}'"
+ return "${KSFT_FAIL}"
+ fi
+
+ if [[ "${out}" != *"Operation not permitted"* ]]; then
+ log_host "no EPERM under '${wrapper}': [${out}]"
+ return "${KSFT_FAIL}"
+ fi
+
+ return "${KSFT_PASS}"
+}
+
+test_ns_guest_assign_g2h_netns_no_cap_net_admin_fails() {
+ check_assign_g2h_eperm "unshare -n setpriv --bounding-set=-net_admin"
+}
+
+test_ns_guest_assign_g2h_netns_unpriv_user_ns_fails() {
+ local unpriv_uid=65534
+ local unpriv
+
+ unpriv="setpriv --reuid=${unpriv_uid} --regid=${unpriv_uid}"
+ unpriv="${unpriv} --clear-groups"
+
+ if ! vm_ssh "init_ns" -- "${unpriv} unshare -Urn true"; then
+ log_host "unprivileged user namespaces unavailable, skipping"
+ return "${KSFT_SKIP}"
+ fi
+
+ check_assign_g2h_eperm "${unpriv} unshare -Urn"
+}
+
shared_vm_test() {
local tname
--
2.53.1-Meta
prev parent reply other threads:[~2026-11-18 1:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 1:54 [PATCH net-next v7 0/7] vsock: assign the guest vsock device to a network namespace Bobby Eshleman
2026-11-18 1:54 ` [PATCH net-next v7 1/7] vsock: constify the transport in vsock_for_each_connected_socket() Bobby Eshleman
2026-11-18 1:54 ` [PATCH net-next v7 2/7] vsock: rename the vsock pernet operations Bobby Eshleman
2026-11-18 1:54 ` [PATCH net-next v7 3/7] vsock: pass the netns to ->has_remote_cid() Bobby Eshleman
2026-11-18 1:54 ` [PATCH net-next v7 4/7] vsock: add a netlink command to assign the g2h device to a netns Bobby Eshleman
2026-11-18 1:54 ` [PATCH net-next v7 5/7] vsock/virtio: support guest device network namespace Bobby Eshleman
2026-11-18 1:54 ` [PATCH net-next v7 6/7] selftests/vsock: test the guest vsock " Bobby Eshleman
2026-11-18 1:54 ` Bobby Eshleman [this message]
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=20261117-vsock-guest-ns-v7-7-7e522ea9dd9b@meta.com \
--to=bobbyeshleman@meta.com \
--cc=acking@vmware.com \
--cc=bobbyeshleman@gmail.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=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®