]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/filesystems: add open() test for anonymous inodes
authorChristian Brauner <brauner@kernel.org>
Mon, 7 Apr 2025 09:54:23 +0000 (11:54 +0200)
committerChristian Brauner <brauner@kernel.org>
Mon, 7 Apr 2025 14:20:15 +0000 (16:20 +0200)
Test that anonymous inodes cannot be open()ed.

Link: https://lore.kernel.org/20250407-work-anon_inode-v1-9-53a44c20d44e@kernel.org
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
tools/testing/selftests/filesystems/anon_inode_test.c

index 486496252ddd26fef820985eb06d1990625503b7..e8e0ef1460d279cbed0364e4b1b5e752225691a5 100644 (file)
@@ -48,5 +48,22 @@ TEST(anon_inode_no_exec)
        EXPECT_EQ(close(fd_context), 0);
 }
 
+TEST(anon_inode_no_open)
+{
+       int fd_context;
+
+       fd_context = sys_fsopen("tmpfs", 0);
+       ASSERT_GE(fd_context, 0);
+
+       ASSERT_GE(dup2(fd_context, 500), 0);
+       ASSERT_EQ(close(fd_context), 0);
+       fd_context = 500;
+
+       ASSERT_LT(open("/proc/self/fd/500", 0), 0);
+       ASSERT_EQ(errno, ENXIO);
+
+       EXPECT_EQ(close(fd_context), 0);
+}
+
 TEST_HARNESS_MAIN