Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In check_assign_g2h_eperm()
(tools/testing/selftests/vsock/vmtest.sh), if the assign unexpectedly…
- [Low] check_assign_g2h_eperm() counts a run as PASS if the substring
"Operation not permitted" appears anywhere in the combined stdout and…
--
selftests/vsock: test the netns assign privilege checks
This patch adds two vsock selftests. Both check that
VSOCK_CMD_DEV_NETNS_SET is refused in two cases: when CAP_NET_ADMIN has
been dropped from the bounding set, and when the caller holds
CAP_NET_ADMIN only in an unprivileged user namespace. It also enables
CONFIG_USER_NS in the selftest config and makes setpriv a dependency of
these two tests.
> diff --git a/tools/testing/selftests/vsock/vmtest.sh b/tools/testing/selftests/vsock/vmtest.sh
> index c771d0cb9268a..248a4c6900f1e 100755
> --- a/tools/testing/selftests/vsock/vmtest.sh
> +++ b/tools/testing/selftests/vsock/vmtest.sh
[ ... ]
> @@ -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}"
[Severity: Low]
If the assign unexpectedly succeeds, should this path call vm_reset_g2h()
before returning?
The request has neither a netns-fd nor a netns-pid attribute. In that
case vsock_nl_dev_netns_set_doit() uses the caller's netns:
net/vmw_vsock/af_vsock.c:vsock_nl_dev_netns_set_doit() {
...
else
net = get_net(genl_info_net(info));
...
}
Under the "unshare -n ..." and "... unshare -Urn" wrappers, the caller's
netns is a temporary one. If the privilege check ever regresses, the
guest's g2h device would move into a namespace that goes away when the
wrapper exits. test_ns_guest_assign_g2h_netns_pins_ns_ok shows that the
device keeps such a namespace alive until it is reassigned.
Both new tests are in USE_SHARED_VM. Any later shared-VM test that
expects the device to be in init_net would then fail for an unrelated
reason.
The other ns_guest_assign_* tests call vm_reset_g2h on their failure
paths. Could this helper do the same?
> + fi
> +
> + if [[ "${out}" != *"Operation not permitted"* ]]; then
> + log_host "no EPERM under '${wrapper}': [${out}]"
> + return "${KSFT_FAIL}"
> + fi
[Severity: Low]
Can this match give a false pass? The output is the merged stdout and
stderr of the whole wrapper chain. If unshare or setpriv fails with
EPERM, it prints something like:
unshare: unshare failed: Operation not permitted
That text passes the substring check, even though cli.py never ran and
no VSOCK_CMD_DEV_NETNS_SET request reached the kernel.
test_ns_guest_assign_g2h_netns_unpriv_user_ns_fails guards against this
by running the wrapper with "true" first:
if ! vm_ssh "init_ns" -- "${unpriv} unshare -Urn true"; then
test_ns_guest_assign_g2h_netns_no_cap_net_admin_fails has no such probe.
If "unshare -n" or "setpriv --bounding-set=-net_admin" fails in the guest
(for example because of an LSM or seccomp policy), the test would
report a pass for the CAP_NET_ADMIN check.
When the kernel rejects the request, cli.py prints the NlError string,
which starts with "Netlink error: " (see NlError.__str__() in
tools/net/ynl/pyynl/lib/ynl.py). Would matching on that prefix, or adding
the same "true" probe, tie the check to the kernel's GENL_ADMIN_PERM
rejection?
> +
> + 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"
> +}
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/2026…%40meta.com