From nobody Sat Feb 7 06:21:45 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 B3AC536337B; Wed, 29 Oct 2025 12:25:42 +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=1761740742; cv=none; b=aSyRHiD78MI6RLio3oD4IyV7xzHiinMf6cU4PnWXe7C3BT3SJLoncFmXv9IeQ5OMZF/8KKtBQT2xv4m/pI2vKZqFJ/T+fz27ko4FP3WKWtkCgXnqycgBM/aHCRmQz0ZMAay+fNloLYLm6v1SHh7HHHBxi+cCfhxKF1p5qU2y8uk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761740742; c=relaxed/simple; bh=m+pfjG9qzc5y9QbnPIMpZwGVfopUom8AcMnRPDQcZaU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KOSTrCOUnZpyxPW4tdOuYrlYvDU4O1woER/JrNA0OHJkS3CU4JeIzVolTldFZwPE7JcjIQVnl4Z68ESsm9mYxOEVtdMkXnttP+Hj4/Rd2sIRWiZqKSiPlOtFwCesK2TgBY09jdU4PHr8phzqdGTJes9j5D3Pg84Ld+Qgbm5RU+c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iOgTSrqz; 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="iOgTSrqz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12AACC4CEF7; Wed, 29 Oct 2025 12:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1761740742; bh=m+pfjG9qzc5y9QbnPIMpZwGVfopUom8AcMnRPDQcZaU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=iOgTSrqz7/qOSk+tcKgcnXQ20nFBnVlZ9MDWFvdtXDs3elcqIwyCPzxGHYDmUOl87 oc1DbAZfyzsAp/8IUMCQv2T09/Op7KRFBBFu4ESzkhTIfRcc6O72JqEEF0sEIbo9Y5 +8g78hhDrimEFi6GuAnJvXGZJjIL8O8hE7UbsmSrWkitXCUMGjHF0xsGzEtFyTz+/+ ebb2/AmVR65TlpgeFmEttPhFVB00uVsbMiXpvYKzcqQ0FsqFMyxgQZtyHw6MqVfFgl iskqyvQIgHTSR/kA8k+f/wjcP669KXzrRV5dusiHPYZCcKNoJCB1/DbWG0C6Pg5SDd cCGN6zPbp8lnA== From: Christian Brauner Date: Wed, 29 Oct 2025 13:21:13 +0100 Subject: [PATCH v4 60/72] selftests/namespaces: sixth inactive namespace resurrection test 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: <20251029-work-namespace-nstree-listns-v4-60-2e6f823ebdc0@kernel.org> References: <20251029-work-namespace-nstree-listns-v4-0-2e6f823ebdc0@kernel.org> In-Reply-To: <20251029-work-namespace-nstree-listns-v4-0-2e6f823ebdc0@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=2328; i=brauner@kernel.org; h=from:subject:message-id; bh=m+pfjG9qzc5y9QbnPIMpZwGVfopUom8AcMnRPDQcZaU=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWQysfWHHwn/tEnhvbVdc9nU27XX+Zm6pAKC067oCf/+4 HnQI3xFRykLgxgXg6yYIotDu0m43HKeis1GmRowc1iZQIYwcHEKwETKtRkZds1rU9Vrmq5qfSJV SsC5uvaA1ysh+dg5O4KzuRilWBueMvwVD/trurSJ88nqQ1zGN68FPo400/Dg3tFc7rntHWPgs1J OAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Test multiple sockets keep the same network namespace active. Create multiple sockets, verify closing some doesn't affect others. Signed-off-by: Christian Brauner --- .../testing/selftests/namespaces/siocgskns_test.c | 68 ++++++++++++++++++= ++++ 1 file changed, 68 insertions(+) diff --git a/tools/testing/selftests/namespaces/siocgskns_test.c b/tools/te= sting/selftests/namespaces/siocgskns_test.c index bbfef3c51ac1..231830daf5dc 100644 --- a/tools/testing/selftests/namespaces/siocgskns_test.c +++ b/tools/testing/selftests/namespaces/siocgskns_test.c @@ -333,4 +333,72 @@ TEST(siocgskns_non_socket) close(pipefd[1]); } =20 +/* + * Test multiple sockets keep the same network namespace active. + * Create multiple sockets, verify closing some doesn't affect others. + */ +TEST(siocgskns_multiple_sockets) +{ + int socks[5]; + int netns_fds[5]; + int i; + struct stat st; + ino_t netns_ino; + + /* Create new network namespace */ + ASSERT_EQ(unshare(CLONE_NEWNET), 0); + + /* Create multiple sockets */ + for (i =3D 0; i < 5; i++) { + socks[i] =3D socket(AF_INET, SOCK_STREAM, 0); + ASSERT_GE(socks[i], 0); + } + + /* Get netns from all sockets */ + for (i =3D 0; i < 5; i++) { + netns_fds[i] =3D ioctl(socks[i], SIOCGSKNS); + if (netns_fds[i] < 0) { + int j; + for (j =3D 0; j <=3D i; j++) { + close(socks[j]); + if (j < i && netns_fds[j] >=3D 0) + close(netns_fds[j]); + } + if (errno =3D=3D ENOTTY || errno =3D=3D EINVAL) + SKIP(return, "SIOCGSKNS not supported"); + ASSERT_GE(netns_fds[i], 0); + } + } + + /* Verify all point to same netns */ + ASSERT_EQ(fstat(netns_fds[0], &st), 0); + netns_ino =3D st.st_ino; + + for (i =3D 1; i < 5; i++) { + ASSERT_EQ(fstat(netns_fds[i], &st), 0); + ASSERT_EQ(st.st_ino, netns_ino); + } + + /* Close some sockets */ + for (i =3D 0; i < 3; i++) { + close(socks[i]); + } + + /* Remaining netns FDs should still be valid */ + for (i =3D 3; i < 5; i++) { + char path[64]; + snprintf(path, sizeof(path), "/proc/self/fd/%d", netns_fds[i]); + int test_fd =3D open(path, O_RDONLY); + ASSERT_GE(test_fd, 0); + close(test_fd); + } + + /* Cleanup */ + for (i =3D 0; i < 5; i++) { + if (i >=3D 3) + close(socks[i]); + close(netns_fds[i]); + } +} + TEST_HARNESS_MAIN --=20 2.47.3