|
20 | 20 | #include <sys/mount.h>
|
21 | 21 | #include <sys/prctl.h>
|
22 | 22 | #include <sys/sendfile.h>
|
| 23 | +#include <sys/socket.h> |
23 | 24 | #include <sys/stat.h>
|
24 | 25 | #include <sys/sysmacros.h>
|
| 26 | +#include <sys/un.h> |
25 | 27 | #include <sys/vfs.h>
|
26 | 28 | #include <unistd.h>
|
27 | 29 |
|
@@ -3978,6 +3980,55 @@ TEST_F_FORK(layout1, named_pipe_ioctl)
|
3978 | 3980 | ASSERT_EQ(child_pid, waitpid(child_pid, NULL, 0));
|
3979 | 3981 | }
|
3980 | 3982 |
|
| 3983 | +/* For named UNIX domain sockets, no IOCTL restrictions apply. */ |
| 3984 | +TEST_F_FORK(layout1, named_unix_domain_socket_ioctl) |
| 3985 | +{ |
| 3986 | + const char *const path = file1_s1d1; |
| 3987 | + int srv_fd, cli_fd, ruleset_fd; |
| 3988 | + socklen_t size; |
| 3989 | + struct sockaddr_un srv_un, cli_un; |
| 3990 | + const struct landlock_ruleset_attr attr = { |
| 3991 | + .handled_access_fs = LANDLOCK_ACCESS_FS_IOCTL_DEV, |
| 3992 | + }; |
| 3993 | + |
| 3994 | + /* Sets up a server */ |
| 3995 | + srv_un.sun_family = AF_UNIX; |
| 3996 | + strncpy(srv_un.sun_path, path, sizeof(srv_un.sun_path)); |
| 3997 | + |
| 3998 | + ASSERT_EQ(0, unlink(path)); |
| 3999 | + ASSERT_LE(0, (srv_fd = socket(AF_UNIX, SOCK_STREAM, 0))); |
| 4000 | + |
| 4001 | + size = offsetof(struct sockaddr_un, sun_path) + strlen(srv_un.sun_path); |
| 4002 | + ASSERT_EQ(0, bind(srv_fd, (struct sockaddr *)&srv_un, size)); |
| 4003 | + ASSERT_EQ(0, listen(srv_fd, 10 /* qlen */)); |
| 4004 | + |
| 4005 | + /* Enables Landlock. */ |
| 4006 | + ruleset_fd = landlock_create_ruleset(&attr, sizeof(attr), 0); |
| 4007 | + ASSERT_LE(0, ruleset_fd); |
| 4008 | + enforce_ruleset(_metadata, ruleset_fd); |
| 4009 | + ASSERT_EQ(0, close(ruleset_fd)); |
| 4010 | + |
| 4011 | + /* Sets up a client connection to it */ |
| 4012 | + cli_un.sun_family = AF_UNIX; |
| 4013 | + |
| 4014 | + ASSERT_LE(0, (cli_fd = socket(AF_UNIX, SOCK_STREAM, 0))); |
| 4015 | + |
| 4016 | + size = offsetof(struct sockaddr_un, sun_path) + strlen(cli_un.sun_path); |
| 4017 | + ASSERT_EQ(0, bind(cli_fd, (struct sockaddr *)&cli_un, size)); |
| 4018 | + |
| 4019 | + bzero(&cli_un, sizeof(cli_un)); |
| 4020 | + cli_un.sun_family = AF_UNIX; |
| 4021 | + strncpy(cli_un.sun_path, path, sizeof(cli_un.sun_path)); |
| 4022 | + size = offsetof(struct sockaddr_un, sun_path) + strlen(cli_un.sun_path); |
| 4023 | + |
| 4024 | + ASSERT_EQ(0, connect(cli_fd, (struct sockaddr *)&cli_un, size)); |
| 4025 | + |
| 4026 | + /* FIONREAD and other IOCTLs should not be forbidden. */ |
| 4027 | + EXPECT_EQ(0, test_fionread_ioctl(cli_fd)); |
| 4028 | + |
| 4029 | + ASSERT_EQ(0, close(cli_fd)); |
| 4030 | +} |
| 4031 | + |
3981 | 4032 | /* clang-format off */
|
3982 | 4033 | FIXTURE(ioctl) {};
|
3983 | 4034 |
|
|
0 commit comments