Message ID | 20230623144329.136541-5-gnoack@google.com (mailing list archive) |
---|---|
State | Handled Elsewhere |
Headers | show |
Series | Landlock: ioctl support | expand |
On 23/06/2023 16:43, Günther Noack wrote: > Because the ioctl right is associated with the opened file, > we expect that it will work with files which are opened by means > other than open(2). > > Signed-off-by: Günther Noack <gnoack@google.com> > --- > tools/testing/selftests/landlock/fs_test.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c > index 0f0899768fe7..ebd93e895775 100644 > --- a/tools/testing/selftests/landlock/fs_test.c > +++ b/tools/testing/selftests/landlock/fs_test.c > @@ -3716,18 +3716,20 @@ TEST_F_FORK(ftruncate, open_and_ftruncate_in_different_processes) > ASSERT_EQ(0, close(socket_fds[1])); > } > > -TEST(memfd_ftruncate) > +TEST(memfd_ftruncate_and_ioctl) You could create memfd fixture/teardown with TEST_F(memfd, ftruncate) and TEST_F(memfd, ioctl) to cleanly differentiate these tests. > { > - int fd; > + int fd, n; > > fd = memfd_create("name", MFD_CLOEXEC); > ASSERT_LE(0, fd); > > /* > - * Checks that ftruncate is permitted on file descriptors that are > - * created in ways other than open(2). > + * Checks that operations associated with the opened file > + * (ftruncate, ioctl) are permitted on file descriptors that > + * are created in ways other than open(2). > */ > EXPECT_EQ(0, test_ftruncate(fd)); I previously missed it but this test should check ftruncate with and without FS sandboxing to be sure that the resulting behavior is the same. Ditto for the IOCTL test. > + EXPECT_EQ(0, ioctl(fd, FIONREAD, &n)); > > ASSERT_EQ(0, close(fd)); EXPECT_EQ() for close() should be enough right? > }
diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c index 0f0899768fe7..ebd93e895775 100644 --- a/tools/testing/selftests/landlock/fs_test.c +++ b/tools/testing/selftests/landlock/fs_test.c @@ -3716,18 +3716,20 @@ TEST_F_FORK(ftruncate, open_and_ftruncate_in_different_processes) ASSERT_EQ(0, close(socket_fds[1])); } -TEST(memfd_ftruncate) +TEST(memfd_ftruncate_and_ioctl) { - int fd; + int fd, n; fd = memfd_create("name", MFD_CLOEXEC); ASSERT_LE(0, fd); /* - * Checks that ftruncate is permitted on file descriptors that are - * created in ways other than open(2). + * Checks that operations associated with the opened file + * (ftruncate, ioctl) are permitted on file descriptors that + * are created in ways other than open(2). */ EXPECT_EQ(0, test_ftruncate(fd)); + EXPECT_EQ(0, ioctl(fd, FIONREAD, &n)); ASSERT_EQ(0, close(fd)); }
Because the ioctl right is associated with the opened file, we expect that it will work with files which are opened by means other than open(2). Signed-off-by: Günther Noack <gnoack@google.com> --- tools/testing/selftests/landlock/fs_test.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)