Skip to content

Commit

Permalink
A temporary fix to the bug caused by apparmor profiles stacking.
Browse files Browse the repository at this point in the history
  • Loading branch information
KOLANICH committed Nov 15, 2022
1 parent 98e8f28 commit 900db66
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions etc/profile-a-l/firefox-common.profile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ include whitelist-runuser-common.inc
include whitelist-var-common.inc

apparmor
# Fixme!
apparmor-replace
caps.drop all
# machine-id breaks pulse audio; add it to your firefox-common.local if sound is not required.
#machine-id
Expand Down
1 change: 1 addition & 0 deletions src/firejail/firejail.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ extern int arg_writable_var_log; // writable /var/log
extern int arg_appimage; // appimage
extern int arg_apparmor; // apparmor
extern char *apparmor_profile; // apparmor profile
extern bool apparmor_replace; // whether apparmor should replace the profile (legacy behavior)
extern int arg_allow_debuggers; // allow debuggers
extern int arg_x11_block; // block X11
extern int arg_x11_xorg; // use X11 security extension
Expand Down
5 changes: 5 additions & 0 deletions src/firejail/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ int arg_writable_var_log = 0; // writable /var/log
int arg_appimage = 0; // appimage
int arg_apparmor = 0; // apparmor
char *apparmor_profile = NULL; // apparmor profile
bool apparmor_replace = false; // apparmor profile
int arg_allow_debuggers = 0; // allow debuggers
int arg_x11_block = 0; // block X11
int arg_x11_xorg = 0; // use X11 security extension
Expand Down Expand Up @@ -1383,6 +1384,10 @@ int main(int argc, char **argv, char **envp) {
arg_apparmor = 1;
apparmor_profile = argv[i] + 11;
}
else if (strncmp(argv[i], "--apparmor-replace", 18) == 0) {
arg_apparmor = 1;
apparmor_replace = true;
}
#endif
else if (strncmp(argv[i], "--protocol=", 11) == 0) {
if (checkcfg(CFG_SECCOMP)) {
Expand Down
16 changes: 16 additions & 0 deletions src/firejail/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,22 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
return 0;
}

if (strcmp(ptr, "apparmor-replace") == 0) {
#ifdef HAVE_APPARMOR
arg_apparmor = 1;
apparmor_replace = true;
#endif
return 0;
}

if (strcmp(ptr, "apparmor-stack") == 0) {
#ifdef HAVE_APPARMOR
arg_apparmor = 1;
apparmor_replace = false;
#endif
return 0;
}

if (strncmp(ptr, "protocol ", 9) == 0) {
if (checkcfg(CFG_SECCOMP)) {
const char *add = ptr + 9;
Expand Down
9 changes: 8 additions & 1 deletion src/firejail/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ static void set_caps(void) {
static void set_apparmor(void) {
EUID_ASSERT();
if (checkcfg(CFG_APPARMOR) && arg_apparmor) {
if (aa_stack_onexec(apparmor_profile)) {
int res = 0;
if(apparmor_replace){
fwarning("Replacing profile instead of stacking it. It is a legacy behavior that can result in relaxation of the protection. It is here as a temporary measure to unbreak the software that has been broken by switching to the stacking behavior.\n");
res = aa_change_onexec(apparmor_profile);
} else {
res = aa_stack_onexec(apparmor_profile);
}
if (res) {
fwarning("Cannot confine the application using AppArmor.\n"
"Maybe firejail-default AppArmor profile is not loaded into the kernel.\n"
"As root, run \"aa-enforce firejail-default\" to load it.\n");
Expand Down

0 comments on commit 900db66

Please # to comment.