diff options
-rw-r--r-- | .github/workflows/codeql-analysis.yml | 6 | ||||
-rw-r--r-- | etc/inc/allow-common-devel.inc | 5 | ||||
-rw-r--r-- | etc/inc/disable-common.inc | 2 | ||||
-rw-r--r-- | etc/inc/disable-programs.inc | 1 | ||||
-rw-r--r-- | etc/profile-a-l/cmake.profile | 9 | ||||
-rw-r--r-- | etc/profile-m-z/mupdf-gl.profile | 3 | ||||
-rw-r--r-- | etc/profile-m-z/mupdf-x11.profile | 3 | ||||
-rw-r--r-- | etc/profile-m-z/mupdf.profile | 4 | ||||
-rw-r--r-- | etc/profile-m-z/ocenaudio.profile | 33 | ||||
-rw-r--r-- | etc/profile-m-z/opera.profile | 11 | ||||
-rw-r--r-- | etc/profile-m-z/pip.profile | 5 | ||||
-rw-r--r-- | src/fbuilder/build_fs.c | 117 | ||||
-rw-r--r-- | src/fbuilder/build_profile.c | 6 | ||||
-rw-r--r-- | src/fbuilder/fbuilder.h | 6 | ||||
-rw-r--r-- | src/fbuilder/filedb.c | 10 | ||||
-rw-r--r-- | src/man/firejail.txt | 12 |
16 files changed, 193 insertions, 40 deletions
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1352ce3e6..e1d972d04 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml | |||
@@ -47,7 +47,7 @@ jobs: | |||
47 | 47 | ||
48 | # Initializes the CodeQL tools for scanning. | 48 | # Initializes the CodeQL tools for scanning. |
49 | - name: Initialize CodeQL | 49 | - name: Initialize CodeQL |
50 | uses: github/codeql-action/init@75f07e7ab2ee63cba88752d8c696324e4df67466 | 50 | uses: github/codeql-action/init@883476649888a9e8e219d5b2e6b789dc024f690c |
51 | with: | 51 | with: |
52 | languages: ${{ matrix.language }} | 52 | languages: ${{ matrix.language }} |
53 | # If you wish to specify custom queries, you can do so here or in a config file. | 53 | # If you wish to specify custom queries, you can do so here or in a config file. |
@@ -58,7 +58,7 @@ jobs: | |||
58 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). | 58 | # 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) | 59 | # If this step fails, then you should remove it and run the build manually (see below) |
60 | - name: Autobuild | 60 | - name: Autobuild |
61 | uses: github/codeql-action/autobuild@75f07e7ab2ee63cba88752d8c696324e4df67466 | 61 | uses: github/codeql-action/autobuild@883476649888a9e8e219d5b2e6b789dc024f690c |
62 | 62 | ||
63 | # âšī¸ Command-line programs to run using the OS shell. | 63 | # âšī¸ Command-line programs to run using the OS shell. |
64 | # đ https://git.io/JvXDl | 64 | # đ https://git.io/JvXDl |
@@ -72,4 +72,4 @@ jobs: | |||
72 | # make release | 72 | # make release |
73 | 73 | ||
74 | - name: Perform CodeQL Analysis | 74 | - name: Perform CodeQL Analysis |
75 | uses: github/codeql-action/analyze@75f07e7ab2ee63cba88752d8c696324e4df67466 | 75 | uses: github/codeql-action/analyze@883476649888a9e8e219d5b2e6b789dc024f690c |
diff --git a/etc/inc/allow-common-devel.inc b/etc/inc/allow-common-devel.inc index 4e460fc10..9576239f3 100644 --- a/etc/inc/allow-common-devel.inc +++ b/etc/inc/allow-common-devel.inc | |||
@@ -8,8 +8,13 @@ noblacklist ${HOME}/.gitconfig | |||
8 | noblacklist ${HOME}/.git-credentials | 8 | noblacklist ${HOME}/.git-credentials |
9 | 9 | ||
10 | # Java | 10 | # Java |
11 | noblacklist ${HOME}/.ammonite | ||
12 | noblacklist ${HOME}/.config/jgit | ||
13 | noblacklist ${HOME}/.g8 | ||
11 | noblacklist ${HOME}/.gradle | 14 | noblacklist ${HOME}/.gradle |
15 | noblacklist ${HOME}/.ivy2 | ||
12 | noblacklist ${HOME}/.java | 16 | noblacklist ${HOME}/.java |
17 | noblacklist ${HOME}/.sbt | ||
13 | 18 | ||
14 | # Node.js | 19 | # Node.js |
15 | noblacklist ${HOME}/.node-gyp | 20 | noblacklist ${HOME}/.node-gyp |
diff --git a/etc/inc/disable-common.inc b/etc/inc/disable-common.inc index 2e2f6c429..080a7f3a1 100644 --- a/etc/inc/disable-common.inc +++ b/etc/inc/disable-common.inc | |||
@@ -13,6 +13,7 @@ blacklist-nolog ${HOME}/.*_history_* | |||
13 | blacklist-nolog ${HOME}/.adobe | 13 | blacklist-nolog ${HOME}/.adobe |
14 | blacklist-nolog ${HOME}/.ammonite/history | 14 | blacklist-nolog ${HOME}/.ammonite/history |
15 | blacklist-nolog ${HOME}/.cache/greenclip* | 15 | blacklist-nolog ${HOME}/.cache/greenclip* |
16 | blacklist-nolog ${HOME}/.cache/mupdf.history | ||
16 | blacklist-nolog ${HOME}/.histfile | 17 | blacklist-nolog ${HOME}/.histfile |
17 | blacklist-nolog ${HOME}/.history | 18 | blacklist-nolog ${HOME}/.history |
18 | blacklist-nolog ${HOME}/.kde/share/apps/klipper | 19 | blacklist-nolog ${HOME}/.kde/share/apps/klipper |
@@ -511,6 +512,7 @@ blacklist /usr/lib/policykit-1/polkit-agent-helper-1 | |||
511 | blacklist /usr/lib/dbus-1.0/dbus-daemon-launch-helper | 512 | blacklist /usr/lib/dbus-1.0/dbus-daemon-launch-helper |
512 | blacklist /usr/lib/eject/dmcrypt-get-device | 513 | blacklist /usr/lib/eject/dmcrypt-get-device |
513 | blacklist /usr/lib/chromium/chrome-sandbox | 514 | blacklist /usr/lib/chromium/chrome-sandbox |
515 | blacklist /usr/lib/opera/opera_sandbox | ||
514 | blacklist /usr/lib/vmware | 516 | blacklist /usr/lib/vmware |
515 | blacklist ${PATH}/suexec | 517 | blacklist ${PATH}/suexec |
516 | blacklist /usr/lib/squid/basic_pam_auth | 518 | blacklist /usr/lib/squid/basic_pam_auth |
diff --git a/etc/inc/disable-programs.inc b/etc/inc/disable-programs.inc index fcd385cae..efe1b2572 100644 --- a/etc/inc/disable-programs.inc +++ b/etc/inc/disable-programs.inc | |||
@@ -175,6 +175,7 @@ blacklist ${HOME}/.cache/mypaint | |||
175 | blacklist ${HOME}/.cache/netsurf | 175 | blacklist ${HOME}/.cache/netsurf |
176 | blacklist ${HOME}/.cache/nheko | 176 | blacklist ${HOME}/.cache/nheko |
177 | blacklist ${HOME}/.cache/nvim | 177 | blacklist ${HOME}/.cache/nvim |
178 | blacklist ${HOME}/.cache/ocenaudio | ||
178 | blacklist ${HOME}/.cache/okular | 179 | blacklist ${HOME}/.cache/okular |
179 | blacklist ${HOME}/.cache/opera | 180 | blacklist ${HOME}/.cache/opera |
180 | blacklist ${HOME}/.cache/opera-beta | 181 | blacklist ${HOME}/.cache/opera-beta |
diff --git a/etc/profile-a-l/cmake.profile b/etc/profile-a-l/cmake.profile index 26cc2a00a..acc03e93f 100644 --- a/etc/profile-a-l/cmake.profile +++ b/etc/profile-a-l/cmake.profile | |||
@@ -1,12 +1,15 @@ | |||
1 | # Firejail profile for cargo | 1 | # Firejail profile for cmake |
2 | # Description: The Rust package manager | 2 | # Description: A cross-platform open-source make system |
3 | # This file is overwritten after every install/update | 3 | # This file is overwritten after every install/update |
4 | quiet | 4 | quiet |
5 | # Persistent local customizations | 5 | # Persistent local customizations |
6 | include cargo.local | 6 | include cmake.local |
7 | # Persistent global definitions | 7 | # Persistent global definitions |
8 | include globals.local | 8 | include globals.local |
9 | 9 | ||
10 | whitelist /usr/share/cmake | ||
11 | whitelist /usr/share/cmake-* | ||
12 | |||
10 | memory-deny-write-execute | 13 | memory-deny-write-execute |
11 | 14 | ||
12 | # Redirect | 15 | # Redirect |
diff --git a/etc/profile-m-z/mupdf-gl.profile b/etc/profile-m-z/mupdf-gl.profile index be94a9083..c5d94c371 100644 --- a/etc/profile-m-z/mupdf-gl.profile +++ b/etc/profile-m-z/mupdf-gl.profile | |||
@@ -7,7 +7,10 @@ include mupdf-gl.local | |||
7 | # added by included profile | 7 | # added by included profile |
8 | #include globals.local | 8 | #include globals.local |
9 | 9 | ||
10 | noblacklist ${HOME}/.cache/mupdf.history | ||
10 | noblacklist ${HOME}/.mupdf.history | 11 | noblacklist ${HOME}/.mupdf.history |
11 | 12 | ||
13 | ignore no3d | ||
14 | |||
12 | # Redirect | 15 | # Redirect |
13 | include mupdf.profile | 16 | include mupdf.profile |
diff --git a/etc/profile-m-z/mupdf-x11.profile b/etc/profile-m-z/mupdf-x11.profile index 256201d0c..547aa4f2f 100644 --- a/etc/profile-m-z/mupdf-x11.profile +++ b/etc/profile-m-z/mupdf-x11.profile | |||
@@ -7,8 +7,5 @@ include mupdf-x11.local | |||
7 | # added by included profile | 7 | # added by included profile |
8 | #include globals.local | 8 | #include globals.local |
9 | 9 | ||
10 | memory-deny-write-execute | ||
11 | read-only ${HOME} | ||
12 | |||
13 | # Redirect | 10 | # Redirect |
14 | include mupdf.profile | 11 | include mupdf.profile |
diff --git a/etc/profile-m-z/mupdf.profile b/etc/profile-m-z/mupdf.profile index 22cb83cc4..7a1f62858 100644 --- a/etc/profile-m-z/mupdf.profile +++ b/etc/profile-m-z/mupdf.profile | |||
@@ -21,6 +21,7 @@ apparmor | |||
21 | caps.drop all | 21 | caps.drop all |
22 | machine-id | 22 | machine-id |
23 | net none | 23 | net none |
24 | no3d | ||
24 | nodvd | 25 | nodvd |
25 | nogroups | 26 | nogroups |
26 | noinput | 27 | noinput |
@@ -41,3 +42,6 @@ private-tmp | |||
41 | 42 | ||
42 | dbus-user none | 43 | dbus-user none |
43 | dbus-system none | 44 | dbus-system none |
45 | |||
46 | memory-deny-write-execute | ||
47 | read-only ${HOME} | ||
diff --git a/etc/profile-m-z/ocenaudio.profile b/etc/profile-m-z/ocenaudio.profile index 0bfb35333..080b4c92b 100644 --- a/etc/profile-m-z/ocenaudio.profile +++ b/etc/profile-m-z/ocenaudio.profile | |||
@@ -6,8 +6,9 @@ include ocenaudio.local | |||
6 | # Persistent global definitions | 6 | # Persistent global definitions |
7 | include globals.local | 7 | include globals.local |
8 | 8 | ||
9 | noblacklist ${HOME}/.cache/ocenaudio | ||
9 | noblacklist ${HOME}/.local/share/ocenaudio | 10 | noblacklist ${HOME}/.local/share/ocenaudio |
10 | noblacklist ${DOCUMENTS} | 11 | |
11 | noblacklist ${MUSIC} | 12 | noblacklist ${MUSIC} |
12 | 13 | ||
13 | include disable-common.inc | 14 | include disable-common.inc |
@@ -18,38 +19,44 @@ include disable-programs.inc | |||
18 | include disable-shell.inc | 19 | include disable-shell.inc |
19 | include disable-xdg.inc | 20 | include disable-xdg.inc |
20 | 21 | ||
22 | mkdir ${HOME}/.cache/ocenaudio | ||
23 | mkdir ${HOME}/.local/share/ocenaudio | ||
24 | whitelist ${HOME}/.cache/ocenaudio | ||
25 | whitelist ${HOME}/.local/share/ocenaudio | ||
26 | whitelist ${DOWNLOADS} | ||
27 | whitelist ${MUSIC} | ||
28 | include whitelist-common.inc | ||
29 | include whitelist-run-common.inc | ||
30 | include whitelist-runuser-common.inc | ||
21 | include whitelist-usr-share-common.inc | 31 | include whitelist-usr-share-common.inc |
22 | include whitelist-var-common.inc | 32 | include whitelist-var-common.inc |
23 | 33 | ||
24 | apparmor | 34 | apparmor |
25 | caps.drop all | 35 | caps.drop all |
26 | ipc-namespace | 36 | #ipc-namespace |
27 | # net none - breaks update functionality and AppArmor on Ubuntu systems | ||
28 | # Add 'net none' to your ocenaudio.local when you want that functionality. | ||
29 | #net none | ||
30 | netfilter | 37 | netfilter |
31 | no3d | 38 | no3d |
32 | nodvd | 39 | nodvd |
33 | nogroups | 40 | nogroups |
34 | noinput | 41 | noinput |
35 | nonewprivs | 42 | nonewprivs |
43 | noprinters | ||
36 | noroot | 44 | noroot |
37 | notv | 45 | notv |
38 | nou2f | 46 | nou2f |
39 | novideo | 47 | novideo |
40 | protocol unix | 48 | # Add `protocol unix\nignore protocol` to your ocenaudio.local to disable networking. |
49 | protocol unix,inet,inet6 | ||
41 | seccomp | 50 | seccomp |
42 | shell none | 51 | shell none |
43 | tracelog | 52 | tracelog |
44 | 53 | ||
45 | private-bin ocenaudio | 54 | private-bin ocenaudio,ocenvst |
46 | private-cache | 55 | private-cache |
47 | private-dev | 56 | private-dev |
48 | private-etc alternatives,asound.conf,fonts,ld.so.cache,ld.so.preload,pulse | 57 | private-etc alternatives,asound.conf,ca-certificates,crypto-policies,dconf,fonts,group,gtk-2.0,gtk-3.0,hostname,hosts,ld.so.cache,ld.so.conf,ld.so.conf.d,ld.so.preload,mime.types,nsswitch.conf,pki,pulse,resolv.conf,ssl,X11,xdg |
58 | private-opt ocenaudio | ||
49 | private-tmp | 59 | private-tmp |
50 | 60 | ||
51 | # breaks preferences | 61 | dbus-user none |
52 | # dbus-user none | 62 | dbus-system none |
53 | # dbus-system none | ||
54 | |||
55 | #memory-deny-write-execute - breaks on Arch (see issue #1803) | ||
diff --git a/etc/profile-m-z/opera.profile b/etc/profile-m-z/opera.profile index b342b3961..e52e9294d 100644 --- a/etc/profile-m-z/opera.profile +++ b/etc/profile-m-z/opera.profile | |||
@@ -17,5 +17,16 @@ whitelist ${HOME}/.cache/opera | |||
17 | whitelist ${HOME}/.config/opera | 17 | whitelist ${HOME}/.config/opera |
18 | whitelist ${HOME}/.opera | 18 | whitelist ${HOME}/.opera |
19 | 19 | ||
20 | # https://github.com/netblue30/firejail/issues/4965 | ||
21 | ignore whitelist /usr/share/mozilla/extensions | ||
22 | ignore whitelist /usr/share/webext | ||
23 | |||
24 | # opera uses opera_sandbox instead of chrome-sandbox | ||
25 | noblacklist /usr/lib/opera/opera_sandbox | ||
26 | ignore noblacklist /usr/lib/chromium/chrome-sandbox | ||
27 | |||
28 | # Add the below to your opera.local if you want to disable auto update | ||
29 | #env OPERA_AUTOUPDATE_DISABLED=1 | ||
30 | |||
20 | # Redirect | 31 | # Redirect |
21 | include chromium-common.profile | 32 | include chromium-common.profile |
diff --git a/etc/profile-m-z/pip.profile b/etc/profile-m-z/pip.profile index a0926371f..560957d47 100644 --- a/etc/profile-m-z/pip.profile +++ b/etc/profile-m-z/pip.profile | |||
@@ -3,7 +3,7 @@ | |||
3 | # This file is overwritten after every install/update | 3 | # This file is overwritten after every install/update |
4 | quiet | 4 | quiet |
5 | # Persistent local customizations | 5 | # Persistent local customizations |
6 | include meson.local | 6 | include pip.local |
7 | # Persistent global definitions | 7 | # Persistent global definitions |
8 | include globals.local | 8 | include globals.local |
9 | 9 | ||
@@ -12,6 +12,9 @@ ignore read-only ${HOME}/.local/lib | |||
12 | # Allow python3 (blacklisted by disable-interpreters.inc) | 12 | # Allow python3 (blacklisted by disable-interpreters.inc) |
13 | include allow-python3.inc | 13 | include allow-python3.inc |
14 | 14 | ||
15 | noblacklist ${HOME}/.cache/pip | ||
16 | |||
17 | #whitelist ${HOME}/.cache/pip | ||
15 | #whitelist ${HOME}/.local/lib/python* | 18 | #whitelist ${HOME}/.local/lib/python* |
16 | 19 | ||
17 | # Redirect | 20 | # Redirect |
diff --git a/src/fbuilder/build_fs.c b/src/fbuilder/build_fs.c index ede96c9b4..88b5eaad3 100644 --- a/src/fbuilder/build_fs.c +++ b/src/fbuilder/build_fs.c | |||
@@ -68,8 +68,23 @@ static void process_file(const char *fname, const char *dir, void (*callback)(ch | |||
68 | ptr += 7; | 68 | ptr += 7; |
69 | else if (strncmp(ptr, "open ", 5) == 0) | 69 | else if (strncmp(ptr, "open ", 5) == 0) |
70 | ptr += 5; | 70 | ptr += 5; |
71 | else if (strncmp(ptr, "opendir ", 8) == 0) | ||
72 | ptr += 8; | ||
73 | else if (strncmp(ptr, "connect ", 8) == 0) { | ||
74 | ptr += 8; | ||
75 | // file descriptor argument | ||
76 | if (!isdigit(*ptr)) | ||
77 | continue; | ||
78 | while (isdigit(*ptr)) | ||
79 | ptr++; | ||
80 | if (*ptr++ != ' ') | ||
81 | continue; | ||
82 | if (*ptr != '/') | ||
83 | continue; | ||
84 | } | ||
71 | else | 85 | else |
72 | continue; | 86 | continue; |
87 | |||
73 | if (strncmp(ptr, dir, dir_len) != 0) | 88 | if (strncmp(ptr, dir, dir_len) != 0) |
74 | continue; | 89 | continue; |
75 | 90 | ||
@@ -117,8 +132,19 @@ static void etc_callback(char *ptr) { | |||
117 | if (strncmp(ptr, "/etc/firejail", 13) == 0) | 132 | if (strncmp(ptr, "/etc/firejail", 13) == 0) |
118 | return; | 133 | return; |
119 | 134 | ||
135 | // extract the directory: | ||
136 | assert(strncmp(ptr, "/etc", 4) == 0); | ||
137 | ptr += 4; | ||
138 | if (*ptr != '/') | ||
139 | return; | ||
140 | ptr++; | ||
141 | |||
142 | if (*ptr == '/') // double '/' | ||
143 | ptr++; | ||
144 | if (*ptr == '\0') | ||
145 | return; | ||
146 | |||
120 | // add only top files and directories | 147 | // add only top files and directories |
121 | ptr += 5; // skip "/etc/" | ||
122 | char *end = strchr(ptr, '/'); | 148 | char *end = strchr(ptr, '/'); |
123 | if (end) | 149 | if (end) |
124 | *end = '\0'; | 150 | *end = '\0'; |
@@ -163,6 +189,11 @@ static char *var_skip[] = { | |||
163 | static FileDB *var_out = NULL; | 189 | static FileDB *var_out = NULL; |
164 | static FileDB *var_skip = NULL; | 190 | static FileDB *var_skip = NULL; |
165 | static void var_callback(char *ptr) { | 191 | static void var_callback(char *ptr) { |
192 | // skip /var/lib/flatpak, /var/lib/snapd directory | ||
193 | if (strncmp(ptr, "/var/lib/flatpak", 16) == 0 || | ||
194 | strncmp(ptr, "/var/lib/snapd", 14) == 0) | ||
195 | return; | ||
196 | |||
166 | // extract the directory: | 197 | // extract the directory: |
167 | assert(strncmp(ptr, "/var", 4) == 0); | 198 | assert(strncmp(ptr, "/var", 4) == 0); |
168 | char *p1 = ptr + 4; | 199 | char *p1 = ptr + 4; |
@@ -183,8 +214,6 @@ void build_var(const char *fname, FILE *fp) { | |||
183 | assert(fname); | 214 | assert(fname); |
184 | 215 | ||
185 | var_skip = filedb_load_whitelist(var_skip, "whitelist-var-common.inc", "whitelist /var/"); | 216 | var_skip = filedb_load_whitelist(var_skip, "whitelist-var-common.inc", "whitelist /var/"); |
186 | var_skip = filedb_add(var_skip, "lib/flatpak"); | ||
187 | var_skip = filedb_add(var_skip, "lib/snapd"); | ||
188 | process_files(fname, "/var", var_callback); | 217 | process_files(fname, "/var", var_callback); |
189 | 218 | ||
190 | // always whitelist /var | 219 | // always whitelist /var |
@@ -193,6 +222,88 @@ void build_var(const char *fname, FILE *fp) { | |||
193 | fprintf(fp, "include whitelist-var-common.inc\n"); | 222 | fprintf(fp, "include whitelist-var-common.inc\n"); |
194 | } | 223 | } |
195 | 224 | ||
225 | //******************************************* | ||
226 | // run directory | ||
227 | //******************************************* | ||
228 | static FileDB *run_out = NULL; | ||
229 | static FileDB *run_skip = NULL; | ||
230 | static void run_callback(char *ptr) { | ||
231 | // skip /run/firejail | ||
232 | if (strncmp(ptr, "/run/firejail", 13) == 0) | ||
233 | return; | ||
234 | // skip files in /run/user | ||
235 | if (strncmp(ptr, "/run/user", 9) == 0) | ||
236 | return; | ||
237 | |||
238 | // extract the directory: | ||
239 | assert(strncmp(ptr, "/run", 4) == 0); | ||
240 | char *p1 = ptr + 4; | ||
241 | if (*p1 != '/') | ||
242 | return; | ||
243 | p1++; | ||
244 | |||
245 | if (*p1 == '/') // double '/' | ||
246 | p1++; | ||
247 | if (*p1 == '\0') | ||
248 | return; | ||
249 | |||
250 | if (!filedb_find(run_skip, p1)) | ||
251 | run_out = filedb_add(run_out, p1); | ||
252 | } | ||
253 | |||
254 | void build_run(const char *fname, FILE *fp) { | ||
255 | assert(fname); | ||
256 | |||
257 | run_skip = filedb_load_whitelist(run_skip, "whitelist-run-common.inc", "whitelist /run/"); | ||
258 | process_files(fname, "/run", run_callback); | ||
259 | |||
260 | // always whitelist /run | ||
261 | if (run_out) | ||
262 | filedb_print(run_out, "whitelist /run/", fp); | ||
263 | fprintf(fp, "include whitelist-run-common.inc\n"); | ||
264 | } | ||
265 | |||
266 | //******************************************* | ||
267 | // ${RUNUSER} directory | ||
268 | //******************************************* | ||
269 | static char *runuser_fname = NULL; | ||
270 | static FileDB *runuser_out = NULL; | ||
271 | static FileDB *runuser_skip = NULL; | ||
272 | static void runuser_callback(char *ptr) { | ||
273 | // extract the directory: | ||
274 | assert(runuser_fname); | ||
275 | assert(strncmp(ptr, runuser_fname, strlen(runuser_fname)) == 0); | ||
276 | char *p1 = ptr + strlen(runuser_fname); | ||
277 | if (*p1 != '/') | ||
278 | return; | ||
279 | p1++; | ||
280 | |||
281 | if (*p1 == '/') // double '/' | ||
282 | p1++; | ||
283 | if (*p1 == '\0') | ||
284 | return; | ||
285 | |||
286 | if (!filedb_find(runuser_skip, p1)) | ||
287 | runuser_out = filedb_add(runuser_out, p1); | ||
288 | } | ||
289 | |||
290 | void build_runuser(const char *fname, FILE *fp) { | ||
291 | assert(fname); | ||
292 | |||
293 | if (asprintf(&runuser_fname, "/run/user/%d", getuid()) < 0) | ||
294 | errExit("asprintf"); | ||
295 | |||
296 | if (!is_dir(runuser_fname)) | ||
297 | return; | ||
298 | |||
299 | runuser_skip = filedb_load_whitelist(runuser_skip, "whitelist-runuser-common.inc", "whitelist ${RUNUSER}/"); | ||
300 | process_files(fname, runuser_fname, runuser_callback); | ||
301 | |||
302 | // always whitelist /run/user/$UID | ||
303 | if (runuser_out) | ||
304 | filedb_print(runuser_out, "whitelist ${RUNUSER}/", fp); | ||
305 | fprintf(fp, "include whitelist-runuser-common.inc\n"); | ||
306 | } | ||
196 | 307 | ||
197 | //******************************************* | 308 | //******************************************* |
198 | // usr/share directory | 309 | // usr/share directory |
diff --git a/src/fbuilder/build_profile.c b/src/fbuilder/build_profile.c index 4fcd950c6..24cb4472c 100644 --- a/src/fbuilder/build_profile.c +++ b/src/fbuilder/build_profile.c | |||
@@ -122,8 +122,10 @@ void build_profile(int argc, char **argv, int index, FILE *fp) { | |||
122 | fprintf(fp, "\n"); | 122 | fprintf(fp, "\n"); |
123 | 123 | ||
124 | fprintf(fp, "### Filesystem Whitelisting ###\n"); | 124 | fprintf(fp, "### Filesystem Whitelisting ###\n"); |
125 | build_share(trace_output, fp); | 125 | build_run(trace_output, fp); |
126 | //todo: include whitelist-runuser-common.inc | 126 | build_runuser(trace_output, fp); |
127 | if (!arg_appimage) | ||
128 | build_share(trace_output, fp); | ||
127 | build_var(trace_output, fp); | 129 | build_var(trace_output, fp); |
128 | fprintf(fp, "\n"); | 130 | fprintf(fp, "\n"); |
129 | 131 | ||
diff --git a/src/fbuilder/fbuilder.h b/src/fbuilder/fbuilder.h index 3e23d7854..b07209e51 100644 --- a/src/fbuilder/fbuilder.h +++ b/src/fbuilder/fbuilder.h | |||
@@ -26,7 +26,7 @@ | |||
26 | #include <sys/types.h> | 26 | #include <sys/types.h> |
27 | #include <sys/stat.h> | 27 | #include <sys/stat.h> |
28 | #include <fcntl.h> | 28 | #include <fcntl.h> |
29 | 29 | #include <fnmatch.h> | |
30 | 30 | ||
31 | #define MAX_BUF 4096 | 31 | #define MAX_BUF 4096 |
32 | // main.c | 32 | // main.c |
@@ -46,6 +46,8 @@ void build_var(const char *fname, FILE *fp); | |||
46 | void build_tmp(const char *fname, FILE *fp); | 46 | void build_tmp(const char *fname, FILE *fp); |
47 | void build_dev(const char *fname, FILE *fp); | 47 | void build_dev(const char *fname, FILE *fp); |
48 | void build_share(const char *fname, FILE *fp); | 48 | void build_share(const char *fname, FILE *fp); |
49 | void build_run(const char *fname, FILE *fp); | ||
50 | void build_runuser(const char *fname, FILE *fp); | ||
49 | 51 | ||
50 | // build_bin.c | 52 | // build_bin.c |
51 | void build_bin(const char *fname, FILE *fp); | 53 | void build_bin(const char *fname, FILE *fp); |
@@ -61,7 +63,7 @@ char *extract_dir(char *fname); | |||
61 | typedef struct filedb_t { | 63 | typedef struct filedb_t { |
62 | struct filedb_t *next; | 64 | struct filedb_t *next; |
63 | char *fname; // file name | 65 | char *fname; // file name |
64 | int len; // length of file name | 66 | unsigned len; // length of file name |
65 | } FileDB; | 67 | } FileDB; |
66 | 68 | ||
67 | FileDB *filedb_add(FileDB *head, const char *fname); | 69 | FileDB *filedb_add(FileDB *head, const char *fname); |
diff --git a/src/fbuilder/filedb.c b/src/fbuilder/filedb.c index 569095785..89b6980d2 100644 --- a/src/fbuilder/filedb.c +++ b/src/fbuilder/filedb.c | |||
@@ -25,17 +25,17 @@ FileDB *filedb_find(FileDB *head, const char *fname) { | |||
25 | assert(fname); | 25 | assert(fname); |
26 | FileDB *ptr = head; | 26 | FileDB *ptr = head; |
27 | int found = 0; | 27 | int found = 0; |
28 | int len = strlen(fname); | ||
29 | 28 | ||
30 | while (ptr) { | 29 | while (ptr) { |
31 | // exact name | 30 | // ptr->fname can be a pattern, like .mutter-Xwaylandauth.* |
32 | if (strcmp(fname, ptr->fname) == 0) { | 31 | // check if fname is a match |
32 | if (fnmatch(ptr->fname, fname, FNM_PATHNAME) == 0) { | ||
33 | found = 1; | 33 | found = 1; |
34 | break; | 34 | break; |
35 | } | 35 | } |
36 | 36 | ||
37 | // parent directory in the list | 37 | // parent directory in the list |
38 | if (len > ptr->len && | 38 | if (strlen(fname) > ptr->len && |
39 | fname[ptr->len] == '/' && | 39 | fname[ptr->len] == '/' && |
40 | strncmp(ptr->fname, fname, ptr->len) == 0) { | 40 | strncmp(ptr->fname, fname, ptr->len) == 0) { |
41 | found = 1; | 41 | found = 1; |
@@ -54,8 +54,6 @@ FileDB *filedb_find(FileDB *head, const char *fname) { | |||
54 | FileDB *filedb_add(FileDB *head, const char *fname) { | 54 | FileDB *filedb_add(FileDB *head, const char *fname) { |
55 | assert(fname); | 55 | assert(fname); |
56 | 56 | ||
57 | // todo: support fnames such as ${RUNUSER}/.mutter-Xwaylandauth.* | ||
58 | |||
59 | // don't add it if it is already there or if the parent directory is already in the list | 57 | // don't add it if it is already there or if the parent directory is already in the list |
60 | if (filedb_find(head, fname)) | 58 | if (filedb_find(head, fname)) |
61 | return head; | 59 | return head; |
diff --git a/src/man/firejail.txt b/src/man/firejail.txt index 228d0c91c..1d028b8ac 100644 --- a/src/man/firejail.txt +++ b/src/man/firejail.txt | |||
@@ -185,23 +185,27 @@ $ firejail "\-\-blacklist=/home/username/My Virtual Machines" | |||
185 | $ firejail \-\-blacklist=/home/username/My\\ Virtual\\ Machines | 185 | $ firejail \-\-blacklist=/home/username/My\\ Virtual\\ Machines |
186 | .TP | 186 | .TP |
187 | \fB\-\-build | 187 | \fB\-\-build |
188 | The command builds a whitelisted profile. The profile is printed on the screen. The program is run in a very relaxed sandbox, with only --caps.drop=all and --nonewprivs. Programs that raise user privileges are not supported. | 188 | The command builds a whitelisted profile. The profile is printed on the screen. The program is run in a very relaxed sandbox, with only \-\-caps.drop=all and \-\-seccomp=!chroot. Programs that raise user privileges are not supported. |
189 | .br | 189 | .br |
190 | 190 | ||
191 | .br | 191 | .br |
192 | Example: | 192 | Example: |
193 | .br | 193 | .br |
194 | $ firejail --build vlc ~/Videos/test.mp4 | 194 | $ firejail \-\-build vlc ~/Videos/test.mp4 |
195 | .br | ||
196 | $ firejail \-\-build \-\-appimage ~/Downloads/Subsurface.AppImage | ||
195 | .TP | 197 | .TP |
196 | \fB\-\-build=profile-file | 198 | \fB\-\-build=profile-file |
197 | The command builds a whitelisted profile, and saves it in profile-file. The program is run in a very relaxed sandbox, | 199 | The command builds a whitelisted profile, and saves it in profile-file. The program is run in a very relaxed sandbox, |
198 | with only --caps.drop=all and --nonewprivs. Programs that raise user privileges are not supported. | 200 | with only \-\-caps.drop=all and \-\-seccomp=!chroot. Programs that raise user privileges are not supported. |
199 | .br | 201 | .br |
200 | 202 | ||
201 | .br | 203 | .br |
202 | Example: | 204 | Example: |
203 | .br | 205 | .br |
204 | $ firejail --build=vlc.profile vlc ~/Videos/test.mp4 | 206 | $ firejail \-\-build=vlc.profile vlc ~/Videos/test.mp4 |
207 | .br | ||
208 | $ firejail \-\-build=Subsurface.profile \-\-appimage ~/Downloads/Subsurface.AppImage | ||
205 | .TP | 209 | .TP |
206 | \fB\-c | 210 | \fB\-c |
207 | Login shell compatibility option. This option is use by some login programs when executing | 211 | Login shell compatibility option. This option is use by some login programs when executing |