diff options
-rw-r--r-- | config.mk.in | 3 | ||||
-rwxr-xr-x | configure | 16 | ||||
-rw-r--r-- | configure.ac | 10 | ||||
-rw-r--r-- | contrib/vim/syntax/firejail.vim | 2 | ||||
-rw-r--r-- | src/bash_completion/firejail.bash_completion.in | 16 | ||||
-rw-r--r-- | src/firejail/firejail.h | 26 | ||||
-rw-r--r-- | src/firejail/landlock.c | 79 | ||||
-rw-r--r-- | src/firejail/main.c | 81 | ||||
-rw-r--r-- | src/firejail/profile.c | 84 | ||||
-rw-r--r-- | src/firejail/sandbox.c | 27 | ||||
-rw-r--r-- | src/firejail/usage.c | 6 | ||||
-rw-r--r-- | src/firejail/util.c | 4 | ||||
-rw-r--r-- | src/man/firejail-profile.txt | 29 | ||||
-rw-r--r-- | src/man/firejail.txt | 63 | ||||
-rw-r--r-- | src/zsh_completion/_firejail.in | 6 |
15 files changed, 447 insertions, 5 deletions
diff --git a/config.mk.in b/config.mk.in index 9973b7eaa..150ac8e15 100644 --- a/config.mk.in +++ b/config.mk.in | |||
@@ -41,6 +41,7 @@ HAVE_PRIVATE_HOME=@HAVE_PRIVATE_HOME@ | |||
41 | HAVE_IDS=@HAVE_IDS@ | 41 | HAVE_IDS=@HAVE_IDS@ |
42 | HAVE_GCOV=@HAVE_GCOV@ | 42 | HAVE_GCOV=@HAVE_GCOV@ |
43 | HAVE_SELINUX=@HAVE_SELINUX@ | 43 | HAVE_SELINUX=@HAVE_SELINUX@ |
44 | HAVE_LANDLOCK=@HAVE_LANDLOCK@ | ||
44 | HAVE_SUID=@HAVE_SUID@ | 45 | HAVE_SUID=@HAVE_SUID@ |
45 | HAVE_DBUSPROXY=@HAVE_DBUSPROXY@ | 46 | HAVE_DBUSPROXY=@HAVE_DBUSPROXY@ |
46 | HAVE_USERTMPFS=@HAVE_USERTMPFS@ | 47 | HAVE_USERTMPFS=@HAVE_USERTMPFS@ |
@@ -49,7 +50,7 @@ HAVE_LTS=@HAVE_LTS@ | |||
49 | HAVE_FORCE_NONEWPRIVS=@HAVE_FORCE_NONEWPRIVS@ | 50 | HAVE_FORCE_NONEWPRIVS=@HAVE_FORCE_NONEWPRIVS@ |
50 | HAVE_ONLY_SYSCFG_PROFILES=@HAVE_ONLY_SYSCFG_PROFILES@ | 51 | HAVE_ONLY_SYSCFG_PROFILES=@HAVE_ONLY_SYSCFG_PROFILES@ |
51 | 52 | ||
52 | MANFLAGS = $(HAVE_LTS) $(HAVE_OUTPUT) $(HAVE_X11) $(HAVE_PRIVATE_HOME) $(HAVE_APPARMOR) $(HAVE_IDS) $(HAVE_OVERLAYFS) $(HAVE_USERTMPFS) $(HAVE_DBUSPROXY) $(HAVE_FIRETUNNEL) $(HAVE_GLOBALCFG) $(HAVE_CHROOT) $(HAVE_NETWORK) $(HAVE_USERNS) $(HAVE_FILE_TRANSFER) $(HAVE_SELINUX) $(HAVE_SUID) $(HAVE_FORCE_NONEWPRIVS) $(HAVE_ONLY_SYSCFG_PROFILES) | 53 | MANFLAGS = $(HAVE_LTS) $(HAVE_OUTPUT) $(HAVE_X11) $(HAVE_PRIVATE_HOME) $(HAVE_APPARMOR) $(HAVE_IDS) $(HAVE_OVERLAYFS) $(HAVE_USERTMPFS) $(HAVE_DBUSPROXY) $(HAVE_FIRETUNNEL) $(HAVE_GLOBALCFG) $(HAVE_CHROOT) $(HAVE_NETWORK) $(HAVE_USERNS) $(HAVE_FILE_TRANSFER) $(HAVE_SELINUX) $(HAVE_SUID) $(HAVE_LANDLOCK) $(HAVE_FORCE_NONEWPRIVS) $(HAVE_ONLY_SYSCFG_PROFILES) |
53 | 54 | ||
54 | CC=@CC@ | 55 | CC=@CC@ |
55 | CFLAGS=@CFLAGS@ | 56 | CFLAGS=@CFLAGS@ |
@@ -652,6 +652,7 @@ HAVE_DBUSPROXY | |||
652 | EXTRA_LDFLAGS | 652 | EXTRA_LDFLAGS |
653 | EXTRA_CFLAGS | 653 | EXTRA_CFLAGS |
654 | HAVE_SELINUX | 654 | HAVE_SELINUX |
655 | HAVE_LANDLOCK | ||
655 | AA_LIBS | 656 | AA_LIBS |
656 | AA_CFLAGS | 657 | AA_CFLAGS |
657 | PKG_CONFIG_LIBDIR | 658 | PKG_CONFIG_LIBDIR |
@@ -713,6 +714,7 @@ enable_sanitizer | |||
713 | enable_ids | 714 | enable_ids |
714 | enable_apparmor | 715 | enable_apparmor |
715 | enable_selinux | 716 | enable_selinux |
717 | enable_landlock | ||
716 | enable_dbusproxy | 718 | enable_dbusproxy |
717 | enable_output | 719 | enable_output |
718 | enable_usertmpfs | 720 | enable_usertmpfs |
@@ -1374,6 +1376,7 @@ Optional Features: | |||
1374 | --enable-ids enable ids | 1376 | --enable-ids enable ids |
1375 | --enable-apparmor enable apparmor | 1377 | --enable-apparmor enable apparmor |
1376 | --enable-selinux SELinux labeling support | 1378 | --enable-selinux SELinux labeling support |
1379 | --enable-landlock Landlock self-restriction support | ||
1377 | --disable-dbusproxy disable dbus proxy | 1380 | --disable-dbusproxy disable dbus proxy |
1378 | --disable-output disable --output logging | 1381 | --disable-output disable --output logging |
1379 | --disable-usertmpfs disable tmpfs as regular user | 1382 | --disable-usertmpfs disable tmpfs as regular user |
@@ -3342,7 +3345,19 @@ if test "x$enable_selinux" = "xyes"; then : | |||
3342 | 3345 | ||
3343 | fi | 3346 | fi |
3344 | 3347 | ||
3348 | HAVE_LANDLOCK="" | ||
3345 | 3349 | ||
3350 | # Check whether --enable-landlock was given. | ||
3351 | if test "${enable_landlock+set}" = set; then : | ||
3352 | enableval=$enable_landlock; | ||
3353 | fi | ||
3354 | |||
3355 | if test "x$enable_landlock" = "xyes"; then : | ||
3356 | |||
3357 | HAVE_LANDLOCK="-DHAVE_LANDLOCK" | ||
3358 | EXTRA_LDFLAGS="$EXTRA_LDFLAGS" | ||
3359 | |||
3360 | fi | ||
3346 | 3361 | ||
3347 | 3362 | ||
3348 | 3363 | ||
@@ -5277,6 +5292,7 @@ Features: | |||
5277 | overlayfs support: $HAVE_OVERLAYFS | 5292 | overlayfs support: $HAVE_OVERLAYFS |
5278 | private home support: $HAVE_PRIVATE_HOME | 5293 | private home support: $HAVE_PRIVATE_HOME |
5279 | SELinux labeling support: $HAVE_SELINUX | 5294 | SELinux labeling support: $HAVE_SELINUX |
5295 | Landlock self-restriction support: $HAVE_LANDLOCK | ||
5280 | user namespace: $HAVE_USERNS | 5296 | user namespace: $HAVE_USERNS |
5281 | X11 sandboxing support: $HAVE_X11 | 5297 | X11 sandboxing support: $HAVE_X11 |
5282 | 5298 | ||
diff --git a/configure.ac b/configure.ac index 8a488ff43..78681cb7a 100644 --- a/configure.ac +++ b/configure.ac | |||
@@ -81,10 +81,18 @@ AS_IF([test "x$enable_selinux" = "xyes"], [ | |||
81 | EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lselinux" | 81 | EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lselinux" |
82 | ]) | 82 | ]) |
83 | 83 | ||
84 | HAVE_LANDLOCK="" | ||
85 | AC_SUBST([HAVE_LANDLOCK]) | ||
86 | AC_ARG_ENABLE([landlock]) | ||
87 | [AS_HELP_STRING([--enable-landlock], [Landlock self-restriction support])] | ||
88 | AS_IF([test "x$enable_landlock" = "xyes"], [ | ||
89 | HAVE_LANDLOCK="-DHAVE_LANDLOCK" | ||
90 | EXTRA_LDFLAGS="$EXTRA_LDFLAGS" | ||
91 | ]) | ||
92 | |||
84 | AC_SUBST([EXTRA_CFLAGS]) | 93 | AC_SUBST([EXTRA_CFLAGS]) |
85 | AC_SUBST([EXTRA_LDFLAGS]) | 94 | AC_SUBST([EXTRA_LDFLAGS]) |
86 | 95 | ||
87 | |||
88 | HAVE_DBUSPROXY="" | 96 | HAVE_DBUSPROXY="" |
89 | AC_SUBST([HAVE_DBUSPROXY]) | 97 | AC_SUBST([HAVE_DBUSPROXY]) |
90 | AC_ARG_ENABLE([dbusproxy], | 98 | AC_ARG_ENABLE([dbusproxy], |
diff --git a/contrib/vim/syntax/firejail.vim b/contrib/vim/syntax/firejail.vim index 0c8ebdbd8..7c1c33421 100644 --- a/contrib/vim/syntax/firejail.vim +++ b/contrib/vim/syntax/firejail.vim | |||
@@ -52,7 +52,7 @@ syn match fjVar /\v\$\{(CFG|DESKTOP|DOCUMENTS|DOWNLOADS|HOME|MUSIC|PATH|PICTURES | |||
52 | 52 | ||
53 | " Commands grabbed from: src/firejail/profile.c | 53 | " Commands grabbed from: src/firejail/profile.c |
54 | " Generate list with: { rg -o 'strn?cmp\(ptr, "([^"]+) "' -r '$1' src/firejail/profile.c; echo private-lib; } | grep -vEx '(include|ignore|caps\.drop|caps\.keep|protocol|restrict-namespaces|seccomp|seccomp\.drop|seccomp\.keep|env|rmenv|net|ip)' | sort -u | tr $'\n' '|' # private-lib is special-cased in the code and doesn't match the regex; grep-ed patterns are handled later with 'syn match nextgroup=' directives (except for include which is special-cased as a fjCommandNoCond keyword) | 54 | " Generate list with: { rg -o 'strn?cmp\(ptr, "([^"]+) "' -r '$1' src/firejail/profile.c; echo private-lib; } | grep -vEx '(include|ignore|caps\.drop|caps\.keep|protocol|restrict-namespaces|seccomp|seccomp\.drop|seccomp\.keep|env|rmenv|net|ip)' | sort -u | tr $'\n' '|' # private-lib is special-cased in the code and doesn't match the regex; grep-ed patterns are handled later with 'syn match nextgroup=' directives (except for include which is special-cased as a fjCommandNoCond keyword) |
55 | syn match fjCommand /\v(apparmor|bind|blacklist|blacklist-nolog|cpu|defaultgw|dns|hostname|hosts-file|ip6|iprange|join-or-start|mac|mkdir|mkfile|mtu|name|netfilter|netfilter6|netmask|nice|noblacklist|noexec|nowhitelist|overlay-named|private|private-bin|private-cwd|private-etc|private-home|private-lib|private-opt|private-srv|read-only|read-write|rlimit-as|rlimit-cpu|rlimit-fsize|rlimit-nofile|rlimit-nproc|rlimit-sigpending|timeout|tmpfs|veth-name|whitelist|xephyr-screen) / skipwhite contained | 55 | syn match fjCommand /\v(apparmor|bind|blacklist|blacklist-nolog|cpu|defaultgw|dns|hostname|hosts-file|ip6|iprange|join-or-start|landlock|landlock.proc|landlock.read|landlock.write|landlock.special|landlock.execute|mac|mkdir|mkfile|mtu|name|netfilter|netfilter6|netmask|nice|noblacklist|noexec|nowhitelist|overlay-named|private|private-bin|private-cwd|private-etc|private-home|private-lib|private-opt|private-srv|read-only|read-write|rlimit-as|rlimit-cpu|rlimit-fsize|rlimit-nofile|rlimit-nproc|rlimit-sigpending|timeout|tmpfs|veth-name|whitelist|xephyr-screen) / skipwhite contained |
56 | " Generate list with: rg -o 'strn?cmp\(ptr, "([^ "]*[^ ])"' -r '$1' src/firejail/profile.c | grep -vEx '(include|rlimit|quiet)' | sed -e 's/\./\\./' | sort -u | tr $'\n' '|' # include/rlimit are false positives, quiet is special-cased below | 56 | " Generate list with: rg -o 'strn?cmp\(ptr, "([^ "]*[^ ])"' -r '$1' src/firejail/profile.c | grep -vEx '(include|rlimit|quiet)' | sed -e 's/\./\\./' | sort -u | tr $'\n' '|' # include/rlimit are false positives, quiet is special-cased below |
57 | syn match fjCommand /\v(allow-debuggers|allusers|apparmor|caps|deterministic-exit-code|deterministic-shutdown|disable-mnt|ipc-namespace|keep-config-pulse|keep-dev-shm|keep-fd|keep-var-tmp|machine-id|memory-deny-write-execute|netfilter|no3d|noautopulse|nodbus|nodvd|nogroups|noinput|nonewprivs|noprinters|noroot|nosound|notv|nou2f|novideo|overlay|overlay-tmpfs|private|private-cache|private-cwd|private-dev|private-lib|private-tmp|seccomp|seccomp\.32|seccomp\.block-secondary|tracelog|writable-etc|writable-run-user|writable-var|writable-var-log|x11)$/ contained | 57 | syn match fjCommand /\v(allow-debuggers|allusers|apparmor|caps|deterministic-exit-code|deterministic-shutdown|disable-mnt|ipc-namespace|keep-config-pulse|keep-dev-shm|keep-fd|keep-var-tmp|machine-id|memory-deny-write-execute|netfilter|no3d|noautopulse|nodbus|nodvd|nogroups|noinput|nonewprivs|noprinters|noroot|nosound|notv|nou2f|novideo|overlay|overlay-tmpfs|private|private-cache|private-cwd|private-dev|private-lib|private-tmp|seccomp|seccomp\.32|seccomp\.block-secondary|tracelog|writable-etc|writable-run-user|writable-var|writable-var-log|x11)$/ contained |
58 | syn match fjCommand /ignore / nextgroup=fjCommand,fjCommandNoCond skipwhite contained | 58 | syn match fjCommand /ignore / nextgroup=fjCommand,fjCommandNoCond skipwhite contained |
diff --git a/src/bash_completion/firejail.bash_completion.in b/src/bash_completion/firejail.bash_completion.in index 8e047ce90..4829f1fde 100644 --- a/src/bash_completion/firejail.bash_completion.in +++ b/src/bash_completion/firejail.bash_completion.in | |||
@@ -42,6 +42,22 @@ _firejail() | |||
42 | _filedir -d | 42 | _filedir -d |
43 | return 0 | 43 | return 0 |
44 | ;; | 44 | ;; |
45 | --landlock.read) | ||
46 | _filedir | ||
47 | return 0 | ||
48 | ;; | ||
49 | --landlock.write) | ||
50 | _filedir | ||
51 | return 0 | ||
52 | ;; | ||
53 | --landlock.special) | ||
54 | _filedir | ||
55 | return 0 | ||
56 | ;; | ||
57 | --landlock.execute) | ||
58 | _filedir | ||
59 | return 0 | ||
60 | ;; | ||
45 | --tmpfs) | 61 | --tmpfs) |
46 | _filedir | 62 | _filedir |
47 | return 0 | 63 | return 0 |
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 0a4dffb75..9c2b53c18 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -22,6 +22,9 @@ | |||
22 | #include "../include/common.h" | 22 | #include "../include/common.h" |
23 | #include "../include/euid_common.h" | 23 | #include "../include/euid_common.h" |
24 | #include "../include/rundefs.h" | 24 | #include "../include/rundefs.h" |
25 | #ifdef HAVE_LANDLOCK | ||
26 | #include <linux/landlock.h> | ||
27 | #endif | ||
25 | #include <linux/limits.h> // Note: Plain limits.h may break ARG_MAX (see #4583) | 28 | #include <linux/limits.h> // Note: Plain limits.h may break ARG_MAX (see #4583) |
26 | #include <stdarg.h> | 29 | #include <stdarg.h> |
27 | #include <sys/stat.h> | 30 | #include <sys/stat.h> |
@@ -29,7 +32,25 @@ | |||
29 | // debug restricted shell | 32 | // debug restricted shell |
30 | //#define DEBUG_RESTRICTED_SHELL | 33 | //#define DEBUG_RESTRICTED_SHELL |
31 | 34 | ||
35 | #ifdef HAVE_LANDLOCK | ||
36 | |||
37 | extern int landlock_create_ruleset(struct landlock_ruleset_attr *rsattr,size_t size,__u32 flags); | ||
38 | |||
39 | extern int landlock_add_rule(int fd,enum landlock_rule_type t,void *attr,__u32 flags); | ||
40 | |||
41 | extern int landlock_restrict_self(int fd,__u32 flags); | ||
42 | |||
43 | extern int create_full_ruleset(); | ||
44 | |||
45 | extern int add_read_access_rule_by_path(int rset_fd,char *allowed_path); | ||
32 | 46 | ||
47 | extern int add_write_access_rule_by_path(int rset_fd,char *allowed_path); | ||
48 | |||
49 | extern int add_create_special_rule_by_path(int rset_fd,char *allowed_path); | ||
50 | |||
51 | extern int add_execute_rule_by_path(int rset_fd,char *allowed_path); | ||
52 | |||
53 | #endif | ||
33 | 54 | ||
34 | // profiles | 55 | // profiles |
35 | #define DEFAULT_USER_PROFILE "default" | 56 | #define DEFAULT_USER_PROFILE "default" |
@@ -286,6 +307,11 @@ extern int arg_seccomp32; // enable default seccomp filter for 32 bit arch | |||
286 | extern int arg_seccomp_postexec; // need postexec ld.preload library? | 307 | extern int arg_seccomp_postexec; // need postexec ld.preload library? |
287 | extern int arg_seccomp_block_secondary; // block any secondary architectures | 308 | extern int arg_seccomp_block_secondary; // block any secondary architectures |
288 | 309 | ||
310 | #ifdef HAVE_LANDLOCK | ||
311 | extern int arg_landlock; // Landlock ruleset file descriptor | ||
312 | extern int arg_landlock_proc; // Landlock rule for accessing /proc (0 for no access, 1 for read-only and 2 for read-write) | ||
313 | #endif | ||
314 | |||
289 | extern int arg_caps_default_filter; // enable default capabilities filter | 315 | extern int arg_caps_default_filter; // enable default capabilities filter |
290 | extern int arg_caps_drop; // drop list | 316 | extern int arg_caps_drop; // drop list |
291 | extern int arg_caps_drop_all; // drop all capabilities | 317 | extern int arg_caps_drop_all; // drop all capabilities |
diff --git a/src/firejail/landlock.c b/src/firejail/landlock.c new file mode 100644 index 000000000..67e2b2cfc --- /dev/null +++ b/src/firejail/landlock.c | |||
@@ -0,0 +1,79 @@ | |||
1 | #define _GNU_SOURCE | ||
2 | #include <stdio.h> | ||
3 | #include <stddef.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <unistd.h> | ||
6 | #include <fcntl.h> | ||
7 | #include <sys/syscall.h> | ||
8 | #include <sys/types.h> | ||
9 | #include <sys/prctl.h> | ||
10 | #include <linux/prctl.h> | ||
11 | #include <linux/landlock.h> | ||
12 | |||
13 | int landlock_create_ruleset(struct landlock_ruleset_attr *rsattr,size_t size,__u32 flags) { | ||
14 | return syscall(__NR_landlock_create_ruleset,rsattr,size,flags); | ||
15 | } | ||
16 | |||
17 | int landlock_add_rule(int fd,enum landlock_rule_type t,void *attr,__u32 flags) { | ||
18 | return syscall(__NR_landlock_add_rule,fd,t,attr,flags); | ||
19 | } | ||
20 | |||
21 | int landlock_restrict_self(int fd,__u32 flags) { | ||
22 | prctl(PR_SET_NO_NEW_PRIVS,1,0,0,0); | ||
23 | int result = syscall(__NR_landlock_restrict_self,fd,flags); | ||
24 | if (result!=0) return result; | ||
25 | else { | ||
26 | close(fd); | ||
27 | return 0; | ||
28 | } | ||
29 | } | ||
30 | |||
31 | int create_full_ruleset() { | ||
32 | struct landlock_ruleset_attr attr; | ||
33 | attr.handled_access_fs = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR | LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SOCK | LANDLOCK_ACCESS_FS_MAKE_FIFO | LANDLOCK_ACCESS_FS_MAKE_BLOCK | LANDLOCK_ACCESS_FS_MAKE_SYM | LANDLOCK_ACCESS_FS_EXECUTE; | ||
34 | return landlock_create_ruleset(&attr,sizeof(attr),0); | ||
35 | } | ||
36 | |||
37 | int add_read_access_rule_by_path(int rset_fd,char *allowed_path) { | ||
38 | int result; | ||
39 | int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
40 | struct landlock_path_beneath_attr target; | ||
41 | target.parent_fd = allowed_fd; | ||
42 | target.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR; | ||
43 | result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
44 | close(allowed_fd); | ||
45 | return result; | ||
46 | } | ||
47 | |||
48 | int add_write_access_rule_by_path(int rset_fd,char *allowed_path) { | ||
49 | int result; | ||
50 | int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
51 | struct landlock_path_beneath_attr target; | ||
52 | target.parent_fd = allowed_fd; | ||
53 | target.allowed_access = LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SYM; | ||
54 | result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
55 | close(allowed_fd); | ||
56 | return result; | ||
57 | } | ||
58 | |||
59 | int add_create_special_rule_by_path(int rset_fd,char *allowed_path) { | ||
60 | int result; | ||
61 | int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
62 | struct landlock_path_beneath_attr target; | ||
63 | target.parent_fd = allowed_fd; | ||
64 | target.allowed_access = LANDLOCK_ACCESS_FS_MAKE_SOCK | LANDLOCK_ACCESS_FS_MAKE_FIFO | LANDLOCK_ACCESS_FS_MAKE_BLOCK; | ||
65 | result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
66 | close(allowed_fd); | ||
67 | return result; | ||
68 | } | ||
69 | |||
70 | int add_execute_rule_by_path(int rset_fd,char *allowed_path) { | ||
71 | int result; | ||
72 | int allowed_fd = open(allowed_path,O_PATH | O_CLOEXEC); | ||
73 | struct landlock_path_beneath_attr target; | ||
74 | target.parent_fd = allowed_fd; | ||
75 | target.allowed_access = LANDLOCK_ACCESS_FS_EXECUTE; | ||
76 | result = landlock_add_rule(rset_fd,LANDLOCK_RULE_PATH_BENEATH,&target,0); | ||
77 | close(allowed_fd); | ||
78 | return result; | ||
79 | } | ||
diff --git a/src/firejail/main.c b/src/firejail/main.c index 29c25dfc5..3f0dc960a 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -81,6 +81,11 @@ int arg_seccomp_postexec = 0; // need postexec ld.preload library? | |||
81 | int arg_seccomp_block_secondary = 0; // block any secondary architectures | 81 | int arg_seccomp_block_secondary = 0; // block any secondary architectures |
82 | int arg_seccomp_error_action = 0; | 82 | int arg_seccomp_error_action = 0; |
83 | 83 | ||
84 | #ifdef HAVE_LANDLOCK | ||
85 | int arg_landlock = -1; // Landlock ruleset file descriptor (-1 if it doesn't exist) | ||
86 | int arg_landlock_proc = 0; // Landlock rule for accessing /proc (0 for no access, 1 for read-only and 2 for read-write) | ||
87 | #endif | ||
88 | |||
84 | int arg_caps_default_filter = 0; // enable default capabilities filter | 89 | int arg_caps_default_filter = 0; // enable default capabilities filter |
85 | int arg_caps_drop = 0; // drop list | 90 | int arg_caps_drop = 0; // drop list |
86 | int arg_caps_drop_all = 0; // drop all capabilities | 91 | int arg_caps_drop_all = 0; // drop all capabilities |
@@ -1401,6 +1406,82 @@ int main(int argc, char **argv, char **envp) { | |||
1401 | else | 1406 | else |
1402 | exit_err_feature("seccomp"); | 1407 | exit_err_feature("seccomp"); |
1403 | } | 1408 | } |
1409 | #ifdef HAVE_LANDLOCK | ||
1410 | else if (strcmp(argv[i], "--landlock") == 0) { | ||
1411 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1412 | const char *home_dir = env_get("HOME"); | ||
1413 | int home_fd = open(home_dir,O_PATH | O_CLOEXEC); | ||
1414 | struct landlock_path_beneath_attr target; | ||
1415 | target.parent_fd = home_fd; | ||
1416 | target.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR | LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SYM; | ||
1417 | if (landlock_add_rule(arg_landlock,LANDLOCK_RULE_PATH_BENEATH,&target,0)) { | ||
1418 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1419 | } | ||
1420 | close(home_fd); | ||
1421 | if (add_read_access_rule_by_path(arg_landlock, "/bin/")) { | ||
1422 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1423 | } | ||
1424 | if (add_execute_rule_by_path(arg_landlock, "/bin/")) { | ||
1425 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1426 | } | ||
1427 | if (add_read_access_rule_by_path(arg_landlock, "/dev/")) { | ||
1428 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1429 | } | ||
1430 | if (add_read_access_rule_by_path(arg_landlock, "/etc/")) { | ||
1431 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1432 | } | ||
1433 | if (add_read_access_rule_by_path(arg_landlock, "/lib/")) { | ||
1434 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1435 | } | ||
1436 | if (add_execute_rule_by_path(arg_landlock, "/lib/")) { | ||
1437 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1438 | } | ||
1439 | if (add_read_access_rule_by_path(arg_landlock, "/opt/")) { | ||
1440 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1441 | } | ||
1442 | if (add_execute_rule_by_path(arg_landlock, "/opt/")) { | ||
1443 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1444 | } | ||
1445 | if (add_read_access_rule_by_path(arg_landlock, "/usr/")) { | ||
1446 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1447 | } | ||
1448 | if (add_execute_rule_by_path(arg_landlock, "/usr/")) { | ||
1449 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1450 | } | ||
1451 | if (add_read_access_rule_by_path(arg_landlock, "/var/")) { | ||
1452 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1453 | } | ||
1454 | } | ||
1455 | else if (strncmp(argv[i], "--landlock.proc=", 16) == 0) { | ||
1456 | if (strncmp(argv[i]+16, "no", 2) == 0) arg_landlock_proc = 0; | ||
1457 | else if (strncmp(argv[i]+16, "ro", 2) == 0) arg_landlock_proc = 1; | ||
1458 | else if (strncmp(argv[i]+16, "rw", 2) == 0) arg_landlock_proc = 2; | ||
1459 | } | ||
1460 | else if (strncmp(argv[i], "--landlock.read=", 16) == 0) { | ||
1461 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1462 | if (add_read_access_rule_by_path(arg_landlock, argv[i]+16)) { | ||
1463 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1464 | } | ||
1465 | } | ||
1466 | else if (strncmp(argv[i], "--landlock.write=", 17) == 0) { | ||
1467 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1468 | if (add_write_access_rule_by_path(arg_landlock, argv[i]+17)) { | ||
1469 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1470 | } | ||
1471 | } | ||
1472 | else if (strncmp(argv[i], "--landlock.special=", 17) == 0) { | ||
1473 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1474 | if (add_create_special_rule_by_path(arg_landlock, argv[i]+17)) { | ||
1475 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1476 | } | ||
1477 | } | ||
1478 | else if (strncmp(argv[i], "--landlock.execute=", 19) == 0) { | ||
1479 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1480 | if (add_execute_rule_by_path(arg_landlock, argv[i]+19)) { | ||
1481 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1482 | } | ||
1483 | } | ||
1484 | #endif | ||
1404 | else if (strcmp(argv[i], "--memory-deny-write-execute") == 0) { | 1485 | else if (strcmp(argv[i], "--memory-deny-write-execute") == 0) { |
1405 | if (checkcfg(CFG_SECCOMP)) | 1486 | if (checkcfg(CFG_SECCOMP)) |
1406 | arg_memory_deny_write_execute = 1; | 1487 | arg_memory_deny_write_execute = 1; |
diff --git a/src/firejail/profile.c b/src/firejail/profile.c index f406e2c53..9a2f8c82c 100644 --- a/src/firejail/profile.c +++ b/src/firejail/profile.c | |||
@@ -1045,6 +1045,90 @@ int profile_check_line(char *ptr, int lineno, const char *fname) { | |||
1045 | return 0; | 1045 | return 0; |
1046 | } | 1046 | } |
1047 | 1047 | ||
1048 | #ifdef HAVE_LANDLOCK | ||
1049 | // Landlock ruleset paths | ||
1050 | if (strcmp(ptr, "landlock") == 0) { | ||
1051 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1052 | const char *home_dir = env_get("HOME"); | ||
1053 | int home_fd = open(home_dir,O_PATH | O_CLOEXEC); | ||
1054 | struct landlock_path_beneath_attr target; | ||
1055 | target.parent_fd = home_fd; | ||
1056 | target.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_READ_DIR | LANDLOCK_ACCESS_FS_WRITE_FILE | LANDLOCK_ACCESS_FS_REMOVE_FILE | LANDLOCK_ACCESS_FS_REMOVE_DIR | LANDLOCK_ACCESS_FS_MAKE_CHAR | LANDLOCK_ACCESS_FS_MAKE_DIR | LANDLOCK_ACCESS_FS_MAKE_REG | LANDLOCK_ACCESS_FS_MAKE_SYM; | ||
1057 | if (landlock_add_rule(arg_landlock,LANDLOCK_RULE_PATH_BENEATH,&target,0)) { | ||
1058 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1059 | } | ||
1060 | close(home_fd); | ||
1061 | if (add_read_access_rule_by_path(arg_landlock, "/bin/")) { | ||
1062 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1063 | } | ||
1064 | if (add_execute_rule_by_path(arg_landlock, "/bin/")) { | ||
1065 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1066 | } | ||
1067 | if (add_read_access_rule_by_path(arg_landlock, "/dev/")) { | ||
1068 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1069 | } | ||
1070 | if (add_read_access_rule_by_path(arg_landlock, "/etc/")) { | ||
1071 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1072 | } | ||
1073 | if (add_read_access_rule_by_path(arg_landlock, "/lib/")) { | ||
1074 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1075 | } | ||
1076 | if (add_execute_rule_by_path(arg_landlock, "/lib/")) { | ||
1077 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1078 | } | ||
1079 | if (add_read_access_rule_by_path(arg_landlock, "/opt/")) { | ||
1080 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1081 | } | ||
1082 | if (add_execute_rule_by_path(arg_landlock, "/opt/")) { | ||
1083 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1084 | } | ||
1085 | if (add_read_access_rule_by_path(arg_landlock, "/usr/")) { | ||
1086 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1087 | } | ||
1088 | if (add_execute_rule_by_path(arg_landlock, "/usr/")) { | ||
1089 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1090 | } | ||
1091 | if (add_read_access_rule_by_path(arg_landlock, "/var/")) { | ||
1092 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1093 | } | ||
1094 | return 0; | ||
1095 | } | ||
1096 | if (strncmp(ptr, "landlock.proc ", 14) == 0) { | ||
1097 | if (strncmp(ptr+14, "no", 2) == 0) arg_landlock_proc = 0; | ||
1098 | else if (strncmp(ptr+14, "ro", 2) == 0) arg_landlock_proc = 1; | ||
1099 | else if (strncmp(ptr+14, "rw", 2) == 0) arg_landlock_proc = 2; | ||
1100 | return 0; | ||
1101 | } | ||
1102 | if (strncmp(ptr, "landlock.read ", 14) == 0) { | ||
1103 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1104 | if (add_read_access_rule_by_path(arg_landlock, ptr+14)) { | ||
1105 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1106 | } | ||
1107 | return 0; | ||
1108 | } | ||
1109 | if (strncmp(ptr, "landlock.write ", 15) == 0) { | ||
1110 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1111 | if (add_write_access_rule_by_path(arg_landlock, ptr+15)) { | ||
1112 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1113 | } | ||
1114 | return 0; | ||
1115 | } | ||
1116 | if (strncmp(ptr, "landlock.special ", 26) == 0) { | ||
1117 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1118 | if (add_create_special_rule_by_path(arg_landlock, ptr+26)) { | ||
1119 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1120 | } | ||
1121 | return 0; | ||
1122 | } | ||
1123 | if (strncmp(ptr, "landlock.execute ", 17) == 0) { | ||
1124 | if (arg_landlock == -1) arg_landlock = create_full_ruleset(); | ||
1125 | if (add_execute_rule_by_path(arg_landlock, ptr+17)) { | ||
1126 | fprintf(stderr,"An error has occured while adding a rule to the Landlock ruleset.\n"); | ||
1127 | } | ||
1128 | return 0; | ||
1129 | } | ||
1130 | #endif | ||
1131 | |||
1048 | // memory deny write&execute | 1132 | // memory deny write&execute |
1049 | if (strcmp(ptr, "memory-deny-write-execute") == 0) { | 1133 | if (strcmp(ptr, "memory-deny-write-execute") == 0) { |
1050 | if (checkcfg(CFG_SECCOMP)) | 1134 | if (checkcfg(CFG_SECCOMP)) |
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c index 9299268a3..5fcccbd92 100644 --- a/src/firejail/sandbox.c +++ b/src/firejail/sandbox.c | |||
@@ -488,6 +488,7 @@ void start_application(int no_sandbox, int fd, char *set_sandbox_status) { | |||
488 | #ifdef HAVE_APPARMOR | 488 | #ifdef HAVE_APPARMOR |
489 | set_apparmor(); | 489 | set_apparmor(); |
490 | #endif | 490 | #endif |
491 | |||
491 | close_file_descriptors(); | 492 | close_file_descriptors(); |
492 | 493 | ||
493 | // set nice and rlimits | 494 | // set nice and rlimits |
@@ -509,6 +510,16 @@ void start_application(int no_sandbox, int fd, char *set_sandbox_status) { | |||
509 | printf("LD_PRELOAD=%s\n", getenv("LD_PRELOAD")); | 510 | printf("LD_PRELOAD=%s\n", getenv("LD_PRELOAD")); |
510 | } | 511 | } |
511 | 512 | ||
513 | #ifdef HAVE_LANDLOCK | ||
514 | // set Landlock | ||
515 | if (arg_landlock >= 0) { | ||
516 | if (landlock_restrict_self(arg_landlock,0)) { | ||
517 | fprintf(stderr,"An error has occured while enabling Landlock self-restriction. Exiting...\n"); | ||
518 | exit(1); // it isn't safe to continue if Landlock self-restriction was enabled and the "landlock_restrict_self" syscall has failed | ||
519 | } | ||
520 | } | ||
521 | #endif | ||
522 | |||
512 | if (just_run_the_shell) { | 523 | if (just_run_the_shell) { |
513 | char *arg[2]; | 524 | char *arg[2]; |
514 | arg[0] = cfg.usershell; | 525 | arg[0] = cfg.usershell; |
@@ -999,6 +1010,15 @@ int sandbox(void* sandbox_arg) { | |||
999 | fs_proc_sys_dev_boot(); | 1010 | fs_proc_sys_dev_boot(); |
1000 | 1011 | ||
1001 | //**************************** | 1012 | //**************************** |
1013 | // Allow access to /proc | ||
1014 | //**************************** | ||
1015 | #ifdef HAVE_LANDLOCK | ||
1016 | if (arg_landlock>-1) { | ||
1017 | if (arg_landlock_proc >= 1) add_read_access_rule_by_path(arg_landlock, "/proc/"); | ||
1018 | if (arg_landlock_proc == 2) add_write_access_rule_by_path(arg_landlock, "/proc/"); | ||
1019 | } | ||
1020 | #endif | ||
1021 | //**************************** | ||
1002 | // handle /mnt and /media | 1022 | // handle /mnt and /media |
1003 | //**************************** | 1023 | //**************************** |
1004 | if (checkcfg(CFG_DISABLE_MNT)) | 1024 | if (checkcfg(CFG_DISABLE_MNT)) |
@@ -1093,9 +1113,12 @@ int sandbox(void* sandbox_arg) { | |||
1093 | //**************************** | 1113 | //**************************** |
1094 | // rebuild etc directory, set dns | 1114 | // rebuild etc directory, set dns |
1095 | //**************************** | 1115 | //**************************** |
1096 | if (!arg_writable_etc) | 1116 | if (!arg_writable_etc){ |
1097 | fs_rebuild_etc(); | 1117 | fs_rebuild_etc(); |
1098 | 1118 | #ifdef HAVE_LANDLOCK | |
1119 | if (arg_landlock>-1) add_read_access_rule_by_path(arg_landlock, "/etc/"); | ||
1120 | #endif | ||
1121 | } | ||
1099 | //**************************** | 1122 | //**************************** |
1100 | // start dhcp client | 1123 | // start dhcp client |
1101 | //**************************** | 1124 | //**************************** |
diff --git a/src/firejail/usage.c b/src/firejail/usage.c index e11081eed..e0751ef5c 100644 --- a/src/firejail/usage.c +++ b/src/firejail/usage.c | |||
@@ -122,6 +122,12 @@ static char *usage_str = | |||
122 | " --keep-dev-shm - /dev/shm directory is untouched (even with --private-dev).\n" | 122 | " --keep-dev-shm - /dev/shm directory is untouched (even with --private-dev).\n" |
123 | " --keep-fd - inherit open file descriptors to sandbox.\n" | 123 | " --keep-fd - inherit open file descriptors to sandbox.\n" |
124 | " --keep-var-tmp - /var/tmp directory is untouched.\n" | 124 | " --keep-var-tmp - /var/tmp directory is untouched.\n" |
125 | " --landlock - add basic rules to the Landlock ruleset.\n" | ||
126 | " --landlock.proc=no|ro|rw - add an access rule for /proc to the Landlock ruleset.\n" | ||
127 | " --landlock.read=path - add a read access rule for the path to the Landlock ruleset.\n" | ||
128 | " --landlock.write=path - add a write access rule for the path to the Landlock ruleset.\n" | ||
129 | " --landlock.special=path - add an access rule for creating FIFO pipes, Unix domain sockets and block devices for the path to the Landlock ruleset.\n" | ||
130 | " --landlock.execute=path - add an execution-permitting rule for the path to the Landlock ruleset.\n" | ||
125 | " --list - list all sandboxes.\n" | 131 | " --list - list all sandboxes.\n" |
126 | #ifdef HAVE_FILE_TRANSFER | 132 | #ifdef HAVE_FILE_TRANSFER |
127 | " --ls=name|pid dir_or_filename - list files in sandbox container.\n" | 133 | " --ls=name|pid dir_or_filename - list files in sandbox container.\n" |
diff --git a/src/firejail/util.c b/src/firejail/util.c index a01290cf2..b6a7ca08c 100644 --- a/src/firejail/util.c +++ b/src/firejail/util.c | |||
@@ -1338,6 +1338,10 @@ void close_all(int *keep_list, size_t sz) { | |||
1338 | if (keep) | 1338 | if (keep) |
1339 | continue; | 1339 | continue; |
1340 | 1340 | ||
1341 | // don't close the file descriptor of the Landlock ruleset -- it will be automatically closed by the landlock_restrict_self wrapper function | ||
1342 | #ifdef HAVE_LANDLOCK | ||
1343 | if (fd == arg_landlock) continue; | ||
1344 | #endif | ||
1341 | close(fd); | 1345 | close(fd); |
1342 | } | 1346 | } |
1343 | closedir(dir); | 1347 | closedir(dir); |
diff --git a/src/man/firejail-profile.txt b/src/man/firejail-profile.txt index 138aae8af..1f543980e 100644 --- a/src/man/firejail-profile.txt +++ b/src/man/firejail-profile.txt | |||
@@ -497,6 +497,35 @@ Blacklist all Linux capabilities. | |||
497 | .TP | 497 | .TP |
498 | \fBcaps.keep capability,capability,capability | 498 | \fBcaps.keep capability,capability,capability |
499 | Whitelist given Linux capabilities. | 499 | Whitelist given Linux capabilities. |
500 | #ifdef HAVE_LANDLOCK | ||
501 | .TP | ||
502 | \fBlandlock | ||
503 | Create a Landlock ruleset (if it doesn't already exist) and add basic access rules to it. | ||
504 | .br | ||
505 | .TP | ||
506 | \fBlandlock.proc no|ro|rw | ||
507 | Add an access rule for /proc directory (read-only if set to \fBro\fR and read-write if set to \fBrw\fR). The access rule for /proc is added after this directory is set up in the sandbox. Access rules for /proc set up with other Landlock-related profile options have no effect. | ||
508 | .br | ||
509 | .TP | ||
510 | \fBlandlock.read path | ||
511 | Create a Landlock ruleset (if it doesn't already exist) and add a read access rule for path. | ||
512 | .br | ||
513 | |||
514 | .TP | ||
515 | \fBlandlock.write path | ||
516 | Create a Landlock ruleset (if it doesn't already exist) and add a write access rule for path. | ||
517 | .br | ||
518 | |||
519 | .TP | ||
520 | \fBlandlock.special path | ||
521 | Create a Landlock ruleset (if it doesn't already exist) and add an access rule for creation of FIFO pipes, Unix-domain sockets and block devices beneath given path. | ||
522 | .br | ||
523 | |||
524 | .TP | ||
525 | \fBlandlock.execute path | ||
526 | Create a Landlock ruleset (if it doesn't already exist) and add an execution permission rule for path. | ||
527 | .br | ||
528 | #endif | ||
500 | .TP | 529 | .TP |
501 | \fBmemory-deny-write-execute | 530 | \fBmemory-deny-write-execute |
502 | Install a seccomp filter to block attempts to create memory mappings | 531 | Install a seccomp filter to block attempts to create memory mappings |
diff --git a/src/man/firejail.txt b/src/man/firejail.txt index 1dd5508b3..0b78203d7 100644 --- a/src/man/firejail.txt +++ b/src/man/firejail.txt | |||
@@ -1151,6 +1151,41 @@ Example: | |||
1151 | .br | 1151 | .br |
1152 | $ firejail --keep-var-tmp | 1152 | $ firejail --keep-var-tmp |
1153 | 1153 | ||
1154 | #ifdef HAVE_LANDLOCK | ||
1155 | .TP | ||
1156 | \fB\-\-landlock | ||
1157 | Create a Landlock ruleset (if it doesn't already exist) and add basic access rules to it. See \fBLANDLOCK\fR section for more information. | ||
1158 | .br | ||
1159 | .TP | ||
1160 | \fB\-\-landlock.proc=no|ro|rw | ||
1161 | Add an access rule for /proc directory (read-only if set to \fBro\fR and read-write if set to \fBrw\fR). The access rule for /proc is added after this directory is set up in the sandbox. Access rules for /proc set up with other Landlock-related command-line options have no effect. | ||
1162 | .br | ||
1163 | .TP | ||
1164 | \fB\-\-landlock.read=path | ||
1165 | Create a Landlock ruleset (if it doesn't already exist) and add a read access rule for path. | ||
1166 | .br | ||
1167 | |||
1168 | .TP | ||
1169 | \fB\-\-landlock.write=path | ||
1170 | Create a Landlock ruleset (if it doesn't already exist) and add a write access rule for path. | ||
1171 | .br | ||
1172 | |||
1173 | .TP | ||
1174 | \fB\-\-landlock.special=path | ||
1175 | Create a Landlock ruleset (if it doesn't already exist) and add a permission rule to create FIFO pipes, Unix domain sockets and block devices beneath given path. | ||
1176 | .br | ||
1177 | |||
1178 | .TP | ||
1179 | \fB\-\-landlock.execute=path | ||
1180 | Create a Landlock ruleset (if it doesn't already exist) and add an execution permission rule for path. | ||
1181 | .br | ||
1182 | |||
1183 | .br | ||
1184 | Example: | ||
1185 | .br | ||
1186 | $ firejail \-\-landlock.read=/ \-\-landlock.write=/home \-\-landlock.execute=/usr | ||
1187 | #endif | ||
1188 | |||
1154 | .TP | 1189 | .TP |
1155 | \fB\-\-list | 1190 | \fB\-\-list |
1156 | List all sandboxes, see \fBMONITORING\fR section for more details. | 1191 | List all sandboxes, see \fBMONITORING\fR section for more details. |
@@ -1268,6 +1303,7 @@ $ firejail --list | |||
1268 | .br | 1303 | .br |
1269 | 1312:netblue:browser-1312:firejail --name=browser --private firefox --no-remote | 1304 | 1312:netblue:browser-1312:firejail --name=browser --private firefox --no-remote |
1270 | .br | 1305 | .br |
1306 | |||
1271 | #ifdef HAVE_NETWORK | 1307 | #ifdef HAVE_NETWORK |
1272 | .TP | 1308 | .TP |
1273 | \fB\-\-net=bridge_interface | 1309 | \fB\-\-net=bridge_interface |
@@ -3201,7 +3237,34 @@ To enable AppArmor confinement on top of your current Firejail security features | |||
3201 | .br | 3237 | .br |
3202 | $ firejail --apparmor firefox | 3238 | $ firejail --apparmor firefox |
3203 | #endif | 3239 | #endif |
3240 | #ifdef HAVE_LANDLOCK | ||
3241 | .SH LANDLOCK | ||
3242 | .TP | ||
3243 | Landlock is a Linux security module first introduced in the 5.13 version of Linux kernel. It allows unprivileged processes to restrict their access to the filesystem. Once imposed, these restrictions can never be removed, and all child processes created by a Landlock-restricted processes inherit these restrictions. Firejail supports Landlock as an additional sandboxing feature. It can be used to ensure that a sandboxed application can only access files and directories that it was explicitly allowed to access. Firejail supports populating the ruleset with both basic set of rules and with custom set of rules. Basic set of rules allows read-only access to /bin, /dev, /etc, /lib, /opt, /proc, /usr and /var, read-write access to the home directory, and allows execution of binaries located in /bin, /opt and /usr. | ||
3244 | .br | ||
3245 | |||
3246 | .TP | ||
3247 | Important notes: | ||
3248 | .br | ||
3249 | |||
3250 | .br | ||
3251 | - A process can install a Landlock ruleset only if it has either \fBCAP_SYS_ADMIN\fR in its effective capability set, or the "No New Privileges" restriction enabled. Because of this, enabling the Landlock feature will also cause Firejail to enable the "No New Privileges" restriction, regardless of the profile or the \fB\-\-no\-new\-privs\fR command line option. | ||
3252 | .br | ||
3204 | 3253 | ||
3254 | .br | ||
3255 | - Access to the /proc directory is managed through the \fB\-\-landlock.proc\fR command line option. | ||
3256 | |||
3257 | .br | ||
3258 | - Access to the /etc directory is automatically allowed. To override this, use the \fB\-\-writable\-etc\fR command line option. You can also use the \fB\-\-private\-etc\fR option to restrict access to the /etc directory. | ||
3259 | .br | ||
3260 | |||
3261 | .TP | ||
3262 | To enable Landlock self-restriction on top of your current Firejail security features, pass \fB\-\-landlock\fR flag to Firejail command line. You can also use \fB\-\-landlock.read\fR, \fB\-\-landlock.write\fR, \fB\-\-landlock.special\fR and \fB\-\-landlock.execute\fR options together with \fB\-\-landlock\fR or instead of it. Example: | ||
3263 | .br | ||
3264 | |||
3265 | .br | ||
3266 | $ firejail --landlock --landlock.read=/media --landlock.proc=ro mc | ||
3267 | #endif | ||
3205 | .SH DESKTOP INTEGRATION | 3268 | .SH DESKTOP INTEGRATION |
3206 | A symbolic link to /usr/bin/firejail under the name of a program, will start the program in Firejail sandbox. | 3269 | A symbolic link to /usr/bin/firejail under the name of a program, will start the program in Firejail sandbox. |
3207 | The symbolic link should be placed in the first $PATH position. On most systems, a good place | 3270 | The symbolic link should be placed in the first $PATH position. On most systems, a good place |
diff --git a/src/zsh_completion/_firejail.in b/src/zsh_completion/_firejail.in index 2b67c2a00..ed7337762 100644 --- a/src/zsh_completion/_firejail.in +++ b/src/zsh_completion/_firejail.in | |||
@@ -105,6 +105,12 @@ _firejail_args=( | |||
105 | '--keep-dev-shm[/dev/shm directory is untouched (even with --private-dev)]' | 105 | '--keep-dev-shm[/dev/shm directory is untouched (even with --private-dev)]' |
106 | '--keep-fd[inherit open file descriptors to sandbox]: :' | 106 | '--keep-fd[inherit open file descriptors to sandbox]: :' |
107 | '--keep-var-tmp[/var/tmp directory is untouched]' | 107 | '--keep-var-tmp[/var/tmp directory is untouched]' |
108 | '--landlock[Basic Landlock ruleset]' | ||
109 | '--landlock.proc=-[Access to the /proc directory]: :(no ro rw)' | ||
110 | '--landlock.read=-[Landlock read access rule]: :_files' | ||
111 | '--landlock.write=-[Landlock write access rule]: :_files' | ||
112 | "--landlock.special=-[Landlock access rule for creation of FIFO pipes, sockets and block devices]: :_files" | ||
113 | '--landlock.execute=-[Landlock execution-permitting rule]: :_files' | ||
108 | '--machine-id[spoof /etc/machine-id with a random id]' | 114 | '--machine-id[spoof /etc/machine-id with a random id]' |
109 | '--memory-deny-write-execute[seccomp filter to block attempts to create memory mappings that are both writable and executable]' | 115 | '--memory-deny-write-execute[seccomp filter to block attempts to create memory mappings that are both writable and executable]' |
110 | '*--mkdir=-[create a directory]:' | 116 | '*--mkdir=-[create a directory]:' |