Skip to content

Commit 5f36f03

Browse files
committed
feature: build: add --disable-sandbox-check configure flag
This flag disables the code which checks whether the current instance of firejail is running within a sandbox like LXC, chroot or firejail itself. If we want to develop firejail inside of a sandbox, to keep the "host system" clean of unnecessary installed dependencies and changes to the system, we might want to force firejail to run normally, so that we can test different profiles inside of the sandbox. This is only meant for people who are working on the firejail code, not someone attempting to run firejail inside of a sandbox as a user, because it needs to run as root and it can escape the sandbox easily.
1 parent 102d760 commit 5f36f03

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

config.mk.in

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ HAVE_OUTPUT=@HAVE_OUTPUT@
4444
HAVE_OVERLAYFS=@HAVE_OVERLAYFS@
4545
HAVE_PRIVATE_HOME=@HAVE_PRIVATE_HOME@
4646
HAVE_PRIVATE_LIB=@HAVE_PRIVATE_LIB@
47+
HAVE_SANDBOX_CHECK=@HAVE_SANDBOX_CHECK@
4748
HAVE_SELINUX=@HAVE_SELINUX@
4849
HAVE_SUID=@HAVE_SUID@
4950
HAVE_USERNS=@HAVE_USERNS@
@@ -65,6 +66,7 @@ MANFLAGS = \
6566
$(HAVE_OVERLAYFS) \
6667
$(HAVE_PRIVATE_HOME) \
6768
$(HAVE_PRIVATE_LIB) \
69+
$(HAVE_SANDBOX_CHECK) \
6870
$(HAVE_SELINUX) \
6971
$(HAVE_SUID) \
7072
$(HAVE_USERNS) \

configure

+21
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ PKG_CONFIG_PATH
674674
PKG_CONFIG
675675
HAVE_APPARMOR
676676
HAVE_IDS
677+
HAVE_SANDBOX_CHECK
677678
DEPS_CFLAGS
678679
TAR
679680
STRIP
@@ -733,6 +734,7 @@ ac_user_opts='
733734
enable_option_checking
734735
enable_analyzer
735736
enable_sanitizer
737+
enable_sandbox_check
736738
enable_ids
737739
enable_apparmor
738740
enable_selinux
@@ -1391,6 +1393,9 @@ Optional Features:
13911393
--enable-analyzer enable GCC static analyzer
13921394
--enable-sanitizer=[address | memory | undefined]
13931395
enable a compiler-based sanitizer (debug)
1396+
--disable-sandbox-check checking if current instance of firejail is running
1397+
within a sandbox is disabled, only use this when
1398+
developing firejail inside of a sandbox
13941399
--enable-ids enable ids
13951400
--enable-apparmor enable apparmor
13961401
--enable-selinux SELinux labeling support
@@ -3955,6 +3960,21 @@ esac
39553960
fi
39563961

39573962

3963+
fi
3964+
3965+
HAVE_SANDBOX_CHECK=""
3966+
3967+
# Check whether --enable-sandbox-check was given.
3968+
if test ${enable_sandbox_check+y}
3969+
then :
3970+
enableval=$enable_sandbox_check;
3971+
fi
3972+
3973+
if test "x$enable_sandbox_check" != "xno"
3974+
then :
3975+
3976+
HAVE_SANDBOX_CHECK="-DHAVE_SANDBOX_CHECK"
3977+
39583978
fi
39593979

39603980
HAVE_IDS=""
@@ -5793,6 +5813,7 @@ Features:
57935813
overlayfs support: $HAVE_OVERLAYFS
57945814
private home support: $HAVE_PRIVATE_HOME
57955815
private lib support: $HAVE_PRIVATE_LIB
5816+
sandbox check: $HAVE_SANDBOX_CHECK
57965817
SELinux labeling support: $HAVE_SELINUX
57975818
user namespace: $HAVE_USERNS
57985819
X11 sandboxing support: $HAVE_X11

configure.ac

+9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ AS_IF([test "x$enable_sanitizer" != "xno" ], [
6969
], [AC_MSG_ERROR([sanitizer not supported: $enable_sanitizer])])
7070
])
7171

72+
HAVE_SANDBOX_CHECK=""
73+
AC_SUBST([HAVE_SANDBOX_CHECK])
74+
AC_ARG_ENABLE([sandbox-check],
75+
[AS_HELP_STRING([--disable-sandbox-check], [checking if current instance of firejail is running within a sandbox is disabled, only use this when developing firejail inside of a sandbox])])
76+
AS_IF([test "x$enable_sandbox_check" != "xno"], [
77+
HAVE_SANDBOX_CHECK="-DHAVE_SANDBOX_CHECK"
78+
])
79+
7280
HAVE_IDS=""
7381
AC_SUBST([HAVE_IDS])
7482
AC_ARG_ENABLE([ids],
@@ -324,6 +332,7 @@ Features:
324332
overlayfs support: $HAVE_OVERLAYFS
325333
private home support: $HAVE_PRIVATE_HOME
326334
private lib support: $HAVE_PRIVATE_LIB
335+
sandbox check: $HAVE_SANDBOX_CHECK
327336
SELinux labeling support: $HAVE_SELINUX
328337
user namespace: $HAVE_USERNS
329338
X11 sandboxing support: $HAVE_X11

src/firejail/main.c

+2
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ int main(int argc, char **argv, char **envp) {
11301130
// If LXC is detected, start firejail sandbox
11311131
// otherwise try to detect a PID namespace by looking under /proc for specific kernel processes and:
11321132
// - start the application in a /bin/bash shell
1133+
#ifdef HAVE_SANDBOX_CHECK
11331134
if (check_namespace_virt() == 0) {
11341135
EUID_ROOT();
11351136
int rv = check_kernel_procs();
@@ -1145,6 +1146,7 @@ int main(int argc, char **argv, char **envp) {
11451146
__builtin_unreachable();
11461147
}
11471148
}
1149+
#endif
11481150

11491151
// profile builder
11501152
if (check_arg(argc, argv, "--build", 0)) // supports both --build and --build=filename

0 commit comments

Comments
 (0)