Skip to content

Commit 9ae9d83

Browse files
committed
modif: block TPM devices & turn notpm command into keep-dev-tpm
Instead of having a `notpm` command and potentially adding it to almost all profiles (as few programs should need direct access to TPM devices), add a `keep-dev-tpm` command and use it only in profiles that need access to TPM devices. Changes: * Turn `notpm` command into `keep-dev-tpm` command * Warn and ignore if `notpm` is used * Block `/dev/tpm*` devices by default * Allow `/dev/tpm*` devices with `keep-dev-tpm` (even if `private-dev` is used) Added on commit 0013202 ("feature: add notpm command & keep tpm devices in private-dev (netblue30#6390)", 2024-07-09). See also commit ee1c264 ("feature: block /dev/ntsync & add keep-dev-ntsync command (netblue30#6660)", 2025-03-06) and the discussion at PR netblue30#6660. This is a follow-up to netblue30#6687.
1 parent 8348050 commit 9ae9d83

File tree

14 files changed

+52
-31
lines changed

14 files changed

+52
-31
lines changed

contrib/syntax/lists/profile_commands_arg0.list

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ipc-namespace
1111
keep-config-pulse
1212
keep-dev-ntsync
1313
keep-dev-shm
14+
keep-dev-tpm
1415
keep-shell-rc
1516
keep-var-tmp
1617
landlock.enforce

etc/profile-a-l/default.profile

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ noinput
3737
nonewprivs
3838
noroot
3939
#nosound
40-
#notpm
4140
notv
4241
#nou2f
4342
novideo

etc/profile-m-z/noprofile.profile

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ allusers
2323
keep-config-pulse
2424
keep-dev-ntsync
2525
keep-dev-shm
26+
keep-dev-tpm
2627
keep-fd all
2728
keep-shell-rc
2829
keep-var-tmp

etc/templates/profile.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ include globals.local
162162
##keep-config-pulse
163163
##keep-dev-ntsync
164164
##keep-dev-shm
165+
##keep-dev-tpm
165166
##keep-fd all
166167
##keep-shell-rc
167168
##keep-var-tmp
@@ -191,7 +192,6 @@ include globals.local
191192
#noprinters
192193
#noroot
193194
#nosound
194-
#notpm
195195
#notv
196196
#nou2f
197197
#novideo

src/fbuilder/build_profile.c

