From 2b9fa5bf0c417c444d3c572dfe2138da7fdf11cd Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Wed, 29 Oct 2025 13:21:12 +0100 Subject: [PATCH] selftests/namespaces: fifth inactive namespace resurrection test Test SIOCGSKNS fails on non-socket file descriptors. Link: https://patch.msgid.link/20251029-work-namespace-nstree-listns-v4-59-2e6f823ebdc0@kernel.org Tested-by: syzbot@syzkaller.appspotmail.com Reviewed-by: Jeff Layton Signed-off-by: Christian Brauner --- .../selftests/namespaces/siocgskns_test.c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/testing/selftests/namespaces/siocgskns_test.c b/tools/testing/selftests/namespaces/siocgskns_test.c index 28e45954c4fac..bbfef3c51ac1f 100644 --- a/tools/testing/selftests/namespaces/siocgskns_test.c +++ b/tools/testing/selftests/namespaces/siocgskns_test.c @@ -307,4 +307,30 @@ TEST(siocgskns_across_setns) close(netns_a_fd); } +/* + * Test SIOCGSKNS fails on non-socket file descriptors. + */ +TEST(siocgskns_non_socket) +{ + int fd; + int pipefd[2]; + + /* Test on regular file */ + fd = open("/dev/null", O_RDONLY); + ASSERT_GE(fd, 0); + + ASSERT_LT(ioctl(fd, SIOCGSKNS), 0); + ASSERT_TRUE(errno == ENOTTY || errno == EINVAL); + close(fd); + + /* Test on pipe */ + ASSERT_EQ(pipe(pipefd), 0); + + ASSERT_LT(ioctl(pipefd[0], SIOCGSKNS), 0); + ASSERT_TRUE(errno == ENOTTY || errno == EINVAL); + + close(pipefd[0]); + close(pipefd[1]); +} + TEST_HARNESS_MAIN -- 2.47.3