From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=67.231.145.42 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796087267; b=0O20fOuCJEKLA6RX0Q88pB7Q7d4V35bJAR9ip6OVh6Nsvlt5zVYwtkJ8Uu+LHlnxoXsn chMoRwFybl3/udB+UC4UuFaqndqwZnIHMJ8T7B7YFeA8hzb2fxyWkQpeSmGkpwe4z5UHL JaFiXC/q75UfjQKUbAZh9ojOXYKPAOXNMwbdr1b9lP3uOIO1HcaMQ8J6uvHxZ7eoUkRXp AThzffP+3mTcu3E7lNaJ7ycrwr3WaDWznFZQP7gcjptol7r0bMWUPCgONo4BO/LNpTiq0 FoJsSSZXMAXfoUwydk7Y5m9fpMS/SGPYam6ZjAtX7oHOR1hVFkXdckj1YtHtZK5Q/+Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796087267; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:From:Date: Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-ID:References:In-Reply-To:To:CC:X-Mailer:X-Originating-IP: X-Authority-Analysis:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-Spam-Info: X-Proofpoint-GUID:X-Proofpoint-Virus-Version; bh=zFY1GmSViuXI0rPHC6t3ZteUEq5nixMZVkXt8LdMcNY=; b=03xfqsJsc/KdkO+//Eq3shPUCJ9Z/5p6uAeiUy+nx2gIulgzuuOEr9Th65Nta9I7nZz8 Au+QlDX2uX0XOAuyzNWBwv1GZvrMaGfprHxFPysWStswily9nA+QnMgBp/DP0sHFXkKIg ML4hKQgIOFAuHLjssIIdGMClGrice0WxzSHz5nT1bp3Qr6Cndl04z5tX3QdUlKRLkbKkr MEErVLBYLtW/vqX1ur2dQDd90u3ctDggLqGmWCAZptaqR1QzyZ4t1b92K4bQ+lfgDHx91 P/cuQ3BvKD1GjwiPaEVG7Ag+veU4Gl17kPSo4MLLv/i4PZQNCzGPOof7SYK21yTM3Tg== 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=LyVLi87k; arc=none smtp.remote-ip=67.231.145.42 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (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 1C550606A32F; Tue, 1 Dec 2026 01:07:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1C550606A32F 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=LyVLi87k Received: from pps.filterd (m0528009.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AUKWxLw1502082; Mon, 30 Nov 2026 17:07:18 -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=zFY1GmSViuXI0rPHC6t3ZteUEq5nixMZVkXt8 LdMcNY=; b=LyVLi87kwAkLCxDm8jgiAF1WJ6Uiq8ZOTGCx0C5wu9+aH2WatwpTt BLwy26+t1KUqQIDyZL13XFyxeAlGlLuaUKvFmVE0rWI6uR+9htd9l+QEb9ean2Sp OtMaSsu+bdJgHiiT0zoDxY/N5bmTGW3+Hal3K4Ly7KrUKrT9JD2WiZ8QV61gauE3 wGL7NWei9sxPyaun/jBk3BJMjlrlOnazfuKOsAbcZ6BNc7DuiUziUNoaPe9CMY3C 0l6wGUUuLpCTkuhbZSFmG2MrzXlznRJjs1+dYEfsaRFxY+bfWzZpInWT9uhgknA9 9Z2gVTTXMmZokYDJJqYd4FkZozrbl8MSQ== Received: from maileast.thefacebook.com ([163.114.135.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 4j8hka2efx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 30 Nov 2026 17:07:18 -0800 (PST) Received: from localhost (2620:10d:c0a8:1b::8e35) by mail.thefacebook.com (2620:10d:c0a9:6f::8fd4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.2562.56; Tue, 1 Dec 2026 01:07:16 +0000 From: Bobby Eshleman Date: Mon, 30 Nov 2026 17:06:55 -0800 Subject: [PATCH net-next v8 7/7] selftests/vsock: test the netns assign privilege checks X-Mailing-List: linux-kernel@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="utf-8" Content-Transfer-Encoding: 7bit Message-ID: <20261130-vsock-guest-ns-v8-7-5fff852d325b@meta.com> References: <20261130-vsock-guest-ns-v8-0-5fff852d325b@meta.com> In-Reply-To: <20261130-vsock-guest-ns-v8-0-5fff852d325b@meta.com> To: Stefano Garzarella , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Simon Horman , Jonathan Corbet , Shuah Khan , Stefan Hajnoczi , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?utf-8?q?Eugenio_P=C3=A9rez?= , Shuah Khan , Randy Dunlap , Donald Hunter , Eric Dumazet , George Zhang , Andy King , Dmitry Torokhov , Willem de Bruijn , Eric Dumazet CC: , , , , , , , , Bobby Eshleman , Bobby Eshleman X-Mailer: b4 0.14.3 X-Authority-Analysis: v=2.4 cv=WcWZ+EhX c=1 sm=1 tr=0 ts=6b0e1dc6 cx=c_pps a=MfjaFnPeirRr97d5FC5oHw==:117 a=MfjaFnPeirRr97d5FC5oHw==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=7x6HtfJdh03M6CCDgxCd:22 a=U_y8lYiYyhHBU5rMqhb2:22 a=VabnemYjAAAA:8 a=xFiaXek5eyy1MN0Ju3QA:9 a=QEXdDO2ut3YA:10 a=gKebqoRLp9LExxC7YDUY:22 X-Proofpoint-ORIG-GUID: DkV5BaB_XBUcUQBi9z9xoh6O_ozEEzlP X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDAwNCBTYWx0ZWRfX/RoAQ4QSkYIZ OTW1am1lqAHeX6neiiVMqd+fAggH4nneYSeyixeeepBBFQT1Lo2bdRP6bt805l/ybpy9KTBafHQ pUpD+AiEYDY47V9mrqIZMA5w+6LUnGRofTee9USykWFvBSoiDgmGBVGr5BOlBGU5//WLGwBJynm 6xPwyF7a3Ddsdx3C4TfINU5F+RTSQNbo0VFo3Shbyga+7ed7gdpvT1Zg4kLW4APbiUP4W29aJgH vCErCAhedkfri+EqAXpkS43vmJh6NpvcTqWG5sVykMWLsLWyE+VE2ZMPFrnsK8altFHLz+xyWiS SugzEwSSl0U72hupG9o9xho0Zvpsctu5qIVQkiWIgHU34Px81zU70I6be+JGAT26Op9zbPdfRUU lTrymVN5S1A6X3G1TvUcKQiqf4NKpsxeVuoQQi2OVmPz/Er5x9ByY+S7gt4ngfj5Wu517BGf7X5 0cKq53O1WZQEFxWzArw== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDAwNCBTYWx0ZWRfXyGFk/bYAhSMi pHSMQzshNH68Hpv9rDmvZ1KY/cfrOhwJ6JFlYQ9eQvhnXouGawZDFGh4MFcLeu4J4CwRPB6/qjp 66bf2QZTNVMNlwE3G4yr5jHsRJsj6CA= X-Proofpoint-GUID: DkV5BaB_XBUcUQBi9z9xoh6O_ozEEzlP 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-11-30_05,2026-11-30_01,2025-10-01_01 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 --- 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