From nobody Mon Feb 9 17:23:14 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3598368F52; Wed, 22 Oct 2025 16:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761149342; cv=none; b=tebqyiKUSEDYAsAaQp93ruXgnqkq2TA2G9aaeK5PWmDGmSIaIRSbvPXd5+wilVyI8PRws2PyNTEzxmZ2Ua0ZIxyoUxrHLV3QhAsRHoRpPWLOuxBSNoSt+P9oXwlwpHNckss0HOwyEYMLPG6rkVNCzlGPwMSPbe3/08vhAhXk2D4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761149342; c=relaxed/simple; bh=fdHj1hsijB+BXri97N5cswYO4dlb02Ygb6q9aUmDKdA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bzYlGo4S2Nv0JhiECW7nZR4FcX2ye4rOsFovE7nPIY6gx3WOqu+i2my8j2JHXjGMFPN4UplHlPgzZ2EovgONe63D4Lwvb3mDFG5tTRzKe/9xlh8LjIhyc7k4mDKciSmken21h1A6GcYKhqqCyaXQ0k5PVCiRUjgTDUW6uezFdNY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IKNbJVxO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IKNbJVxO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F27ABC113D0; Wed, 22 Oct 2025 16:08:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761149341; bh=fdHj1hsijB+BXri97N5cswYO4dlb02Ygb6q9aUmDKdA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IKNbJVxOWPHbZFlBVVwdlFPbO12K8GPtzoW+y/QvadKR9dYQNcttdp79eTyrrBrkN FNKa6tOe0de7FAjW5tVi1sCBM53Fz2Q1LwQQ9sVBS3IvQF6lTMOYyZp43iO1JLpJbR i0+el02Zzyo+D+ol/h17RCiq537uklBXTShHeRKesakTmaRJpuru/+bCWvGbtecGsi ry0B76HfjUi7+jiLgPyEIqG0ojzmCyp67CRf76wAhUHeo99hYBQLjW8EtpIS0P22xt gyU8+TT300/udIPp5/+f1IQ8hRjQ9UyEh0g+aV2vpknwgR7J/OLsxgfvunneA5Knh2 2qZ+tlzhwFHMQ== From: Christian Brauner Date: Wed, 22 Oct 2025 18:06:11 +0200 Subject: [PATCH v2 33/63] selftests/namespaces: fourteenth active reference count tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251022-work-namespace-nstree-listns-v2-33-71a588572371@kernel.org> References: <20251022-work-namespace-nstree-listns-v2-0-71a588572371@kernel.org> In-Reply-To: <20251022-work-namespace-nstree-listns-v2-0-71a588572371@kernel.org> To: linux-fsdevel@vger.kernel.org, Josef Bacik , Jeff Layton Cc: Jann Horn , Mike Yuan , =?utf-8?q?Zbigniew_J=C4=99drzejewski-Szmek?= , Lennart Poettering , Daan De Meyer , Aleksa Sarai , Amir Goldstein , Tejun Heo , Johannes Weiner , Thomas Gleixner , Alexander Viro , Jan Kara , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, bpf@vger.kernel.org, Eric Dumazet , Jakub Kicinski , netdev@vger.kernel.org, Arnd Bergmann , Christian Brauner X-Mailer: b4 0.15-dev-96507 X-Developer-Signature: v=1; a=openpgp-sha256; l=4527; i=brauner@kernel.org; h=from:subject:message-id; bh=fdHj1hsijB+BXri97N5cswYO4dlb02Ygb6q9aUmDKdA=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWT8ZHg2ue27W/vpvv06b7vUHQ7Z+tjPYjQ9rnz5Sevtn e8mcOSXd5SyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEzE8Dgjw6enjn2mqm2TfXQ6 /i0/qWvqG3Y+58NkkUO1nK3fniRuE2dkOL1IeN00FdXq0JoE3f2RdxmmeXrZW65Tm9u4dO/bzdq +PAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Test that user namespace as a child also propagates correctly. Create user_A -> user_B, verify when user_B is active that user_A is also active. This is different from non-user namespace children. Signed-off-by: Christian Brauner --- .../selftests/namespaces/ns_active_ref_test.c | 138 +++++++++++++++++= ++++ 1 file changed, 138 insertions(+) diff --git a/tools/testing/selftests/namespaces/ns_active_ref_test.c b/tool= s/testing/selftests/namespaces/ns_active_ref_test.c index 4c077223b05c..1eb4dc07e924 100644 --- a/tools/testing/selftests/namespaces/ns_active_ref_test.c +++ b/tools/testing/selftests/namespaces/ns_active_ref_test.c @@ -1914,4 +1914,142 @@ TEST(ns_parent_multiple_children_refcount) } } =20 +/* + * Test that user namespace as a child also propagates correctly. + * Create user_A -> user_B, verify when user_B is active that user_A + * is also active. This is different from non-user namespace children. + */ +TEST(ns_userns_child_propagation) +{ + struct file_handle *ua_handle, *ub_handle; + int ret, pipefd[2]; + pid_t pid; + int status; + __u64 ua_id, ub_id; + char ua_buf[sizeof(*ua_handle) + MAX_HANDLE_SZ]; + char ub_buf[sizeof(*ub_handle) + MAX_HANDLE_SZ]; + + ASSERT_EQ(pipe(pipefd), 0); + pid =3D fork(); + ASSERT_GE(pid, 0); + + if (pid =3D=3D 0) { + close(pipefd[0]); + + /* Create user_A */ + if (setup_userns() < 0) { + close(pipefd[1]); + exit(1); + } + + int ua_fd =3D open("/proc/self/ns/user", O_RDONLY); + if (ua_fd < 0) { + close(pipefd[1]); + exit(1); + } + if (ioctl(ua_fd, NS_GET_ID, &ua_id) < 0) { + close(ua_fd); + close(pipefd[1]); + exit(1); + } + close(ua_fd); + + /* Create user_B (child of user_A) */ + if (setup_userns() < 0) { + close(pipefd[1]); + exit(1); + } + + int ub_fd =3D open("/proc/self/ns/user", O_RDONLY); + if (ub_fd < 0) { + close(pipefd[1]); + exit(1); + } + if (ioctl(ub_fd, NS_GET_ID, &ub_id) < 0) { + close(ub_fd); + close(pipefd[1]); + exit(1); + } + close(ub_fd); + + /* Send both namespace IDs */ + write(pipefd[1], &ua_id, sizeof(ua_id)); + write(pipefd[1], &ub_id, sizeof(ub_id)); + close(pipefd[1]); + exit(0); + } + + close(pipefd[1]); + + /* Read both namespace IDs - fixed size, no parsing needed */ + ret =3D read(pipefd[0], &ua_id, sizeof(ua_id)); + if (ret !=3D sizeof(ua_id)) { + close(pipefd[0]); + waitpid(pid, NULL, 0); + SKIP(return, "Failed to read user_A namespace ID"); + } + + ret =3D read(pipefd[0], &ub_id, sizeof(ub_id)); + close(pipefd[0]); + if (ret !=3D sizeof(ub_id)) { + waitpid(pid, NULL, 0); + SKIP(return, "Failed to read user_B namespace ID"); + } + + /* Construct file handles from namespace IDs */ + ua_handle =3D (struct file_handle *)ua_buf; + ua_handle->handle_bytes =3D sizeof(struct nsfs_file_handle); + ua_handle->handle_type =3D FILEID_NSFS; + struct nsfs_file_handle *ua_fh =3D (struct nsfs_file_handle *)ua_handle->= f_handle; + ua_fh->ns_id =3D ua_id; + ua_fh->ns_type =3D 0; + ua_fh->ns_inum =3D 0; + + ub_handle =3D (struct file_handle *)ub_buf; + ub_handle->handle_bytes =3D sizeof(struct nsfs_file_handle); + ub_handle->handle_type =3D FILEID_NSFS; + struct nsfs_file_handle *ub_fh =3D (struct nsfs_file_handle *)ub_handle->= f_handle; + ub_fh->ns_id =3D ub_id; + ub_fh->ns_type =3D 0; + ub_fh->ns_inum =3D 0; + + /* Open user_B before child exits */ + int ub_fd =3D open_by_handle_at(FD_NSFS_ROOT, ub_handle, O_RDONLY); + if (ub_fd < 0) { + waitpid(pid, NULL, 0); + SKIP(return, "Failed to open user_B"); + } + + waitpid(pid, &status, 0); + ASSERT_TRUE(WIFEXITED(status)); + if (WEXITSTATUS(status) !=3D 0) { + close(ub_fd); + SKIP(return, "Child failed"); + } + + /* With user_B active, user_A should also be active */ + TH_LOG("Testing user_A active when child user_B is active"); + int ua_fd =3D open_by_handle_at(FD_NSFS_ROOT, ua_handle, O_RDONLY); + ASSERT_GE(ua_fd, 0); + + /* Close user_B */ + TH_LOG("Closing user_B"); + close(ub_fd); + + /* user_A should remain active (we hold direct ref) */ + int ua_fd2 =3D open_by_handle_at(FD_NSFS_ROOT, ua_handle, O_RDONLY); + ASSERT_GE(ua_fd2, 0); + close(ua_fd2); + + /* Close user_A - should become inactive */ + TH_LOG("Closing user_A - should become inactive"); + close(ua_fd); + + ua_fd =3D open_by_handle_at(FD_NSFS_ROOT, ua_handle, O_RDONLY); + if (ua_fd >=3D 0) { + close(ua_fd); + TH_LOG("Warning: user_A still active"); + } +} + TEST_HARNESS_MAIN --=20 2.47.3