Skip to content

Commit a17c60e

Browse files
committed
samples/landlock: Don't error out if a file path cannot be opened
Instead of creating a hard error and aborting the sandbox creation, accept file path not usable in the LL_FS_RO and LL_FS_RW environment variables but only print a warning. This makes it easier to test, for instance with LL_FS_RO="${PATH}:/usr/lib:/lib" Print that we are going to execute the command in the sandbox before doing so. Rename "launch" to "execute", and improve header description. Reviewed-by: Günther Noack <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mic: Improve header description as suggested by Günther] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 63817fe commit a17c60e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

samples/landlock/sandboxer.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
/*
3-
* Simple Landlock sandbox manager able to launch a process restricted by a
4-
* user-defined filesystem access control policy.
3+
* Simple Landlock sandbox manager able to execute a process restricted by
4+
* user-defined file system and network access control policies.
55
*
66
* Copyright © 2017-2020 Mickaël Salaün <[email protected]>
77
* Copyright © 2020 ANSSI
@@ -120,9 +120,11 @@ static int populate_ruleset_fs(const char *const env_var, const int ruleset_fd,
120120
if (path_beneath.parent_fd < 0) {
121121
fprintf(stderr, "Failed to open \"%s\": %s\n",
122122
path_list[i], strerror(errno));
123-
goto out_free_name;
123+
continue;
124124
}
125125
if (fstat(path_beneath.parent_fd, &statbuf)) {
126+
fprintf(stderr, "Failed to stat \"%s\": %s\n",
127+
path_list[i], strerror(errno));
126128
close(path_beneath.parent_fd);
127129
goto out_free_name;
128130
}
@@ -227,7 +229,7 @@ int main(const int argc, char *const argv[], char *const *const envp)
227229
ENV_FS_RO_NAME, ENV_FS_RW_NAME, ENV_TCP_BIND_NAME,
228230
ENV_TCP_CONNECT_NAME, argv[0]);
229231
fprintf(stderr,
230-
"Launch a command in a restricted environment.\n\n");
232+
"Execute a command in a restricted environment.\n\n");
231233
fprintf(stderr,
232234
"Environment variables containing paths and ports "
233235
"each separated by a colon:\n");
@@ -248,7 +250,7 @@ int main(const int argc, char *const argv[], char *const *const envp)
248250
ENV_TCP_CONNECT_NAME);
249251
fprintf(stderr,
250252
"\nexample:\n"
251-
"%s=\"/bin:/lib:/usr:/proc:/etc:/dev/urandom\" "
253+
"%s=\"${PATH}:/lib:/usr:/proc:/etc:/dev/urandom\" "
252254
"%s=\"/dev/null:/dev/full:/dev/zero:/dev/pts:/tmp\" "
253255
"%s=\"9418\" "
254256
"%s=\"80:443\" "
@@ -383,6 +385,7 @@ int main(const int argc, char *const argv[], char *const *const envp)
383385

384386
cmd_path = argv[1];
385387
cmd_argv = argv + 1;
388+
fprintf(stderr, "Executing the sandboxed command...\n");
386389
execvpe(cmd_path, cmd_argv, envp);
387390
fprintf(stderr, "Failed to execute \"%s\": %s\n", cmd_path,
388391
strerror(errno));

0 commit comments

Comments
 (0)