Skip to content

Commit cd13738

Browse files
gnoackl0kod
authored andcommitted
samples/landlock: Add support for LANDLOCK_ACCESS_FS_IOCTL_DEV
Add IOCTL support to the Landlock sample tool. The IOCTL right is grouped with the read-write rights in the sample tool, as some IOCTL requests provide features that mutate state. Signed-off-by: Günther Noack <gnoack@google.com> Link: https://lore.kernel.org/r/20240419161122.2023765-9-gnoack@google.com Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent bce605e commit cd13738

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

samples/landlock/sandboxer.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ static int parse_path(char *env_path, const char ***const path_list)
8181
LANDLOCK_ACCESS_FS_EXECUTE | \
8282
LANDLOCK_ACCESS_FS_WRITE_FILE | \
8383
LANDLOCK_ACCESS_FS_READ_FILE | \
84-
LANDLOCK_ACCESS_FS_TRUNCATE)
84+
LANDLOCK_ACCESS_FS_TRUNCATE | \
85+
LANDLOCK_ACCESS_FS_IOCTL_DEV)
8586

8687
/* clang-format on */
8788

@@ -202,11 +203,12 @@ static int populate_ruleset_net(const char *const env_var, const int ruleset_fd,
202203
LANDLOCK_ACCESS_FS_MAKE_BLOCK | \
203204
LANDLOCK_ACCESS_FS_MAKE_SYM | \
204205
LANDLOCK_ACCESS_FS_REFER | \
205-
LANDLOCK_ACCESS_FS_TRUNCATE)
206+
LANDLOCK_ACCESS_FS_TRUNCATE | \
207+
LANDLOCK_ACCESS_FS_IOCTL_DEV)
206208

207209
/* clang-format on */
208210

209-
#define LANDLOCK_ABI_LAST 4
211+
#define LANDLOCK_ABI_LAST 5
210212

211213
int main(const int argc, char *const argv[], char *const *const envp)
212214
{
@@ -320,6 +322,11 @@ int main(const int argc, char *const argv[], char *const *const envp)
320322
ruleset_attr.handled_access_net &=
321323
~(LANDLOCK_ACCESS_NET_BIND_TCP |
322324
LANDLOCK_ACCESS_NET_CONNECT_TCP);
325+
__attribute__((fallthrough));
326+
case 4:
327+
/* Removes LANDLOCK_ACCESS_FS_IOCTL_DEV for ABI < 5 */
328+
ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_IOCTL_DEV;
329+
323330
fprintf(stderr,
324331
"Hint: You should update the running kernel "
325332
"to leverage Landlock features "

0 commit comments

Comments
 (0)