aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build-extra.yml32
-rw-r--r--.github/workflows/build.yml12
-rw-r--r--.github/workflows/codeql-analysis.yml12
-rw-r--r--.github/workflows/profile-checks.yml2
-rw-r--r--.gitignore1
-rw-r--r--config.mk.in2
-rw-r--r--config.sh.in1
-rw-r--r--etc/profile-m-z/onionshare-gui.profile2
-rw-r--r--etc/profile-m-z/torbrowser-launcher.profile1
-rw-r--r--etc/profile-m-z/torbrowser.profile1
-rw-r--r--etc/profile-m-z/viewnior.profile1
-rw-r--r--m4/ax_check_compile_flag.m431
-rw-r--r--src/firejail/firejail.h1
-rw-r--r--src/firejail/fs_bin.c6
-rw-r--r--src/firejail/fs_var.c2
-rw-r--r--src/firejail/join.c30
-rw-r--r--src/firejail/main.c3
-rw-r--r--src/firejail/sandbox.c37
-rw-r--r--src/lib/ldd_utils.c2
-rw-r--r--test/Makefile2
-rwxr-xr-xtest/environment/dns.exp32
-rwxr-xr-xtest/sysutils/less.exp1
-rwxr-xr-xtest/utils/man.exp1
-rwxr-xr-xtest/utils/trace.exp4
24 files changed, 113 insertions, 106 deletions
diff --git a/.github/workflows/build-extra.yml b/.github/workflows/build-extra.yml
index 6f9a4bc2c..9296062c1 100644
--- a/.github/workflows/build-extra.yml
+++ b/.github/workflows/build-extra.yml
@@ -4,7 +4,10 @@ on:
4 push: 4 push:
5 branches: [ master ] 5 branches: [ master ]
6 paths-ignore: 6 paths-ignore:
7 - .git-blame-ignore-revs
8 - .gitignore
7 - CONTRIBUTING.md 9 - CONTRIBUTING.md
10 - COPYING
8 - README 11 - README
9 - README.md 12 - README.md
10 - RELNOTES 13 - RELNOTES
@@ -16,7 +19,10 @@ on:
16 pull_request: 19 pull_request:
17 branches: [ master ] 20 branches: [ master ]
18 paths-ignore: 21 paths-ignore:
22 - .git-blame-ignore-revs
23 - .gitignore
19 - CONTRIBUTING.md 24 - CONTRIBUTING.md
25 - COPYING
20 - README 26 - README
21 - README.md 27 - README.md
22 - RELNOTES 28 - RELNOTES
@@ -28,11 +34,13 @@ on:
28 34
29jobs: 35jobs:
30 build-clang: 36 build-clang:
31 runs-on: ubuntu-20.04 37 runs-on: ubuntu-22.04
32 steps: 38 steps:
33 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b 39 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
40 - name: install dependencies
41 run: sudo apt-get install libapparmor-dev libselinux1-dev
34 - name: configure 42 - name: configure
35 run: CC=clang-11 ./configure --enable-fatal-warnings 43 run: CC=clang-14 ./configure --enable-fatal-warnings --enable-apparmor --enable-selinux
36 - name: make 44 - name: make
37 run: make 45 run: make
38 - name: make install 46 - name: make install
@@ -40,16 +48,26 @@ jobs:
40 - name: print version 48 - name: print version
41 run: command -V firejail && firejail --version 49 run: command -V firejail && firejail --version
42 scan-build: 50 scan-build:
43 runs-on: ubuntu-20.04 51 runs-on: ubuntu-22.04
44 steps: 52 steps:
45 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b 53 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
46 - name: install clang-tools-11 54 - name: install clang-tools-14 and dependencies
47 run: sudo apt-get install clang-tools-11 55 run: sudo apt-get install clang-tools-14 libapparmor-dev libselinux1-dev
48 - name: configure 56 - name: configure
49 run: CC=clang-11 ./configure --enable-fatal-warnings 57 run: CC=clang-14 ./configure --enable-fatal-warnings --enable-apparmor --enable-selinux
50 - name: scan-build 58 - name: scan-build
51 run: NO_EXTRA_CFLAGS="yes" scan-build-11 --status-bugs make 59 run: NO_EXTRA_CFLAGS="yes" scan-build-14 --status-bugs make
52 cppcheck: 60 cppcheck:
61 runs-on: ubuntu-22.04
62 steps:
63 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
64 - name: install cppcheck
65 run: sudo apt-get install cppcheck
66 - name: cppcheck
67 run: cppcheck -q --force --error-exitcode=1 --enable=warning,performance -i src/firejail/checkcfg.c -i src/firejail/main.c .
68 # new cppcheck version currently chokes on checkcfg.c and main.c, therefore scan all files also
69 # with older cppcheck version from ubuntu 20.04.
70 cppcheck_old:
53 runs-on: ubuntu-20.04 71 runs-on: ubuntu-20.04
54 steps: 72 steps:
55 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b 73 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index cc7893305..3203e0677 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -4,7 +4,10 @@ on:
4 push: 4 push:
5 branches: [ master ] 5 branches: [ master ]
6 paths-ignore: 6 paths-ignore:
7 - .git-blame-ignore-revs
8 - .gitignore
7 - CONTRIBUTING.md 9 - CONTRIBUTING.md
10 - COPYING
8 - README 11 - README
9 - README.md 12 - README.md
10 - RELNOTES 13 - RELNOTES
@@ -12,7 +15,10 @@ on:
12 pull_request: 15 pull_request:
13 branches: [ master ] 16 branches: [ master ]
14 paths-ignore: 17 paths-ignore:
18 - .git-blame-ignore-revs
19 - .gitignore
15 - CONTRIBUTING.md 20 - CONTRIBUTING.md
21 - COPYING
16 - README 22 - README
17 - README.md 23 - README.md
18 - RELNOTES 24 - RELNOTES
@@ -20,15 +26,15 @@ on:
20 26
21jobs: 27jobs:
22 build_and_test: 28 build_and_test:
23 runs-on: ubuntu-20.04 29 runs-on: ubuntu-22.04
24 steps: 30 steps:
25 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b 31 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
26 - name: update package information 32 - name: update package information
27 run: sudo apt-get update 33 run: sudo apt-get update
28 - name: install dependencies 34 - name: install dependencies
29 run: sudo apt-get install gcc-11 libapparmor-dev libselinux1-dev expect xzdec 35 run: sudo apt-get install gcc-12 libapparmor-dev libselinux1-dev expect xzdec
30 - name: configure 36 - name: configure
31 run: CC=gcc-11 ./configure --enable-fatal-warnings --enable-analyzer --enable-apparmor --enable-selinux --prefix=/usr 37 run: CC=gcc-12 ./configure --enable-fatal-warnings --enable-analyzer --enable-apparmor --enable-selinux --prefix=/usr
32 - name: make 38 - name: make
33 run: make 39 run: make
34 - name: make install 40 - name: make install
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index d34a48aa3..4a09ad9d8 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -9,7 +9,10 @@ on:
9 push: 9 push:
10 branches: [ master ] 10 branches: [ master ]
11 paths-ignore: 11 paths-ignore:
12 - .git-blame-ignore-revs
13 - .gitignore
12 - CONTRIBUTING.md 14 - CONTRIBUTING.md
15 - COPYING
13 - README 16 - README
14 - README.md 17 - README.md
15 - RELNOTES 18 - RELNOTES
@@ -19,7 +22,10 @@ on:
19 # The branches below must be a subset of the branches above 22 # The branches below must be a subset of the branches above
20 branches: [ master ] 23 branches: [ master ]
21 paths-ignore: 24 paths-ignore:
25 - .git-blame-ignore-revs
26 - .gitignore
22 - CONTRIBUTING.md 27 - CONTRIBUTING.md
28 - COPYING
23 - README 29 - README
24 - README.md 30 - README.md
25 - RELNOTES 31 - RELNOTES
@@ -47,7 +53,7 @@ jobs:
47 53
48 # Initializes the CodeQL tools for scanning. 54 # Initializes the CodeQL tools for scanning.
49 - name: Initialize CodeQL 55 - name: Initialize CodeQL
50 uses: github/codeql-action/init@3f62b754e23e0dd60f91b744033e1dc1654c0ec6 56 uses: github/codeql-action/init@3e7e3b32d0fb8283594bb0a76cc60a00918b0969
51 with: 57 with:
52 languages: ${{ matrix.language }} 58 languages: ${{ matrix.language }}
53 # If you wish to specify custom queries, you can do so here or in a config file. 59 # If you wish to specify custom queries, you can do so here or in a config file.
@@ -58,7 +64,7 @@ jobs:
58 # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 64 # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
59 # If this step fails, then you should remove it and run the build manually (see below) 65 # If this step fails, then you should remove it and run the build manually (see below)
60 - name: Autobuild 66 - name: Autobuild
61 uses: github/codeql-action/autobuild@3f62b754e23e0dd60f91b744033e1dc1654c0ec6 67 uses: github/codeql-action/autobuild@3e7e3b32d0fb8283594bb0a76cc60a00918b0969
62 68
63 # ℹ️ Command-line programs to run using the OS shell. 69 # ℹ️ Command-line programs to run using the OS shell.
64 # 📚 https://git.io/JvXDl 70 # 📚 https://git.io/JvXDl
@@ -72,4 +78,4 @@ jobs:
72 # make release 78 # make release
73 79
74 - name: Perform CodeQL Analysis 80 - name: Perform CodeQL Analysis
75 uses: github/codeql-action/analyze@3f62b754e23e0dd60f91b744033e1dc1654c0ec6 81 uses: github/codeql-action/analyze@3e7e3b32d0fb8283594bb0a76cc60a00918b0969
diff --git a/.github/workflows/profile-checks.yml b/.github/workflows/profile-checks.yml
index 9138e8a57..d235aeb64 100644
--- a/.github/workflows/profile-checks.yml
+++ b/.github/workflows/profile-checks.yml
@@ -18,7 +18,7 @@ on:
18 18
19jobs: 19jobs:
20 profile-checks: 20 profile-checks:
21 runs-on: ubuntu-20.04 21 runs-on: ubuntu-latest
22 steps: 22 steps:
23 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b 23 - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
24 - name: sort.py 24 - name: sort.py
diff --git a/.gitignore b/.gitignore
index 66daccf5d..b5d29dc19 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@
10.directory 10.directory
11*.man 11*.man
12.vscode 12.vscode
13/firejail-*/
13autom4te.cache/ 14autom4te.cache/
14config.log 15config.log
15config.mk 16config.mk
diff --git a/config.mk.in b/config.mk.in
index e76b7ac34..e0be0e656 100644
--- a/config.mk.in
+++ b/config.mk.in
@@ -1,3 +1,5 @@
1# @configure_input@
2#
1# Configure-time variable definitions and any other common definition that can 3# Configure-time variable definitions and any other common definition that can
2# be safely included by all makefiles. 4# be safely included by all makefiles.
3# 5#
diff --git a/config.sh.in b/config.sh.in
index 28251b3d5..3d54ff189 100644
--- a/config.sh.in
+++ b/config.sh.in
@@ -1,2 +1,3 @@
1# @configure_input@
1NAME=@PACKAGE_NAME@ 2NAME=@PACKAGE_NAME@
2VERSION=@PACKAGE_VERSION@ 3VERSION=@PACKAGE_VERSION@
diff --git a/etc/profile-m-z/onionshare-gui.profile b/etc/profile-m-z/onionshare-gui.profile
index fbf4c3ef0..db923056a 100644
--- a/etc/profile-m-z/onionshare-gui.profile
+++ b/etc/profile-m-z/onionshare-gui.profile
@@ -11,6 +11,8 @@ noblacklist ${HOME}/.config/onionshare
11# Allow python (blacklisted by disable-interpreters.inc) 11# Allow python (blacklisted by disable-interpreters.inc)
12include allow-python3.inc 12include allow-python3.inc
13 13
14blacklist /sys/class/net
15
14include disable-common.inc 16include disable-common.inc
15include disable-devel.inc 17include disable-devel.inc
16include disable-exec.inc 18include disable-exec.inc
diff --git a/etc/profile-m-z/torbrowser-launcher.profile b/etc/profile-m-z/torbrowser-launcher.profile
index 700a10be8..9d66c5fa4 100644
--- a/etc/profile-m-z/torbrowser-launcher.profile
+++ b/etc/profile-m-z/torbrowser-launcher.profile
@@ -16,6 +16,7 @@ include allow-python2.inc
16include allow-python3.inc 16include allow-python3.inc
17 17
18blacklist /srv 18blacklist /srv
19blacklist /sys/class/net
19 20
20include disable-common.inc 21include disable-common.inc
21include disable-devel.inc 22include disable-devel.inc
diff --git a/etc/profile-m-z/torbrowser.profile b/etc/profile-m-z/torbrowser.profile
index fc579b973..15ca5b550 100644
--- a/etc/profile-m-z/torbrowser.profile
+++ b/etc/profile-m-z/torbrowser.profile
@@ -13,6 +13,7 @@ noblacklist ${HOME}/.cache/mozilla
13noblacklist ${HOME}/.mozilla 13noblacklist ${HOME}/.mozilla
14 14
15blacklist /usr/libexec 15blacklist /usr/libexec
16blacklist /sys/class/net
16 17
17mkdir ${HOME}/.cache/mozilla/torbrowser 18mkdir ${HOME}/.cache/mozilla/torbrowser
18mkdir ${HOME}/.mozilla 19mkdir ${HOME}/.mozilla
diff --git a/etc/profile-m-z/viewnior.profile b/etc/profile-m-z/viewnior.profile
index 47e618ae2..6d7fa94e7 100644
--- a/etc/profile-m-z/viewnior.profile
+++ b/etc/profile-m-z/viewnior.profile
@@ -19,6 +19,7 @@ include disable-interpreters.inc
19include disable-programs.inc 19include disable-programs.inc
20include disable-shell.inc 20include disable-shell.inc
21 21
22whitelist /usr/share/viewnior
22include whitelist-usr-share-common.inc 23include whitelist-usr-share-common.inc
23include whitelist-var-common.inc 24include whitelist-var-common.inc
24 25
diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4
index dcabb92a1..bd753b34d 100644
--- a/m4/ax_check_compile_flag.m4
+++ b/m4/ax_check_compile_flag.m4
@@ -29,33 +29,12 @@
29# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de> 29# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
30# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com> 30# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
31# 31#
32# This program is free software: you can redistribute it and/or modify it 32# Copying and distribution of this file, with or without modification, are
33# under the terms of the GNU General Public License as published by the 33# permitted in any medium without royalty provided the copyright notice
34# Free Software Foundation, either version 3 of the License, or (at your 34# and this notice are preserved. This file is offered as-is, without any
35# option) any later version. 35# warranty.
36#
37# This program is distributed in the hope that it will be useful, but
38# WITHOUT ANY WARRANTY; without even the implied warranty of
39# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
40# Public License for more details.
41#
42# You should have received a copy of the GNU General Public License along
43# with this program. If not, see <https://www.gnu.org/licenses/>.
44#
45# As a special exception, the respective Autoconf Macro's copyright owner
46# gives unlimited permission to copy, distribute and modify the configure
47# scripts that are the output of Autoconf when processing the Macro. You
48# need not follow the terms of the GNU General Public License when using
49# or distributing such scripts, even though portions of the text of the
50# Macro appear in them. The GNU General Public License (GPL) does govern
51# all other use of the material that constitutes the Autoconf Macro.
52#
53# This special exception to the GPL applies to versions of the Autoconf
54# Macro released by the Autoconf Archive. When you make and distribute a
55# modified version of the Autoconf Macro, you may extend this special
56# exception to the GPL to apply to your modified version as well.
57 36
58#serial 5 37#serial 6
59 38
60AC_DEFUN([AX_CHECK_COMPILE_FLAG], 39AC_DEFUN([AX_CHECK_COMPILE_FLAG],
61[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 40[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h
index b744ebd45..167b6a843 100644
--- a/src/firejail/firejail.h
+++ b/src/firejail/firejail.h
@@ -386,7 +386,6 @@ char *guess_shell(void);
386#define SANDBOX_DONE '1' 386#define SANDBOX_DONE '1'
387int sandbox(void* sandbox_arg); 387int sandbox(void* sandbox_arg);
388void start_application(int no_sandbox, int fd, char *set_sandbox_status) __attribute__((noreturn)); 388void start_application(int no_sandbox, int fd, char *set_sandbox_status) __attribute__((noreturn));
389void set_apparmor(void);
390 389
391// network_main.c 390// network_main.c
392void net_configure_sandbox_ip(Bridge *br); 391void net_configure_sandbox_ip(Bridge *br);
diff --git a/src/firejail/fs_bin.c b/src/firejail/fs_bin.c
index 2b0b3003e..6228e9740 100644
--- a/src/firejail/fs_bin.c
+++ b/src/firejail/fs_bin.c
@@ -27,7 +27,7 @@
27 27
28static int prog_cnt = 0; 28static int prog_cnt = 0;
29 29
30static char *paths[] = { 30static const char * const paths[] = {
31 "/usr/local/bin", 31 "/usr/local/bin",
32 "/usr/bin", 32 "/usr/bin",
33 "/bin", 33 "/bin",
@@ -40,7 +40,7 @@ static char *paths[] = {
40}; 40};
41 41
42// return 1 if found, 0 if not found 42// return 1 if found, 0 if not found
43static char *check_dir_or_file(const char *name) { 43static const char *check_dir_or_file(const char *name) {
44 EUID_ASSERT(); 44 EUID_ASSERT();
45 assert(name); 45 assert(name);
46 struct stat s; 46 struct stat s;
@@ -160,7 +160,7 @@ static void duplicate(char *fname) {
160 else { 160 else {
161 // Find the standard directory (by looping through paths[]) 161 // Find the standard directory (by looping through paths[])
162 // where the filename fname is located 162 // where the filename fname is located
163 char *path = check_dir_or_file(fname); 163 const char *path = check_dir_or_file(fname);
164 if (!path) 164 if (!path)
165 return; 165 return;
166 if (asprintf(&full_path, "%s/%s", path, fname) == -1) 166 if (asprintf(&full_path, "%s/%s", path, fname) == -1)
diff --git a/src/firejail/fs_var.c b/src/firejail/fs_var.c
index 9523875d7..ad5ee6759 100644
--- a/src/firejail/fs_var.c
+++ b/src/firejail/fs_var.c
@@ -300,7 +300,7 @@ void fs_var_utmp(void) {
300 300
301 // read current utmp 301 // read current utmp
302 struct utmp *u; 302 struct utmp *u;
303 struct utmp u_boot; 303 struct utmp u_boot = {0};
304 setutent(); 304 setutent();
305 while ((u = getutent()) != NULL) { 305 while ((u = getutent()) != NULL) {
306 if (u->ut_type == BOOT_TIME) { 306 if (u->ut_type == BOOT_TIME) {
diff --git a/src/firejail/join.c b/src/firejail/join.c
index ec9c922ef..96d891a49 100644
--- a/src/firejail/join.c
+++ b/src/firejail/join.c
@@ -33,10 +33,6 @@
33#define PR_SET_NO_NEW_PRIVS 38 33#define PR_SET_NO_NEW_PRIVS 38
34#endif 34#endif
35 35
36#ifdef HAVE_APPARMOR
37#include <sys/apparmor.h>
38#endif
39
40static int apply_caps = 0; 36static int apply_caps = 0;
41static uint64_t caps = 0; 37static uint64_t caps = 0;
42static unsigned display = 0; 38static unsigned display = 0;
@@ -137,6 +133,8 @@ static void extract_nogroups(ProcessHandle sandbox) {
137 133
138 if (process_rootfs_stat(sandbox, RUN_GROUPS_CFG, &s) == 0) 134 if (process_rootfs_stat(sandbox, RUN_GROUPS_CFG, &s) == 0)
139 arg_nogroups = 1; 135 arg_nogroups = 1;
136 else if (errno != ENOENT)
137 errExit("stat");
140} 138}
141 139
142static void extract_nonewprivs(ProcessHandle sandbox) { 140static void extract_nonewprivs(ProcessHandle sandbox) {
@@ -144,6 +142,8 @@ static void extract_nonewprivs(ProcessHandle sandbox) {
144 142
145 if (process_rootfs_stat(sandbox, RUN_NONEWPRIVS_CFG, &s) == 0) 143 if (process_rootfs_stat(sandbox, RUN_NONEWPRIVS_CFG, &s) == 0)
146 arg_nonewprivs = 1; 144 arg_nonewprivs = 1;
145 else if (errno != ENOENT)
146 errExit("stat");
147} 147}
148 148
149static void extract_caps(ProcessHandle sandbox) { 149static void extract_caps(ProcessHandle sandbox) {
@@ -481,13 +481,6 @@ void join(pid_t pid, int argc, char **argv, int index) {
481 EUID_USER(); 481 EUID_USER();
482 unpin_process(sandbox); 482 unpin_process(sandbox);
483 483
484 // set nonewprivs
485 if (arg_nonewprivs == 1) { // not available for uid 0
486 int rv = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
487 if (arg_debug && rv == 0)
488 printf("NO_NEW_PRIVS set\n");
489 }
490
491 int cwd = 0; 484 int cwd = 0;
492 if (cfg.cwd) { 485 if (cfg.cwd) {
493 if (chdir(cfg.cwd) == 0) 486 if (chdir(cfg.cwd) == 0)
@@ -507,16 +500,23 @@ void join(pid_t pid, int argc, char **argv, int index) {
507 } 500 }
508 } 501 }
509 502
503 // set nonewprivs
504#ifndef HAVE_FORCE_NONEWPRIVS
505 if (arg_nonewprivs == 1) // not available for uid 0
506#endif
507 {
508 if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0)
509 errExit("prctl");
510 if (arg_debug)
511 printf("NO_NEW_PRIVS set\n");
512 }
513
510 // drop privileges 514 // drop privileges
511 drop_privs(arg_nogroups); 515 drop_privs(arg_nogroups);
512 516
513 // kill the child in case the parent died 517 // kill the child in case the parent died
514 prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); 518 prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
515 519
516#ifdef HAVE_APPARMOR
517 set_apparmor();
518#endif
519
520 extract_command(argc, argv, index); 520 extract_command(argc, argv, index);
521 if (cfg.command_line == NULL) 521 if (cfg.command_line == NULL)
522 cfg.window_title = cfg.usershell; 522 cfg.window_title = cfg.usershell;
diff --git a/src/firejail/main.c b/src/firejail/main.c
index 5a7254de2..55f623138 100644
--- a/src/firejail/main.c
+++ b/src/firejail/main.c
@@ -1239,7 +1239,8 @@ int main(int argc, char **argv, char **envp) {
1239 if (check_arg(argc, argv, "--appimage", 1)) 1239 if (check_arg(argc, argv, "--appimage", 1))
1240 arg_appimage = 1; 1240 arg_appimage = 1;
1241 1241
1242 // check for force-nonewprivs in /etc/firejail/firejail.config file 1242 // load configuration file /etc/firejail/firejail.config
1243 // and check for force-nonewprivs
1243 if (checkcfg(CFG_FORCE_NONEWPRIVS)) 1244 if (checkcfg(CFG_FORCE_NONEWPRIVS))
1244 arg_nonewprivs = 1; 1245 arg_nonewprivs = 1;
1245 1246
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c
index 507e916c8..b1b3407b4 100644
--- a/src/firejail/sandbox.c
+++ b/src/firejail/sandbox.c
@@ -50,7 +50,6 @@
50#include <sys/apparmor.h> 50#include <sys/apparmor.h>
51#endif 51#endif
52 52
53static int force_nonewprivs = 0;
54extern int just_run_the_shell; 53extern int just_run_the_shell;
55 54
56static int monitored_pid = 0; 55static int monitored_pid = 0;
@@ -128,7 +127,7 @@ static void set_caps(void) {
128} 127}
129 128
130#ifdef HAVE_APPARMOR 129#ifdef HAVE_APPARMOR
131void set_apparmor(void) { 130static void set_apparmor(void) {
132 EUID_ASSERT(); 131 EUID_ASSERT();
133 if (checkcfg(CFG_APPARMOR) && arg_apparmor) { 132 if (checkcfg(CFG_APPARMOR) && arg_apparmor) {
134 if (aa_change_onexec("firejail-default")) { 133 if (aa_change_onexec("firejail-default")) {
@@ -486,6 +485,9 @@ static void close_file_descriptors(void) {
486 485
487void start_application(int no_sandbox, int fd, char *set_sandbox_status) { 486void start_application(int no_sandbox, int fd, char *set_sandbox_status) {
488 if (no_sandbox == 0) { 487 if (no_sandbox == 0) {
488#ifdef HAVE_APPARMOR
489 set_apparmor();
490#endif
489 close_file_descriptors(); 491 close_file_descriptors();
490 492
491 // set nice and rlimits 493 // set nice and rlimits
@@ -626,7 +628,6 @@ static void enforce_filters(void) {
626 fmessage("\n** Warning: dropping all Linux capabilities and setting NO_NEW_PRIVS prctl **\n\n"); 628 fmessage("\n** Warning: dropping all Linux capabilities and setting NO_NEW_PRIVS prctl **\n\n");
627 // enforce NO_NEW_PRIVS 629 // enforce NO_NEW_PRIVS
628 arg_nonewprivs = 1; 630 arg_nonewprivs = 1;
629 force_nonewprivs = 1;
630 631
631 // disable all capabilities 632 // disable all capabilities
632 arg_caps_drop_all = 1; 633 arg_caps_drop_all = 1;
@@ -829,14 +830,9 @@ int sandbox(void* sandbox_arg) {
829 exit(rv); 830 exit(rv);
830 } 831 }
831 832
832#ifdef HAVE_FORCE_NONEWPRIVS
833 bool always_enforce_filters = true;
834#else
835 bool always_enforce_filters = false;
836#endif
837 // for --appimage, --chroot and --overlay* we force NO_NEW_PRIVS 833 // for --appimage, --chroot and --overlay* we force NO_NEW_PRIVS
838 // and drop all capabilities 834 // and drop all capabilities
839 if (getuid() != 0 && (arg_appimage || cfg.chrootdir || arg_overlay || always_enforce_filters)) 835 if (getuid() != 0 && (arg_appimage || cfg.chrootdir || arg_overlay))
840 enforce_filters(); 836 enforce_filters();
841 837
842 // need ld.so.preload if tracing or seccomp with any non-default lists 838 // need ld.so.preload if tracing or seccomp with any non-default lists
@@ -1273,17 +1269,15 @@ int sandbox(void* sandbox_arg) {
1273 //**************************************** 1269 //****************************************
1274 // Set NO_NEW_PRIVS if desired 1270 // Set NO_NEW_PRIVS if desired
1275 //**************************************** 1271 //****************************************
1276 if (arg_nonewprivs) { 1272#ifndef HAVE_FORCE_NONEWPRIVS
1277 prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); 1273 if (arg_nonewprivs)
1278 1274#endif
1279 if (prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0) != 1) { 1275 {
1280 fwarning("cannot set NO_NEW_PRIVS, it requires a Linux kernel version 3.5 or newer.\n"); 1276 if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0) {
1281 if (force_nonewprivs) { 1277 fprintf(stderr, "Error: cannot set NO_NEW_PRIVS, it requires a Linux kernel version 3.5 or newer.\n");
1282 fprintf(stderr, "Error: NO_NEW_PRIVS required for this sandbox, exiting ...\n"); 1278 exit(1);
1283 exit(1);
1284 }
1285 } 1279 }
1286 else if (arg_debug) 1280 if (arg_debug)
1287 printf("NO_NEW_PRIVS set\n"); 1281 printf("NO_NEW_PRIVS set\n");
1288 } 1282 }
1289 1283
@@ -1309,10 +1303,7 @@ int sandbox(void* sandbox_arg) {
1309 errExit("fork"); 1303 errExit("fork");
1310 1304
1311 if (app_pid == 0) { 1305 if (app_pid == 0) {
1312#ifdef HAVE_APPARMOR 1306 start_application(0, -1, set_sandbox_status); // this function does not return
1313 set_apparmor();
1314#endif
1315 start_application(0, -1, set_sandbox_status);
1316 } 1307 }
1317 1308
1318 munmap(set_sandbox_status, 1); 1309 munmap(set_sandbox_status, 1);
diff --git a/src/lib/ldd_utils.c b/src/lib/ldd_utils.c
index bc4f7cf9c..a50b759c3 100644
--- a/src/lib/ldd_utils.c
+++ b/src/lib/ldd_utils.c
@@ -47,7 +47,7 @@ int is_lib_64(const char *exe) {
47 if (fd < 0) 47 if (fd < 0)
48 return 0; 48 return 0;
49 49
50 unsigned char buf[EI_NIDENT]; 50 unsigned char buf[EI_NIDENT] = {0};
51 ssize_t len = 0; 51 ssize_t len = 0;
52 while (len < EI_NIDENT) { 52 while (len < EI_NIDENT) {
53 ssize_t sz = read(fd, buf + len, EI_NIDENT - len); 53 ssize_t sz = read(fd, buf + len, EI_NIDENT - len);
diff --git a/test/Makefile b/test/Makefile
index 2f3a97d73..2c376da58 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -3,7 +3,7 @@ TESTS=$(patsubst %/,%,$(wildcard */))
3.PHONY: $(TESTS) 3.PHONY: $(TESTS)
4$(TESTS): 4$(TESTS):
5 cd $@ && ./$@.sh 2>&1 | tee $@.log 5 cd $@ && ./$@.sh 2>&1 | tee $@.log
6 cd $@ && grep -a TESTING $@.log && grep -a -L "TESTING ERROR" $@.log 6 cd $@ && grep -a TESTING $@.log && ! grep -a -q "TESTING ERROR" $@.log
7 7
8.PHONY: clean 8.PHONY: clean
9clean: 9clean:
diff --git a/test/environment/dns.exp b/test/environment/dns.exp
index b5a8c119b..2c00cfa1c 100755
--- a/test/environment/dns.exp
+++ b/test/environment/dns.exp
@@ -110,23 +110,23 @@ expect {
110send -- "exit\r" 110send -- "exit\r"
111sleep 1 111sleep 1
112 112
113send -- "firejail --trace --dns=208.67.222.222 wget -q debian.org\r" 113# test disabled, as Github CI uses systemd-resolved, which does not work
114expect { 114# properly with --dns=, so curl does not use the specified nameserver
115 timeout {puts "TESTING ERROR 6.1\n";exit} 115#send -- "firejail --trace --dns=208.67.222.222 -- curl --silent --output /dev/null debian.org\r"
116 "connect" 116#expect {
117} 117# timeout {puts "TESTING ERROR 6.1\n";exit}
118expect { 118# "connect"
119 timeout {puts "TESTING ERROR 6.2\n";exit} 119#}
120 "208.67.222.222" 120#expect {
121} 121# timeout {puts "TESTING ERROR 6.2\n";exit}
122expect { 122# "208.67.222.222"
123 timeout {puts "TESTING ERROR 6.3\n";exit} 123#}
124 "53" 124#expect {
125} 125# timeout {puts "TESTING ERROR 6.3\n";exit}
126after 100 126# "53"
127#}
128#after 100
127 129
128send -- "rm index.html\r"
129after 100
130send -- "exit\r" 130send -- "exit\r"
131sleep 1 131sleep 1
132 132
diff --git a/test/sysutils/less.exp b/test/sysutils/less.exp
index e6698eab0..01a298fe0 100755
--- a/test/sysutils/less.exp
+++ b/test/sysutils/less.exp
@@ -11,6 +11,7 @@ send -- "firejail less sysutils.sh\r"
11expect { 11expect {
12 timeout {puts "TESTING ERROR 1\n";exit} 12 timeout {puts "TESTING ERROR 1\n";exit}
13 "(press RETURN)" {puts "TESTING SKIP 1.1\n";exit} 13 "(press RETURN)" {puts "TESTING SKIP 1.1\n";exit}
14 "Press RETURN to continue" {puts "TESTING SKIP 1.2\n";exit}
14 "MALLOC_CHECK" 15 "MALLOC_CHECK"
15} 16}
16expect { 17expect {
diff --git a/test/utils/man.exp b/test/utils/man.exp
index 3a0ca46d6..f62859a8f 100755
--- a/test/utils/man.exp
+++ b/test/utils/man.exp
@@ -11,6 +11,7 @@ send -- "man firejail\r"
11expect { 11expect {
12 timeout {puts "TESTING ERROR 0\n";exit} 12 timeout {puts "TESTING ERROR 0\n";exit}
13 "(press RETURN)" {puts "TESTING SKIP 1.1\n";exit} 13 "(press RETURN)" {puts "TESTING SKIP 1.1\n";exit}
14 "Press RETURN to continue" {puts "TESTING SKIP 1.2\n";exit}
14 "Linux namespaces sandbox program" 15 "Linux namespaces sandbox program"
15} 16}
16after 100 17after 100
diff --git a/test/utils/trace.exp b/test/utils/trace.exp
index f14001c88..beb59d337 100755
--- a/test/utils/trace.exp
+++ b/test/utils/trace.exp
@@ -68,10 +68,6 @@ expect {
68 "wget:fopen /etc/wgetrc" {puts "OK\n";} 68 "wget:fopen /etc/wgetrc" {puts "OK\n";}
69} 69}
70expect { 70expect {
71 timeout {puts "TESTING ERROR 8.4\n";exit}
72 "wget:fopen /etc/hosts"
73}
74expect {
75 timeout {puts "TESTING ERROR 8.5\n";exit} 71 timeout {puts "TESTING ERROR 8.5\n";exit}
76 "wget:connect" 72 "wget:connect"
77} 73}