Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

landlock: split .special into .makeipc and .makedev #6187

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contrib/syntax/lists/profile_commands_arg1.list
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ iprange
join-or-start
keep-fd
landlock.execute
landlock.makedev
landlock.makeipc
landlock.read
landlock.special
landlock.write
mac
mkdir
Expand Down
2 changes: 1 addition & 1 deletion etc/inc/landlock-common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include landlock-common.local

landlock.read / # whole system read
landlock.read /proc
landlock.special / # sockets etc.
landlock.makeipc / # sockets etc.

# write access
landlock.write ${HOME}
Expand Down
3 changes: 2 additions & 1 deletion etc/templates/profile.template
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ include globals.local
# Landlock commands
##landlock.read PATH
##landlock.write PATH
##landlock.special PATH
##landlock.makeipc PATH
##landlock.makedev PATH
##landlock.execute PATH
#include landlock-common.inc

Expand Down
6 changes: 5 additions & 1 deletion src/bash_completion/firejail.bash_completion.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ _firejail()
_filedir
return 0
;;
--landlock.special)
--landlock.makeipc)
_filedir
return 0
;;
--landlock.makedev)
_filedir
return 0
;;
Expand Down
7 changes: 4 additions & 3 deletions src/firejail/firejail.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,10 @@ typedef struct landlock_entry_t {
struct landlock_entry_t *next;
#define LL_READ 0
#define LL_WRITE 1
#define LL_SPECIAL 2
#define LL_EXEC 3
#define LL_MAX 4
#define LL_MAKEIPC 2
#define LL_MAKEDEV 3
#define LL_EXEC 4
#define LL_MAX 5
int type;
char *data;
} LandlockEntry;
Expand Down
15 changes: 11 additions & 4 deletions src/firejail/landlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,22 @@ static void ll_write(const char *allowed_path) {
ll_fs(allowed_path, allowed_access, __func__);
}

