aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Азалия Смарагдова <charming.flurry@yandex.ru>2022-07-25 17:16:53 +0500
committerLibravatar Азалия Смарагдова <charming.flurry@yandex.ru>2022-08-05 11:47:24 +0500
commit7f3b6c19a0a87bfd240af7c0c9d61ae907668ce6 (patch)
tree9bcc55b6dc49357f1b7330174be4524efbb1b45c /src
parentRELNOTES: add build and ci items (diff)
downloadfirejail-7f3b6c19a0a87bfd240af7c0c9d61ae907668ce6.tar.gz
firejail-7f3b6c19a0a87bfd240af7c0c9d61ae907668ce6.tar.zst
firejail-7f3b6c19a0a87bfd240af7c0c9d61ae907668ce6.zip
Add support for custom AppArmor profiles (--apparmor=)
Diffstat (limited to 'src')
-rw-r--r--src/firejail/firejail.h1
-rw-r--r--src/firejail/main.c9
-rw-r--r--src/firejail/profile.c11
-rw-r--r--src/firejail/sandbox.c2
-rw-r--r--src/firejail/usage.c4
-rw-r--r--src/man/firejail-profile.txt6
-rw-r--r--src/man/firejail.txt8
-rw-r--r--src/zsh_completion/_firejail.in3
8 files changed, 38 insertions, 6 deletions
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h
index 167b6a843..0a4dffb75 100644
--- a/src/firejail/firejail.h
+++ b/src/firejail/firejail.h
@@ -338,6 +338,7 @@ extern int arg_writable_run_user; // writable /run/user
338extern int arg_writable_var_log; // writable /var/log 338extern int arg_writable_var_log; // writable /var/log
339extern int arg_appimage; // appimage 339extern int arg_appimage; // appimage
340extern int arg_apparmor; // apparmor 340extern int arg_apparmor; // apparmor
341extern char *apparmor_profile; // apparmor profile
341extern int arg_allow_debuggers; // allow debuggers 342extern int arg_allow_debuggers; // allow debuggers
342extern int arg_x11_block; // block X11 343extern int arg_x11_block; // block X11
343extern int arg_x11_xorg; // use X11 security extension 344extern int arg_x11_xorg; // use X11 security extension
diff --git a/src/firejail/main.c b/src/firejail/main.c
index 55f623138..29c25dfc5 100644
--- a/src/firejail/main.c
+++ b/src/firejail/main.c
@@ -133,6 +133,7 @@ int arg_writable_run_user = 0; // writable /run/user
133int arg_writable_var_log = 0; // writable /var/log 133int arg_writable_var_log = 0; // writable /var/log
134int arg_appimage = 0; // appimage 134int arg_appimage = 0; // appimage
135int arg_apparmor = 0; // apparmor 135int arg_apparmor = 0; // apparmor
136char *apparmor_profile = NULL; // apparmor profile
136int arg_allow_debuggers = 0; // allow debuggers 137int arg_allow_debuggers = 0; // allow debuggers
137int arg_x11_block = 0; // block X11 138int arg_x11_block = 0; // block X11
138int arg_x11_xorg = 0; // use X11 security extension 139int arg_x11_xorg = 0; // use X11 security extension
@@ -1287,8 +1288,14 @@ int main(int argc, char **argv, char **envp) {
1287 // filtering 1288 // filtering
1288 //************************************* 1289 //*************************************
1289#ifdef HAVE_APPARMOR 1290#ifdef HAVE_APPARMOR
1290 else if (strcmp(argv[i], "--apparmor") == 0) 1291 else if (strcmp(argv[i], "--apparmor") == 0) {
1291 arg_apparmor = 1; 1292 arg_apparmor = 1;
1293 apparmor_profile = "firejail-default";
1294 }
1295 else if (strncmp(argv[i], "--apparmor=", 11) == 0) {
1296 arg_apparmor = 1;
1297 apparmor_profile = argv[i] + 11;
1298 }
1292#endif 1299#endif
1293 else if (strncmp(argv[i], "--protocol=", 11) == 0) { 1300 else if (strncmp(argv[i], "--protocol=", 11) == 0) {
1294 if (checkcfg(CFG_SECCOMP)) { 1301 if (checkcfg(CFG_SECCOMP)) {
diff --git a/src/firejail/profile.c b/src/firejail/profile.c
index dc1aff49a..82f8a393b 100644
--- a/src/firejail/profile.c
+++ b/src/firejail/profile.c
@@ -939,6 +939,17 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
939 if (strcmp(ptr, "apparmor") == 0) { 939 if (strcmp(ptr, "apparmor") == 0) {
940#ifdef HAVE_APPARMOR 940#ifdef HAVE_APPARMOR
941 arg_apparmor = 1; 941 arg_apparmor = 1;
942 apparmor_profile = "firejail-default";
943#endif
944 return 0;
945 }
946
947 if (strncmp(ptr, "apparmor ", 9) == 0) {
948#ifdef HAVE_APPARMOR
949 arg_apparmor = 1;
950 apparmor_profile = strdup(ptr + 9);
951 if (!apparmor_profile)
952 errExit("strdup");
942#endif 953#endif
943 return 0; 954 return 0;
944 } 955 }
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c
index b1b3407b4..9299268a3 100644
--- a/src/firejail/sandbox.c
+++ b/src/firejail/sandbox.c
@@ -130,7 +130,7 @@ static void set_caps(void) {
130static void set_apparmor(void) { 130static void set_apparmor(void) {
131 EUID_ASSERT(); 131 EUID_ASSERT();
132 if (checkcfg(CFG_APPARMOR) && arg_apparmor) { 132 if (checkcfg(CFG_APPARMOR) && arg_apparmor) {
133 if (aa_change_onexec("firejail-default")) { 133 if (aa_stack_onexec(apparmor_profile)) {
134 fwarning("Cannot confine the application using AppArmor.\n" 134 fwarning("Cannot confine the application using AppArmor.\n"
135 "Maybe firejail-default AppArmor profile is not loaded into the kernel.\n" 135 "Maybe firejail-default AppArmor profile is not loaded into the kernel.\n"
136 "As root, run \"aa-enforce firejail-default\" to load it.\n"); 136 "As root, run \"aa-enforce firejail-default\" to load it.\n");
diff --git a/src/firejail/usage.c b/src/firejail/usage.c
index c3c17393c..e11081eed 100644
--- a/src/firejail/usage.c
+++ b/src/firejail/usage.c
@@ -30,7 +30,9 @@ static char *usage_str =
30 " -- - signal the end of options and disables further option processing.\n" 30 " -- - signal the end of options and disables further option processing.\n"
31 " --allow-debuggers - allow tools such as strace and gdb inside the sandbox.\n" 31 " --allow-debuggers - allow tools such as strace and gdb inside the sandbox.\n"
32 " --allusers - all user home directories are visible inside the sandbox.\n" 32 " --allusers - all user home directories are visible inside the sandbox.\n"
33 " --apparmor - enable AppArmor confinement.\n" 33 " --apparmor - enable AppArmor confinement with the default profile.\n"
34 " --apparmor=profile_name - enable AppArmor confinement with a\n"
35 "\tcustom profile.\n"
34 " --apparmor.print=name|pid - print apparmor status.\n" 36 " --apparmor.print=name|pid - print apparmor status.\n"
35 " --appimage - sandbox an AppImage application.\n" 37 " --appimage - sandbox an AppImage application.\n"
36#ifdef HAVE_NETWORK 38#ifdef HAVE_NETWORK
diff --git a/src/man/firejail-profile.txt b/src/man/firejail-profile.txt
index be1f55f0f..0b0c64ec6 100644
--- a/src/man/firejail-profile.txt
+++ b/src/man/firejail-profile.txt
@@ -478,7 +478,11 @@ Allow tools such as strace and gdb inside the sandbox by whitelisting system cal
478#ifdef HAVE_APPARMOR 478#ifdef HAVE_APPARMOR
479.TP 479.TP
480\fBapparmor 480\fBapparmor
481Enable AppArmor confinement. 481Enable AppArmor confinement with the "firejail-default" AppArmor profile.
482.TP
483\fBapparmor profile_name
484Enable AppArmor confinement with a custom AppArmor profile.
485Note that the profile in question must already be loaded into the kernel.
482#endif 486#endif
483.TP 487.TP
484\fBcaps 488\fBcaps
diff --git a/src/man/firejail.txt b/src/man/firejail.txt
index 087d1c85a..b783795f2 100644
--- a/src/man/firejail.txt
+++ b/src/man/firejail.txt
@@ -122,7 +122,13 @@ $ firejail --allusers
122#ifdef HAVE_APPARMOR 122#ifdef HAVE_APPARMOR
123.TP 123.TP
124\fB\-\-apparmor 124\fB\-\-apparmor
125Enable AppArmor confinement. For more information, please see \fBAPPARMOR\fR section below. 125Enable AppArmor confinement with the "firejail-default" AppArmor profile.
126For more information, please see \fBAPPARMOR\fR section below.
127.TP
128\fB\-\-apparmor=profile_name
129Enable AppArmor confinement with a custom AppArmor profile.
130Note that profile in question must already be loaded into the kernel.
131For more information, please see \fBAPPARMOR\fR section below.
126.TP 132.TP
127\fB\-\-apparmor.print=name|pid 133\fB\-\-apparmor.print=name|pid
128Print the AppArmor confinement status for the sandbox identified by name or by PID. 134Print the AppArmor confinement status for the sandbox identified by name or by PID.
diff --git a/src/zsh_completion/_firejail.in b/src/zsh_completion/_firejail.in
index 605000e31..2b67c2a00 100644
--- a/src/zsh_completion/_firejail.in
+++ b/src/zsh_completion/_firejail.in
@@ -171,7 +171,8 @@ _firejail_args=(
171 '--writable-var-log[use the real /var/log directory, not a clone]' 171 '--writable-var-log[use the real /var/log directory, not a clone]'
172 172
173#ifdef HAVE_APPARMOR 173#ifdef HAVE_APPARMOR
174 '--apparmor[enable AppArmor confinement]' 174 '--apparmor[enable AppArmor confinement with the default profile]'
175 '--apparmor=-[enable AppArmor confinement with a custom profile]: :'
175 '--apparmor.print=-[print apparmor status name|pid]:firejail:_all_firejails' 176 '--apparmor.print=-[print apparmor status name|pid]:firejail:_all_firejails'
176#endif 177#endif
177 178