[GH-ISSUE #2029] Possible conflict with noexec and whitelist #1367

Closed
opened 2026-05-05 07:56:51 -06:00 by gitea-mirror · 8 comments
Owner

Originally created by @Fred-Barclay on GitHub (Jul 5, 2018).
Original GitHub issue: https://github.com/netblue30/firejail/issues/2029

Related to #839 and #1628, but this doesn't require read-only while they do.

  1. Whitelist an executable file
  2. Apply noexec to a parent directory, but without wildcards. For example, noexec ${HOME}.
  3. If you run the file inside firejail, it will be executed despite noexec.

For example, I've created ~/Desktop/test.sh with the following contents:

echo "this file is being executed"

~/Desktop/test.profile:

whitelist ${HOME}/Desktop/test.sh
noexec ${HOME}

It's being executed when I run it in firejail:

$ firejail --profile=/home/fred/Desktop/test.profile /home/fred/Desktop/test.sh
Reading profile /home/fred/Desktop/test.profile
Parent pid 16967, child pid 16968
Child process initialized in 31.97 ms
this file is being executed

Parent is shutting down, bye...

Order of operations doesn't matter either -- putting noexec ${HOME} before the whitelist still allows execution.

There are a few ways to keep the file from being executed. Using wildcards prevents execution; noexec ${HOME}/Desktop/* and noexec ${HOME}/*/* both work in this case, although noexec ${HOME}/Desktop/ allows execution.

Also, noexec works as expected if there are no whitelists in the sandbox (or, naturally, if the executable isn't whitelisted).

EDIT: --debug output:

$ firejail --debug --profile=/home/fred/Desktop/test.profile /home/fred/Desktop/test.sh
Reading profile /home/fred/Desktop/test.profile
Autoselecting /bin/bash as shell
Building quoted command line: '/home/fred/Desktop/test.sh' 
Command name #test.sh#
DISPLAY=:0 parsed as 0
Using the local network stack
Parent pid 17466, child pid 17467
Initializing child process
Host network configured
PID namespace installed
Mounting tmpfs on /run/firejail/mnt directory
Creating empty /run/firejail/mnt/seccomp.protocol file
Creating empty /run/firejail/mnt/seccomp.postexec file
Mounting read-only /bin, /sbin, /lib, /lib32, /lib64, /usr, /etc, /var
Mounting tmpfs on /var/lock
Mounting tmpfs on /var/tmp
Mounting tmpfs on /var/log
Create the new utmp file
Mount the new utmp file
Cleaning /home directory
Sanitizing /etc/passwd, UID_MIN 1000
Sanitizing /etc/group, GID_MIN 1000
Disable /home/fred/.config/firejail
Disable /run/firejail/network
Disable /run/firejail/bandwidth
Disable /run/firejail/name
Disable /run/firejail/x11
Remounting /proc and /proc/sys filesystems
Remounting /sys directory
Disable /sys/firmware
Disable /sys/hypervisor
Disable /sys/power
Disable /sys/kernel/debug
Disable /sys/kernel/vmcoreinfo
Disable /proc/sys/fs/binfmt_misc
Disable /proc/sys/kernel/core_pattern
Disable /proc/sys/kernel/modprobe
Disable /proc/sysrq-trigger
Disable /proc/sys/vm/panic_on_oom
Disable /proc/irq
Disable /proc/bus
Disable /proc/config.gz
Disable /proc/sched_debug
Disable /proc/timer_list
Disable /proc/kcore
Disable /proc/kallsyms
Disable /usr/lib/modules (requested /lib/modules)
Disable /boot
Disable /dev/port
Disable /run/user/1000/gnupg
Disable /run/user/1000/systemd
Disable /dev/kmsg
Disable /proc/kmsg
Debug 443: new_name #/home/fred/Desktop/test.sh#, whitelist
Debug 544: fname #/home/fred/Desktop/test.sh#, cfg.homedir #/home/fred#
Replaced whitelist path: whitelist /home/fred/Desktop/test.sh
Drop privileges: pid 2, uid 1000, gid 1000, nogroups 0
Mounting a new /home directory
Mounting a new /root directory
Create a new user directory
Drop privileges: pid 3, uid 1000, gid 1000, nogroups 0
Drop privileges: pid 4, uid 1000, gid 1000, nogroups 0
Whitelisting /home/fred/Desktop/test.sh
1021 1019 8:3 /fred/Desktop/test.sh /home/fred/Desktop/test.sh rw,relatime master:38 - ext4 /dev/sda3 rw,data=ordered
fsname=/fred/Desktop/test.sh dir=/home/fred/Desktop/test.sh fstype=ext4
Mounting noexec /home/fred
Disable /sys/fs
Disable /sys/module
Drop privileges: pid 5, uid 1000, gid 1000, nogroups 0
Drop privileges: pid 6, uid 1000, gid 1000, nogroups 0
1026 1019 0:96 /pulse /home/fred/.config/pulse rw,nosuid,nodev,noexec - tmpfs tmpfs rw,mode=755
fsname=/pulse dir=/home/fred/.config/pulse fstype=tmpfs
Current directory: /home/fred/Desktop
DISPLAY=:0 parsed as 0
Drop privileges: pid 1, uid 1000, gid 1000, nogroups 0
starting application
LD_PRELOAD=(null)
Running '/home/fred/Desktop/test.sh'  command through /bin/bash
execvp argument 0: /bin/bash
execvp argument 1: -c
execvp argument 2: '/home/fred/Desktop/test.sh' 
Child process initialized in 19.90 ms
this file is being executed
monitoring pid 7

Sandbox monitor: waitpid 7 retval 7 status 0

Parent is shutting down, bye...
Originally created by @Fred-Barclay on GitHub (Jul 5, 2018). Original GitHub issue: https://github.com/netblue30/firejail/issues/2029 Related to #839 and #1628, but this doesn't require `read-only` while they do. 1. Whitelist an executable file 2. Apply `noexec` to a parent directory, but without wildcards. For example, `noexec ${HOME}`. 3. If you run the file inside firejail, it will be executed despite `noexec`. For example, I've created ~/Desktop/test.sh with the following contents: ``` echo "this file is being executed" ``` ~/Desktop/test.profile: ``` whitelist ${HOME}/Desktop/test.sh noexec ${HOME} ``` It's being executed when I run it in firejail: ``` $ firejail --profile=/home/fred/Desktop/test.profile /home/fred/Desktop/test.sh Reading profile /home/fred/Desktop/test.profile Parent pid 16967, child pid 16968 Child process initialized in 31.97 ms this file is being executed Parent is shutting down, bye... ``` Order of operations doesn't matter either -- putting `noexec ${HOME}` before the whitelist still allows execution. There are a few ways to keep the file from being executed. Using wildcards prevents execution; `noexec ${HOME}/Desktop/*` and `noexec ${HOME}/*/*` both work in this case, although `noexec ${HOME}/Desktop/` allows execution. Also, `noexec` works as expected if there are no whitelists in the sandbox (or, naturally, if the executable isn't whitelisted). EDIT: `--debug` output: ``` $ firejail --debug --profile=/home/fred/Desktop/test.profile /home/fred/Desktop/test.sh Reading profile /home/fred/Desktop/test.profile Autoselecting /bin/bash as shell Building quoted command line: '/home/fred/Desktop/test.sh' Command name #test.sh# DISPLAY=:0 parsed as 0 Using the local network stack Parent pid 17466, child pid 17467 Initializing child process Host network configured PID namespace installed Mounting tmpfs on /run/firejail/mnt directory Creating empty /run/firejail/mnt/seccomp.protocol file Creating empty /run/firejail/mnt/seccomp.postexec file Mounting read-only /bin, /sbin, /lib, /lib32, /lib64, /usr, /etc, /var Mounting tmpfs on /var/lock Mounting tmpfs on /var/tmp Mounting tmpfs on /var/log Create the new utmp file Mount the new utmp file Cleaning /home directory Sanitizing /etc/passwd, UID_MIN 1000 Sanitizing /etc/group, GID_MIN 1000 Disable /home/fred/.config/firejail Disable /run/firejail/network Disable /run/firejail/bandwidth Disable /run/firejail/name Disable /run/firejail/x11 Remounting /proc and /proc/sys filesystems Remounting /sys directory Disable /sys/firmware Disable /sys/hypervisor Disable /sys/power Disable /sys/kernel/debug Disable /sys/kernel/vmcoreinfo Disable /proc/sys/fs/binfmt_misc Disable /proc/sys/kernel/core_pattern Disable /proc/sys/kernel/modprobe Disable /proc/sysrq-trigger Disable /proc/sys/vm/panic_on_oom Disable /proc/irq Disable /proc/bus Disable /proc/config.gz Disable /proc/sched_debug Disable /proc/timer_list Disable /proc/kcore Disable /proc/kallsyms Disable /usr/lib/modules (requested /lib/modules) Disable /boot Disable /dev/port Disable /run/user/1000/gnupg Disable /run/user/1000/systemd Disable /dev/kmsg Disable /proc/kmsg Debug 443: new_name #/home/fred/Desktop/test.sh#, whitelist Debug 544: fname #/home/fred/Desktop/test.sh#, cfg.homedir #/home/fred# Replaced whitelist path: whitelist /home/fred/Desktop/test.sh Drop privileges: pid 2, uid 1000, gid 1000, nogroups 0 Mounting a new /home directory Mounting a new /root directory Create a new user directory Drop privileges: pid 3, uid 1000, gid 1000, nogroups 0 Drop privileges: pid 4, uid 1000, gid 1000, nogroups 0 Whitelisting /home/fred/Desktop/test.sh 1021 1019 8:3 /fred/Desktop/test.sh /home/fred/Desktop/test.sh rw,relatime master:38 - ext4 /dev/sda3 rw,data=ordered fsname=/fred/Desktop/test.sh dir=/home/fred/Desktop/test.sh fstype=ext4 Mounting noexec /home/fred Disable /sys/fs Disable /sys/module Drop privileges: pid 5, uid 1000, gid 1000, nogroups 0 Drop privileges: pid 6, uid 1000, gid 1000, nogroups 0 1026 1019 0:96 /pulse /home/fred/.config/pulse rw,nosuid,nodev,noexec - tmpfs tmpfs rw,mode=755 fsname=/pulse dir=/home/fred/.config/pulse fstype=tmpfs Current directory: /home/fred/Desktop DISPLAY=:0 parsed as 0 Drop privileges: pid 1, uid 1000, gid 1000, nogroups 0 starting application LD_PRELOAD=(null) Running '/home/fred/Desktop/test.sh' command through /bin/bash execvp argument 0: /bin/bash execvp argument 1: -c execvp argument 2: '/home/fred/Desktop/test.sh' Child process initialized in 19.90 ms this file is being executed monitoring pid 7 Sandbox monitor: waitpid 7 retval 7 status 0 Parent is shutting down, bye... ```
gitea-mirror 2026-05-05 07:56:51 -06:00
Author
Owner

@chiraag-nataraj commented on GitHub (Jul 15, 2018):

I wonder if this is intended behavior. What exactly should the behavior be if you whitelist a binary and mark a parent directory/mount point noexec? Should the binary run and violate noexec or not run and defeat your intent? Clearly, if you are whitelisting an executable file, you want to run it (otherwise, there's no reason to whitelist it). So while on the face of it it seems counterintuitive, I think this behavior actually makes some logical sense.

<!-- gh-comment-id:405116349 --> @chiraag-nataraj commented on GitHub (Jul 15, 2018): I wonder if this is intended behavior. What exactly should the behavior be if you whitelist a binary and mark a parent directory/mount point noexec? Should the binary run and violate noexec or not run and defeat your intent? Clearly, if you are whitelisting an executable file, you want to run it (otherwise, there's no reason to whitelist it). So while on the face of it it seems counterintuitive, I think this behavior actually makes some logical sense.
Author
Owner

@chiraag-nataraj commented on GitHub (Jul 15, 2018):

Now my question is if you whitelist an executable file which creates another executable file and tries to run it, will that second file run? I'm off to test.

<!-- gh-comment-id:405116396 --> @chiraag-nataraj commented on GitHub (Jul 15, 2018): Now my question is if you whitelist an executable file which creates another executable file and tries to run it, will that _second_ file run? I'm off to test.
Author
Owner

@chiraag-nataraj commented on GitHub (Jul 15, 2018):

Awesome, this works as intended: the second script is prevented from running.

$ firejail --noexec=${HOME} --whitelist=~/Desktop/test.sh ~/Desktop/test.sh
Reading profile /usr/local/etc/firejail/default.profile
Reading profile /usr/local/etc/firejail/disable-common.inc
Reading profile /usr/local/etc/firejail/disable-passwdmgr.inc
Reading profile /usr/local/etc/firejail/disable-programs.inc

** Note: you can use --noprofile to disable default.profile **

Parent pid 8452, child pid 8455
Child process initialized in 72.17 ms
This is the first script running
/home/chiraag/Desktop/test.sh: line 6: /home/chiraag/Desktop/test2.sh: Permission denied

Parent is shutting down, bye...

Here's test.sh:

#!/bin/bash

echo "This is the first script running"
echo -e "#!/bin/bash\necho This is the second script running" >> ~/Desktop/test2.sh
chmod +x ~/Desktop/test2.sh
~/Desktop/test2.sh

As you can tell, the second script can't run due to the noexec on the parent mountpoint.

<!-- gh-comment-id:405116655 --> @chiraag-nataraj commented on GitHub (Jul 15, 2018): Awesome, this works as intended: the second script is prevented from running. ``` $ firejail --noexec=${HOME} --whitelist=~/Desktop/test.sh ~/Desktop/test.sh Reading profile /usr/local/etc/firejail/default.profile Reading profile /usr/local/etc/firejail/disable-common.inc Reading profile /usr/local/etc/firejail/disable-passwdmgr.inc Reading profile /usr/local/etc/firejail/disable-programs.inc ** Note: you can use --noprofile to disable default.profile ** Parent pid 8452, child pid 8455 Child process initialized in 72.17 ms This is the first script running /home/chiraag/Desktop/test.sh: line 6: /home/chiraag/Desktop/test2.sh: Permission denied Parent is shutting down, bye... ``` Here's `test.sh`: ``` #!/bin/bash echo "This is the first script running" echo -e "#!/bin/bash\necho This is the second script running" >> ~/Desktop/test2.sh chmod +x ~/Desktop/test2.sh ~/Desktop/test2.sh ``` As you can tell, the second script can't run due to the `noexec` on the parent mountpoint.
Author
Owner

@chiraag-nataraj commented on GitHub (Jul 15, 2018):

So basically, noexec can be more understood as "Don't run anything unless I explicitly whitelist it" rather than a blanket "Don't run anything". This actually makes for a decently flexible jail, since you can basically not allow arbitrary binaries to run while whitelisting ones you trust.

<!-- gh-comment-id:405116703 --> @chiraag-nataraj commented on GitHub (Jul 15, 2018): So basically, `noexec` can be more understood as "Don't run anything unless I explicitly whitelist it" rather than a blanket "Don't run anything". This actually makes for a decently flexible jail, since you can basically not allow arbitrary binaries to run while whitelisting ones you trust.
Author
Owner

@Fred-Barclay commented on GitHub (Jul 16, 2018):

@chiraag-nataraj it would be nice to know if this is intended behavior -- we should probably document it if so. I'm not convinced it makes sense but I do see what you're talking about. 😉

<!-- gh-comment-id:405337519 --> @Fred-Barclay commented on GitHub (Jul 16, 2018): @chiraag-nataraj it would be nice to know if this is intended behavior -- we should probably document it if so. I'm not convinced it makes sense but I do see what you're talking about. :wink:
Author
Owner

@chiraag-nataraj commented on GitHub (Jul 16, 2018):

Tagged it with both - that way, we can remove whichever one doesn't apply 😉

<!-- gh-comment-id:405356748 --> @chiraag-nataraj commented on GitHub (Jul 16, 2018): Tagged it with both - that way, we can remove whichever one doesn't apply :wink:
Author
Owner

@chiraag-nataraj commented on GitHub (Aug 21, 2018):

@netblue30 Is this a bug or is this desired behavior?

<!-- gh-comment-id:414706586 --> @chiraag-nataraj commented on GitHub (Aug 21, 2018): @netblue30 Is this a bug or is this desired behavior?
Author
Owner

@smitsohu commented on GitHub (Nov 26, 2018):

moving the discussion to #2200

<!-- gh-comment-id:441680963 --> @smitsohu commented on GitHub (Nov 26, 2018): moving the discussion to #2200
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#1367
No description provided.