Skip to content

Commit 25a6cc9

Browse files
committed
selftests/filesystems: add open() test for anonymous inodes
Test that anonymous inodes cannot be open()ed. Link: https://lore.kernel.org/[email protected] Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent f8ca403 commit 25a6cc9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tools/testing/selftests/filesystems/anon_inode_test.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,22 @@ TEST(anon_inode_no_exec)
4848
EXPECT_EQ(close(fd_context), 0);
4949
}
5050

51+
TEST(anon_inode_no_open)
52+
{
53+
int fd_context;
54+
55+
fd_context = sys_fsopen("tmpfs", 0);
56+
ASSERT_GE(fd_context, 0);
57+
58+
ASSERT_GE(dup2(fd_context, 500), 0);
59+
ASSERT_EQ(close(fd_context), 0);
60+
fd_context = 500;
61+
62+
ASSERT_LT(open("/proc/self/fd/500", 0), 0);
63+
ASSERT_EQ(errno, ENXIO);
64+
65+
EXPECT_EQ(close(fd_context), 0);
66+
}
67+
5168
TEST_HARNESS_MAIN
5269

0 commit comments

Comments
 (0)