-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ void build_profile(int argc, char **argv, int index, FILE *fp) {
138138
fprintf(fp, "#noinput\t# disable input devices\n");
139139
fprintf(fp, "nonewprivs\n");
140140
fprintf(fp, "noroot\n");
141-
fprintf(fp, "#notpm\t# disable TPM devices\n");
142141
fprintf(fp, "#notv\t# disable DVB TV devices\n");
143142
fprintf(fp, "#nou2f\t# disable U2F devices\n");
144143
fprintf(fp, "#novideo\t# disable video capture devices\n");

src/firejail/firejail.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ extern char *arg_netns; // "ip netns"-created network namespace to use
329329
extern int arg_doubledash; // double dash
330330
extern int arg_private_dev; // private dev directory
331331
extern int arg_keep_dev_ntsync; // preserve /dev/ntsync
332+
extern int arg_keep_dev_tpm; // preserve /dev/tpm*
332333
extern int arg_keep_dev_shm; // preserve /dev/shm
333334
extern int arg_private_etc; // private etc directory
334335
extern int arg_private_opt; // private opt directory
@@ -369,7 +370,6 @@ extern int arg_noprofile; // use default.profile if none other found/specified
369370
extern int arg_memory_deny_write_execute; // block writable and executable memory
370371
extern int arg_notv; // --notv
371372
extern int arg_nodvd; // --nodvd
372-
extern int arg_notpm; // --notpm
373373
extern int arg_nou2f; // --nou2f
374374
extern int arg_noinput; // --noinput
375375
extern int arg_deterministic_exit_code; // always exit with first child's exit status

src/firejail/fs_dev.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static void deventry_mount(void) {
114114
(dev[i].type == DEV_VIDEO && arg_novideo == 0) ||
115115
(dev[i].type == DEV_TV && arg_notv == 0) ||
116116
(dev[i].type == DEV_DVD && arg_nodvd == 0) ||
117-
(dev[i].type == DEV_TPM && arg_notpm == 0) ||
117+
(dev[i].type == DEV_TPM && arg_keep_dev_tpm == 1) ||
118118
(dev[i].type == DEV_U2F && arg_nou2f == 0) ||
119119
(dev[i].type == DEV_INPUT && arg_noinput == 0) ||
120120
(dev[i].type == DEV_NTSYNC && arg_keep_dev_ntsync == 1)) {

src/firejail/main.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ char *arg_netns = NULL; // "ip netns"-created network namespace to use
115115
int arg_doubledash = 0; // double dash
116116
int arg_private_dev = 0; // private dev directory
117117
int arg_keep_dev_ntsync = 0; // preserve /dev/ntsync
118+
int arg_keep_dev_tpm = 0; // preserve /dev/tpm*
118119
int arg_keep_dev_shm = 0; // preserve /dev/shm
119120
int arg_private_etc = 0; // private etc directory
120121
int arg_private_opt = 0; // private opt directory
@@ -156,7 +157,6 @@ int arg_noprofile = 0; // use default.profile if none other found/specified
156157
int arg_memory_deny_write_execute = 0; // block writable and executable memory
157158
int arg_notv = 0; // --notv
158159
int arg_nodvd = 0; // --nodvd
159-
int arg_notpm = 0; // --notpm
160160
int arg_nou2f = 0; // --nou2f
161161
int arg_noinput = 0; // --noinput
162162
int arg_deterministic_exit_code = 0; // always exit with first child's exit status
@@ -2037,6 +2037,9 @@ int main(int argc, char **argv, char **envp) {
20372037
else if (strcmp(argv[i], "--keep-dev-ntsync") == 0) {
20382038
arg_keep_dev_ntsync = 1;
20392039
}
2040+
else if (strcmp(argv[i], "--keep-dev-tpm") == 0) {
2041+
arg_keep_dev_tpm = 1;
2042+
}
20402043
else if (strcmp(argv[i], "--keep-dev-shm") == 0) {
20412044
arg_keep_dev_shm = 1;
20422045
}
@@ -2224,8 +2227,9 @@ int main(int argc, char **argv, char **envp) {
22242227
arg_notv = 1;
22252228
else if (strcmp(argv[i], "--nodvd") == 0)
22262229
arg_nodvd = 1;
2230+
// TODO: Fully remove notpm after 0.9.76.
22272231
else if (strcmp(argv[i], "--notpm") == 0)
2228-
arg_notpm = 1;
2232+
fwarning("ignoring removed command: --notpm (see --keep-dev-tpm)\n");
22292233
else if (strcmp(argv[i], "--nou2f") == 0)
22302234
arg_nou2f = 1;
22312235
else if (strcmp(argv[i], "--noinput") == 0)

src/firejail/profile.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
435435
arg_keep_dev_ntsync = 1;
436436
return 0;
437437
}
438+
else if (strcmp(ptr, "keep-dev-tpm") == 0) {
439+
arg_keep_dev_tpm = 1;
440+
return 0;
441+
}
438442
else if (strcmp(ptr, "keep-dev-shm") == 0) {
439443
arg_keep_dev_shm = 1;
440444
return 0;
@@ -622,8 +626,9 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
622626
#endif
623627
return 1;
624628
}
629+
// TODO: Fully remove notpm after 0.9.76.
625630
else if (strcmp(ptr, "notpm") == 0) {
626-
arg_notpm = 1;
631+
fwarning("ignoring removed command: notpm (see keep-dev-tpm)\n");
627632
return 0;
628633
}
629634
else if (strcmp(ptr, "nou2f") == 0) {

src/firejail/sandbox.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ int sandbox(void* sandbox_arg) {
11011101
if (arg_nodvd)
11021102
fs_dev_disable_dvd();
11031103

1104-
if (arg_notpm)
1104+
if (!arg_keep_dev_tpm)
11051105
fs_dev_disable_tpm();
11061106

11071107
if (arg_nou2f)

src/firejail/usage.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ static const char *const usage_str =
130130
" --join-or-start=name|pid - join the sandbox or start a new one.\n"
131131
" --keep-config-pulse - disable automatic ~/.config/pulse init.\n"
132132
" --keep-dev-ntsync - /dev/ntsync character device is untouched (even with --private-dev).\n"
133+
" --keep-dev-tpm - /dev/tpm* devices are untouched (even with --private-dev).\n"
133134
" --keep-dev-shm - /dev/shm directory is untouched (even with --private-dev).\n"
134135
" --keep-fd - inherit open file descriptors to sandbox.\n"
135136
" --keep-shell-rc - do not copy shell rc files from /etc/skel\n"
@@ -191,7 +192,6 @@ static const char *const usage_str =
191192
#endif
192193
" --nosound - disable sound system.\n"
193194
" --novideo - disable video devices.\n"
194-
" --notpm - disable TPM devices.\n"
195195
" --nou2f - disable U2F devices.\n"
196196
" --nowhitelist=filename - disable whitelist for file or directory.\n"
197197
" --oom=value - configure OutOfMemory killer for the sandbox\n"

src/man/firejail-profile.5.in

+13-7
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ which is blocked by default.
305305
This device is mostly intended to increase performance and compatibility when
306306
running certain programs through Wine.
307307
.TP
308+
\fBkeep-dev-tpm
309+
Allow access to the /dev/tpm* Trusted Platform Module (TPM) devices (even with
310+
\fBprivate-dev\fR), which are blocked by default.
311+
.TP
308312
\fBkeep-dev-shm
309313
/dev/shm directory is untouched (even with private-dev).
310314
.TP
@@ -403,11 +407,10 @@ Set working directory inside the jail. Full directory path is required. Symbolic
403407
.TP
404408
\fBprivate-dev
405409
Create a new /dev directory.
406-
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tpm,
407-
tty, urandom, usb, video and zero devices are available.
408-
Use the options no3d, nodvd, nosound, notpm, notv, nou2f and novideo for
409-
additional restrictions.
410-
410+
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tty,
411+
urandom, usb, video and zero devices are available.
412+
Use the options no3d, nodvd, nosound, notv, nou2f and novideo for additional
413+
restrictions.
411414
.TP
412415
\fBprivate-etc file,directory
413416
Build a new /etc in a temporary
@@ -858,9 +861,12 @@ Disable input devices.
858861
.TP
859862
\fBnosound
860863
Disable sound system.
864+
.\" TODO: Fully remove notpm after 0.9.76.
861865
.TP
862-
\fBnotpm
863-
Disable Trusted Platform Module (TPM) devices.
866+
\fBnotpm\fR (deprecated)
867+
Ignored for compatibility.
868+
.br
869+
TPM devices are now blocked by default, see \fBkeep-dev-tpm\fR.
864870
.TP
865871
\fBnotv
866872
Disable DVB (Digital Video Broadcasting) TV devices.

src/man/firejail.1.in

+19-13
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,17 @@ Example:
12311231
.br
12321232
$ firejail --keep-dev-ntsync --private-dev
12331233

1234+
.TP
1235+
\fB\-\-keep-dev-tpm
1236+
Allow access to the /dev/tpm* Trusted Platform Module (TPM) devices (even with
1237+
\fBprivate-dev\fR), which are blocked by default.
1238+
.br
1239+
1240+
.br
1241+
Example:
1242+
.br
1243+
$ firejail --keep-dev-tpm --private-dev
1244+
12341245
.TP
12351246
\fB\-\-keep-dev-shm
12361247
/dev/shm directory is untouched (even with --private-dev)
@@ -1959,17 +1970,12 @@ Disable sound system.
19591970
Example:
19601971
.br
19611972
$ firejail \-\-nosound firefox
1962-
1973+
.\" TODO: Fully remove notpm after 0.9.76.
19631974
.TP
1964-
\fB\-\-notpm
1965-
Disable Trusted Platform Module (TPM) devices.
1966-
.br
1967-
1975+
\fB\-\-notpm\fR (deprecated)
1976+
Ignored for compatibility.
19681977
.br
1969-
Example:
1970-
.br
1971-
$ firejail \-\-notpm
1972-
1978+
TPM devices are now blocked by default, see \fB\-\-keep-dev-tpm\fR.
19731979
.TP
19741980
\fB\-\-notv
19751981
Disable DVB (Digital Video Broadcasting) TV devices.
@@ -2225,10 +2231,10 @@ $ pwd
22252231
.TP
22262232
\fB\-\-private-dev
22272233
Create a new /dev directory.
2228-
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tpm,
2229-
tty, urandom, usb, video and zero devices are available.
2230-
Use the options \-\-no3d, \-\-nodvd, \-\-nosound, \-\-notpm, \-\-notv,
2231-
\-\-nou2f and \-\-novideo for additional restrictions.
2234+
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tty,
2235+
urandom, usb, video and zero devices are available.
2236+
Use the options \-\-no3d, \-\-nodvd, \-\-nosound, \-\-notv, \-\-nou2f and
2237+
\-\-novideo for additional restrictions.
22322238
.br
22332239

22342240
.br

src/zsh_completion/_firejail.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ _firejail_args=(
103103
'--join-or-start=-[join the sandbox or start a new one name|pid]: :_all_firejails'
104104
'--keep-config-pulse[disable automatic ~/.config/pulse init]'
105105
'--keep-dev-ntsync[/dev/ntsync character device is untouched (even with --private-dev)]'
106+
'--keep-dev-tpm[/dev/tpm* devices are untouched (even with --private-dev)]'
106107
'--keep-dev-shm[/dev/shm directory is untouched (even with --private-dev)]'
107108
'--keep-fd[inherit open file descriptors to sandbox]: :'
108109
'--keep-shell-rc[do not copy shell rc files from /etc/skel]'
@@ -134,7 +135,6 @@ _firejail_args=(
134135
'--nonewprivs[sets the NO_NEW_PRIVS prctl]'
135136
'--noprinters[disable printers]'
136137
'--nosound[disable sound system]'
137-
'--notpm[disable TPM devices]'
138138
'--nou2f[disable U2F devices]'
139139
'--novideo[disable video devices]'
140140
'--private[temporary home directory]'

0 commit comments

Comments
 (0)