Skip to content

Commit 56ffd37

Browse files
gnoackl0kod
authored andcommitted
selftests/landlock: Test IOCTLs on named pipes
Named pipes should behave like pipes created with pipe(2), so we don't want to restrict IOCTLs on them. Suggested-by: Mickaël Salaün <[email protected]> Signed-off-by: Günther Noack <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 7954a1d commit 56ffd37

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tools/testing/selftests/landlock/fs_test.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,6 +3942,49 @@ TEST_F_FORK(layout1, o_path_ftruncate_and_ioctl)
39423942
ASSERT_EQ(0, close(fd));
39433943
}
39443944

3945+
/*
3946+
* Named pipes are not governed by the LANDLOCK_ACCESS_FS_IOCTL_DEV right,
3947+
* because they are not character or block devices.
3948+
*/
3949+
TEST_F_FORK(layout1, named_pipe_ioctl)
3950+
{
3951+
pid_t child_pid;
3952+
int fd, ruleset_fd;
3953+
const char *const path = file1_s1d1;
3954+
const struct landlock_ruleset_attr attr = {
3955+
.handled_access_fs = LANDLOCK_ACCESS_FS_IOCTL_DEV,
3956+
};
3957+
3958+
ASSERT_EQ(0, unlink(path));
3959+
ASSERT_EQ(0, mkfifo(path, 0600));
3960+
3961+
/* Enables Landlock. */
3962+
ruleset_fd = landlock_create_ruleset(&attr, sizeof(attr), 0);
3963+
ASSERT_LE(0, ruleset_fd);
3964+
enforce_ruleset(_metadata, ruleset_fd);
3965+
ASSERT_EQ(0, close(ruleset_fd));
3966+
3967+
/* The child process opens the pipe for writing. */
3968+
child_pid = fork();
3969+
ASSERT_NE(-1, child_pid);
3970+
if (child_pid == 0) {
3971+
fd = open(path, O_WRONLY);
3972+
close(fd);
3973+
exit(0);
3974+
}
3975+
3976+
fd = open(path, O_RDONLY);
3977+
ASSERT_LE(0, fd);
3978+
3979+
/* FIONREAD is implemented by pipefifo_fops. */
3980+
EXPECT_EQ(0, test_fionread_ioctl(fd));
3981+
3982+
ASSERT_EQ(0, close(fd));
3983+
ASSERT_EQ(0, unlink(path));
3984+
3985+
ASSERT_EQ(child_pid, waitpid(child_pid, NULL, 0));
3986+
}
3987+
39453988
/* clang-format off */
39463989
FIXTURE(ioctl) {};
39473990

0 commit comments

Comments
 (0)