Message ID | 20250407-work-anon_inode-v1-9-53a44c20d44e@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | fs: harden anon inodes | expand |
On Mon 07-04-25 11:54:23, Christian Brauner wrote: > Test that anonymous inodes cannot be open()ed. > > Signed-off-by: Christian Brauner <brauner@kernel.org> Looks good. Feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> Honza > --- > tools/testing/selftests/filesystems/anon_inode_test.c | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/tools/testing/selftests/filesystems/anon_inode_test.c b/tools/testing/selftests/filesystems/anon_inode_test.c > index 486496252ddd..e8e0ef1460d2 100644 > --- a/tools/testing/selftests/filesystems/anon_inode_test.c > +++ b/tools/testing/selftests/filesystems/anon_inode_test.c > @@ -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 > > > -- > 2.47.2 >
diff --git a/tools/testing/selftests/filesystems/anon_inode_test.c b/tools/testing/selftests/filesystems/anon_inode_test.c index 486496252ddd..e8e0ef1460d2 100644 --- a/tools/testing/selftests/filesystems/anon_inode_test.c +++ b/tools/testing/selftests/filesystems/anon_inode_test.c @@ -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
Test that anonymous inodes cannot be open()ed. Signed-off-by: Christian Brauner <brauner@kernel.org> --- tools/testing/selftests/filesystems/anon_inode_test.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)