Skip to content

Commit 6b97aad

Browse files
qdiikmk3
authored andcommitted
feature: add notpm command & keep tpm devices in private-dev
An ssh private key may be stored in a Trusted Platform Module (TPM) device and `private-dev` in ssh.profile currently breaks this use-case, as it does not keep tpm devices (see #6379). So add a new `notpm` command and keep tpm devices in /dev by default with `private-dev` unless `notpm` is used.
1 parent ad0e8c1 commit 6b97aad

File tree

13 files changed

+56
-8
lines changed

13 files changed

+56
-8
lines changed

contrib/syntax/lists/profile_commands_arg0.list

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ nonewprivs
2727
noprinters
2828
noroot
2929
nosound
30+
notpm
3031
notv
3132
nou2f
3233
novideo

etc/profile-a-l/default.profile

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

etc/templates/profile.template

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ include globals.local
175175
#noprinters
176176
#noroot
177177
#nosound
178+
#notpm
178179
#notv
179180
#nou2f
180181
#novideo

src/fbuilder/build_profile.c

+1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ 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");
141142
fprintf(fp, "#notv\t# disable DVB TV devices\n");
142143
fprintf(fp, "#nou2f\t# disable U2F devices\n");
143144
fprintf(fp, "#novideo\t# disable video capture devices\n");

src/firejail/firejail.h

+2
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ extern int arg_noprofile; // use default.profile if none other found/specified
368368
extern int arg_memory_deny_write_execute; // block writable and executable memory
369369
extern int arg_notv; // --notv
370370
extern int arg_nodvd; // --nodvd
371+
extern int arg_notpm; // --notpm
371372
extern int arg_nou2f; // --nou2f
372373
extern int arg_noinput; // --noinput
373374
extern int arg_deterministic_exit_code; // always exit with first child's exit status
@@ -646,6 +647,7 @@ void fs_dev_disable_3d(void);
646647
void fs_dev_disable_video(void);
647648
void fs_dev_disable_tv(void);
648649
void fs_dev_disable_dvd(void);
650+
void fs_dev_disable_tpm(void);
649651
void fs_dev_disable_u2f(void);
650652
void fs_dev_disable_input(void);
651653

src/firejail/fs_dev.c

+17
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ typedef enum {
3939
DEV_VIDEO,
4040
DEV_TV,
4141
DEV_DVD,
42+
DEV_TPM,
4243
DEV_U2F,
4344
DEV_INPUT
4445
} DEV_TYPE;
@@ -79,6 +80,12 @@ static DevEntry dev[] = {
7980
{"/dev/video9", RUN_DEV_DIR "/video9", DEV_VIDEO},
8081
{"/dev/dvb", RUN_DEV_DIR "/dvb", DEV_TV}, // DVB (Digital Video Broadcasting) - TV device
8182
{"/dev/sr0", RUN_DEV_DIR "/sr0", DEV_DVD}, // for DVD and audio CD players
83+
{"/dev/tpm0", RUN_DEV_DIR "/tpm0", DEV_TPM}, // TPM (Trusted Platform Module) devices
84+
{"/dev/tpm1", RUN_DEV_DIR "/tpm1", DEV_TPM},
85+
{"/dev/tpm2", RUN_DEV_DIR "/tpm2", DEV_TPM},
86+
{"/dev/tpm3", RUN_DEV_DIR "/tpm3", DEV_TPM},
87+
{"/dev/tpm4", RUN_DEV_DIR "/tpm4", DEV_TPM},
88+
{"/dev/tpm5", RUN_DEV_DIR "/tpm5", DEV_TPM},
8289
{"/dev/hidraw0", RUN_DEV_DIR "/hidraw0", DEV_U2F},
8390
{"/dev/hidraw1", RUN_DEV_DIR "/hidraw1", DEV_U2F},
8491
{"/dev/hidraw2", RUN_DEV_DIR "/hidraw2", DEV_U2F},
@@ -105,6 +112,7 @@ static void deventry_mount(void) {
105112
(dev[i].type == DEV_VIDEO && arg_novideo == 0) ||
106113
(dev[i].type == DEV_TV && arg_notv == 0) ||
107114
(dev[i].type == DEV_DVD && arg_nodvd == 0) ||
115+
(dev[i].type == DEV_TPM && arg_notpm == 0) ||
108116
(dev[i].type == DEV_U2F && arg_nou2f == 0) ||
109117
(dev[i].type == DEV_INPUT && arg_noinput == 0)) {
110118

@@ -384,6 +392,15 @@ void fs_dev_disable_dvd(void) {
384392
}
385393
}
386394

395+
void fs_dev_disable_tpm(void) {
396+
int i = 0;
397+
while (dev[i].dev_fname != NULL) {
398+
if (dev[i].type == DEV_TPM)
399+
disable_file_or_dir(dev[i].dev_fname);
400+
i++;
401+
}
402+
}
403+
387404
void fs_dev_disable_u2f(void) {
388405
int i = 0;
389406
while (dev[i].dev_fname != NULL) {

src/firejail/main.c

+3
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ int arg_noprofile = 0; // use default.profile if none other found/specified
155155
int arg_memory_deny_write_execute = 0; // block writable and executable memory
156156
int arg_notv = 0; // --notv
157157
int arg_nodvd = 0; // --nodvd
158+
int arg_notpm = 0; // --notpm
158159
int arg_nou2f = 0; // --nou2f
159160
int arg_noinput = 0; // --noinput
160161
int arg_deterministic_exit_code = 0; // always exit with first child's exit status
@@ -2209,6 +2210,8 @@ int main(int argc, char **argv, char **envp) {
22092210
arg_notv = 1;
22102211
else if (strcmp(argv[i], "--nodvd") == 0)
22112212
arg_nodvd = 1;
2213+
else if (strcmp(argv[i], "--notpm") == 0)
2214+
arg_notpm = 1;
22122215
else if (strcmp(argv[i], "--nou2f") == 0)
22132216
arg_nou2f = 1;
22142217
else if (strcmp(argv[i], "--noinput") == 0)

src/firejail/profile.c

+4
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
618618
#endif
619619
return 1;
620620
}
621+
else if (strcmp(ptr, "notpm") == 0) {
622+
arg_notpm = 1;
623+
return 0;
624+
}
621625
else if (strcmp(ptr, "nou2f") == 0) {
622626
arg_nou2f = 1;
623627
return 0;

src/firejail/sandbox.c

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

1104+
if (arg_notpm)
1105+
fs_dev_disable_tpm();
1106+
11041107
if (arg_nou2f)
11051108
fs_dev_disable_u2f();
11061109

src/firejail/usage.c

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ static const char *const usage_str =
191191
" --nosound - disable sound system.\n"
192192
" --noautopulse - disable automatic ~/.config/pulse init.\n"
193193
" --novideo - disable video devices.\n"
194+
" --notpm - disable TPM devices.\n"
194195
" --nou2f - disable U2F devices.\n"
195196
" --nowhitelist=filename - disable whitelist for file or directory.\n"
196197
" --oom=value - configure OutOfMemory killer for the sandbox\n"

src/man/firejail-profile.5.in

+7-4
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,10 @@ Set working directory inside the jail. Full directory path is required. Symbolic
383383
.TP
384384
\fBprivate-dev
385385
Create a new /dev directory.
386-
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tty,
387-
urandom, usb, video and zero devices are available.
388-
Use the options no3d, nodvd, nosound, notv, nou2f and novideo for additional
389-
restrictions.
386+
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tpm,
387+
tty, urandom, usb, video and zero devices are available.
388+
Use the options no3d, nodvd, nosound, notpm, notv, nou2f and novideo for
389+
additional restrictions.
390390

391391
.TP
392392
\fBprivate-etc file,directory
@@ -819,6 +819,9 @@ Disable input devices.
819819
\fBnosound
820820
Disable sound system.
821821
.TP
822+
\fBnotpm
823+
Disable Trusted Platform Module (TPM) devices.
824+
.TP
822825
\fBnotv
823826
Disable DVB (Digital Video Broadcasting) TV devices.
824827
.TP

src/man/firejail.1.in

+14-4
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,16 @@ Example:
19181918
.br
19191919
$ firejail \-\-nosound firefox
19201920

1921+
.TP
1922+
\fB\-\-notpm
1923+
Disable Trusted Platform Module (TPM) devices.
1924+
.br
1925+
1926+
.br
1927+
Example:
1928+
.br
1929+
$ firejail \-\-notpm
1930+
19211931
.TP
19221932
\fB\-\-notv
19231933
Disable DVB (Digital Video Broadcasting) TV devices.
@@ -2173,10 +2183,10 @@ $ pwd
21732183
.TP
21742184
\fB\-\-private-dev
21752185
Create a new /dev directory.
2176-
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tty,
2177-
urandom, usb, video and zero devices are available.
2178-
Use the options \-\-no3d, \-\-nodvd, \-\-nosound, \-\-notv, \-\-nou2f and
2179-
\-\-novideo for additional restrictions.
2186+
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tpm,
2187+
tty, urandom, usb, video and zero devices are available.
2188+
Use the options \-\-no3d, \-\-nodvd, \-\-nosound, \-\-notv, \-\-notpm \-\-nou2f
2189+
and \-\-novideo for additional restrictions.
21802190
.br
21812191

21822192
.br

src/zsh_completion/_firejail.in

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ _firejail_args=(
134134
'--nonewprivs[sets the NO_NEW_PRIVS prctl]'
135135
'--noprinters[disable printers]'
136136
'--nosound[disable sound system]'
137+
'--notpm[disable TPM devices]'
137138
'--nou2f[disable U2F devices]'
138139
'--novideo[disable video devices]'
139140
'--private[temporary home directory]'

0 commit comments

Comments
 (0)