netblue30 / firejail

Linux namespaces and seccomp-bpf sandbox
https://firejail.wordpress.com
GNU General Public License v2.0
5.84k stars 569 forks source link

blacklist does not work for new files and folders without firejail restart #6127

Open tm4ig opened 11 months ago

tm4ig commented 11 months ago

Description

Blacklist for [sub]folders (and files) does not work if they were created after start application.

Steps to Reproduce

  1. Create folders structure outside firejail:
tm4ig@sinx ~ % mkdir -p ~/test/{folder1,folder2,folder3}
tm4ig@sinx ~ % tree ~/test       
/home/tm4ig/test
├── folder1
├── folder2
└── folder3

4 directories, 0 files
  1. Run program in firejail with blacklist mode how in my example and check permissions for folders in firejail:
tm4ig@sinx ~ % LC_ALL=C firejail --noblacklist="~/test/folder1" --blacklist="~/test/*" /bin/bash
[tm4ig@sinx ~]$ ls -l ~/test
total 0
drwxr-xr-x 2 tm4ig  tm4ig   6 Dec 13 10:22 folder1
dr-------- 2 nobody nobody 40 Dec 11 20:00 folder2
dr-------- 2 nobody nobody 40 Dec 11 20:00 folder3
  1. Create next folder how in my example outside firejail but not close current firejail program:
tm4ig@sinx ~ % mkdir ~/test/folder4
tm4ig@sinx ~ % tree ~/test
/home/tm4ig/test
├── folder1
├── folder2
├── folder3
└── folder4

5 directories, 0 files

Expected behavior

folder4 will be in blacklist without restart firejail.

Actual behavior

folder4 is not in blacklist:

[tm4ig@sinx ~]$ ls -l ~/test
total 0
drwxr-xr-x 2 tm4ig  tm4ig   6 Dec 13 10:22 folder1
dr-------- 2 nobody nobody 40 Dec 11 20:00 folder2
dr-------- 2 nobody nobody 40 Dec 11 20:00 folder3
drwxr-xr-x 2 tm4ig  tm4ig   6 Dec 13 10:49 folder4

But after restart firejail folder4 already in blacklist:

[tm4ig@sinx ~]$ ls -lh ~/test
total 0
drwxr-xr-x 2 tm4ig tm4ig  6 Dec 13 10:22 folder1
dr-------- 2 root  root  40 Dec 11 20:00 folder2
dr-------- 2 root  root  40 Dec 11 20:00 folder3
dr-------- 2 root  root  40 Dec 11 20:00 folder4

Behavior without a profile

"noprofile" doesn't change the situation.

Environment

Checklist

Log

Output of LC_ALL=C firejail /path/to/program

```console tm4ig@sinx ~ % LC_ALL=C firejail --noblacklist="~/test/folder1" --blacklist="~/test/*" /bin/bash Reading profile /etc/firejail/default.profile Reading profile /etc/firejail/disable-common.inc Reading profile /etc/firejail/disable-programs.inc ** Note: you can use --noprofile to disable default.profile ** Parent pid 539573, child pid 539574 Warning: /sbin directory link was not blacklisted Warning: /usr/sbin directory link was not blacklisted Warning: cleaning all supplementary groups Child process initialized in 31.66 ms ```

Output of LC_ALL=C firejail --debug /path/to/program

[firejail.log](https://github.com/netblue30/firejail/files/13658144/firejail.log)

kmk3 commented 11 months ago

blacklist does not work for new files and folders without firejail restart

firejail runs before the program starts, so there is no way to blacklist anything afterwards.

To prevent new files from appearing in the sandbox, whitelisting has to be used.