]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/namespaces: fifth inactive namespace resurrection test
authorChristian Brauner <brauner@kernel.org>
Wed, 29 Oct 2025 12:21:12 +0000 (13:21 +0100)
committerChristian Brauner <brauner@kernel.org>
Mon, 3 Nov 2025 16:41:23 +0000 (17:41 +0100)
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 <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
tools/testing/selftests/namespaces/siocgskns_test.c

index 28e45954c4fac764f06ba96d7be4e8bf83111371..bbfef3c51ac1f870739f62a8549bfc8e93e5df90 100644 (file)
@@ -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