static void ll_special(const char *allowed_path) {
static void ll_makeipc(const char *allowed_path) {
__u64 allowed_access =
LANDLOCK_ACCESS_FS_MAKE_BLOCK |
LANDLOCK_ACCESS_FS_MAKE_CHAR |
LANDLOCK_ACCESS_FS_MAKE_FIFO |
LANDLOCK_ACCESS_FS_MAKE_SOCK;

ll_fs(allowed_path, allowed_access, __func__);
}

static void ll_makedev(const char *allowed_path) {
__u64 allowed_access =
LANDLOCK_ACCESS_FS_MAKE_BLOCK |
LANDLOCK_ACCESS_FS_MAKE_CHAR;

ll_fs(allowed_path, allowed_access, __func__);
}

static void ll_exec(const char *allowed_path) {
__u64 allowed_access =
LANDLOCK_ACCESS_FS_EXECUTE;
Expand All @@ -223,7 +229,8 @@ int ll_restrict(uint32_t flags) {
void (*fnc[])(const char *) = {
ll_read,
ll_write,
ll_special,
ll_makeipc,
ll_makedev,
ll_exec,
NULL
};
Expand Down
6 changes: 4 additions & 2 deletions src/firejail/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,8 +1509,10 @@ int main(int argc, char **argv, char **envp) {
ll_add_profile(LL_READ, argv[i] + 16);
else if (strncmp(argv[i], "--landlock.write=", 17) == 0)
ll_add_profile(LL_WRITE, argv[i] + 17);
else if (strncmp(argv[i], "--landlock.special=", 19) == 0)
ll_add_profile(LL_SPECIAL, argv[i] + 19);
else if (strncmp(argv[i], "--landlock.makeipc=", 19) == 0)
ll_add_profile(LL_MAKEIPC, argv[i] + 19);
else if (strncmp(argv[i], "--landlock.makedev=", 19) == 0)
ll_add_profile(LL_MAKEDEV, argv[i] + 19);
else if (strncmp(argv[i], "--landlock.execute=", 19) == 0)
ll_add_profile(LL_EXEC, argv[i] + 19);
#endif
Expand Down
8 changes: 6 additions & 2 deletions src/firejail/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,12 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
ll_add_profile(LL_WRITE, ptr + 15);
return 0;
}
if (strncmp(ptr, "landlock.special ", 17) == 0) {
ll_add_profile(LL_SPECIAL, ptr + 17);
if (strncmp(ptr, "landlock.makeipc ", 17) == 0) {
ll_add_profile(LL_MAKEIPC, ptr + 17);
return 0;
}
if (strncmp(ptr, "landlock.makedev ", 17) == 0) {
ll_add_profile(LL_MAKEDEV, ptr + 17);
return 0;
}
if (strncmp(ptr, "landlock.execute ", 17) == 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/firejail/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ static const char *const usage_str =
" --landlock.enforce - enforce the Landlock ruleset.\n"
" --landlock.read=path - add a read access rule for the path to the Landlock ruleset.\n"
" --landlock.write=path - add a write access rule for the path to the Landlock ruleset.\n"
" --landlock.special=path - add an access rule for the path to the Landlock ruleset for creating block/char devices, named pipes and sockets.\n"
" --landlock.makeipc=path - add an access rule for the path to the Landlock ruleset for creating named pipes and sockets.\n"
" --landlock.makedev=path - add an access rule for the path to the Landlock ruleset for creating block/char devices.\n"
" --landlock.execute=path - add an execute access rule for the path to the Landlock ruleset.\n"
#endif
" --list - list all sandboxes.\n"
Expand Down
11 changes: 8 additions & 3 deletions src/man/firejail-profile.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,15 @@ rule for path.
Create a Landlock ruleset (if it doesn't already exist) and add a write access
rule for path.
.TP
\fBlandlock.special path
\fBlandlock.makeipc path
Create a Landlock ruleset (if it doesn't already exist) and add a rule that
allows the creation of block devices, character devices, named pipes (FIFOs)
and Unix domain sockets beneath given path.
allows the creation of named pipes (FIFOs) and Unix domain sockets beneath
the given path.
.TP
\fBlandlock.makedev path
Create a Landlock ruleset (if it doesn't already exist) and add a rule that
allows the creation of block devices and character devices beneath the given
path.
.TP
\fBlandlock.execute path
Create a Landlock ruleset (if it doesn't already exist) and add an execution
Expand Down
11 changes: 8 additions & 3 deletions src/man/firejail.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -1249,10 +1249,15 @@ rule for path.
Create a Landlock ruleset (if it doesn't already exist) and add a write access
rule for path.
.TP
\fB\-\-landlock.special=path
\fB\-\-landlock.makeipc=path
Create a Landlock ruleset (if it doesn't already exist) and add a rule that
allows the creation of block devices, character devices, named pipes (FIFOs)
and Unix domain sockets beneath given path.
allows the creation of named pipes (FIFOs) and Unix domain sockets beneath
the given path.
.TP
\fB\-\-landlock.makedev=path
Create a Landlock ruleset (if it doesn't already exist) and add a rule that
allows the creation of block devices and character devices beneath the given
path.
.TP
\fB\-\-landlock.execute=path
Create a Landlock ruleset (if it doesn't already exist) and add an execution
Expand Down
3 changes: 2 additions & 1 deletion src/zsh_completion/_firejail.in
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ _firejail_args=(
'--landlock.enforce[enforce the Landlock ruleset]'
'--landlock.read=-[add a read access rule for the path to the Landlock ruleset]: :_files'
'--landlock.write=-[add a write access rule for the path to the Landlock ruleset]: :_files'
'--landlock.special=-[add an access rule for the path to the Landlock ruleset for creating block/char devices, named pipes and sockets]: :_files'
'--landlock.makeipc=-[add an access rule for the path to the Landlock ruleset for creating named pipes and sockets]: :_files'
'--landlock.makedev=-[add an access rule for the path to the Landlock ruleset for creating block/char devices]: :_files'
'--landlock.execute=-[add an execute access rule for the path to the Landlock ruleset]: :_files'
#endif
'--machine-id[spoof /etc/machine-id with a random id]'
Expand Down
Loading