Skip to content
New issue

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

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

Already on GitHub? # to your account

Add --apparmor-replace (workaround for apparmor profile stacking bug) #5475

Merged
merged 1 commit into from
Jan 4, 2023
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
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