feature: add notpm command & keep tpm devices in private-dev (#6390)

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.
This commit is contained in:
qdii 2024-07-09 03:43:55 +02:00 committed by GitHub
parent ad0e8c1272
commit 001320226c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 56 additions and 8 deletions

View file

@ -27,6 +27,7 @@ nonewprivs
noprinters
noroot
nosound
notpm
notv
nou2f
novideo

View file

@ -37,6 +37,7 @@ noinput
nonewprivs
noroot
#nosound
#notpm
notv
#nou2f
novideo

View file

@ -175,6 +175,7 @@ include globals.local
#noprinters
#noroot
#nosound
#notpm
#notv
#nou2f
#novideo

View file

@ -138,6 +138,7 @@ void build_profile(int argc, char **argv, int index, FILE *fp) {
fprintf(fp, "#noinput\t# disable input devices\n");
fprintf(fp, "nonewprivs\n");
fprintf(fp, "noroot\n");
fprintf(fp, "#notpm\t# disable TPM devices\n");
fprintf(fp, "#notv\t# disable DVB TV devices\n");
fprintf(fp, "#nou2f\t# disable U2F devices\n");
fprintf(fp, "#novideo\t# disable video capture devices\n");

View file

@ -368,6 +368,7 @@ extern int arg_noprofile; // use default.profile if none other found/specified
extern int arg_memory_deny_write_execute; // block writable and executable memory
extern int arg_notv; // --notv
extern int arg_nodvd; // --nodvd
extern int arg_notpm; // --notpm
extern int arg_nou2f; // --nou2f
extern int arg_noinput; // --noinput
extern int arg_deterministic_exit_code; // always exit with first child's exit status
@ -646,6 +647,7 @@ void fs_dev_disable_3d(void);
void fs_dev_disable_video(void);
void fs_dev_disable_tv(void);
void fs_dev_disable_dvd(void);
void fs_dev_disable_tpm(void);
void fs_dev_disable_u2f(void);
void fs_dev_disable_input(void);

View file

@ -39,6 +39,7 @@ typedef enum {
DEV_VIDEO,
DEV_TV,
DEV_DVD,
DEV_TPM,
DEV_U2F,
DEV_INPUT
} DEV_TYPE;
@ -79,6 +80,12 @@ static DevEntry dev[] = {
{"/dev/video9", RUN_DEV_DIR "/video9", DEV_VIDEO},
{"/dev/dvb", RUN_DEV_DIR "/dvb", DEV_TV}, // DVB (Digital Video Broadcasting) - TV device
{"/dev/sr0", RUN_DEV_DIR "/sr0", DEV_DVD}, // for DVD and audio CD players
{"/dev/tpm0", RUN_DEV_DIR "/tpm0", DEV_TPM}, // TPM (Trusted Platform Module) devices
{"/dev/tpm1", RUN_DEV_DIR "/tpm1", DEV_TPM},
{"/dev/tpm2", RUN_DEV_DIR "/tpm2", DEV_TPM},
{"/dev/tpm3", RUN_DEV_DIR "/tpm3", DEV_TPM},
{"/dev/tpm4", RUN_DEV_DIR "/tpm4", DEV_TPM},
{"/dev/tpm5", RUN_DEV_DIR "/tpm5", DEV_TPM},
{"/dev/hidraw0", RUN_DEV_DIR "/hidraw0", DEV_U2F},
{"/dev/hidraw1", RUN_DEV_DIR "/hidraw1", DEV_U2F},
{"/dev/hidraw2", RUN_DEV_DIR "/hidraw2", DEV_U2F},
@ -105,6 +112,7 @@ static void deventry_mount(void) {
(dev[i].type == DEV_VIDEO && arg_novideo == 0) ||
(dev[i].type == DEV_TV && arg_notv == 0) ||
(dev[i].type == DEV_DVD && arg_nodvd == 0) ||
(dev[i].type == DEV_TPM && arg_notpm == 0) ||
(dev[i].type == DEV_U2F && arg_nou2f == 0) ||
(dev[i].type == DEV_INPUT && arg_noinput == 0)) {
@ -384,6 +392,15 @@ void fs_dev_disable_dvd(void) {
}
}
void fs_dev_disable_tpm(void) {
int i = 0;
while (dev[i].dev_fname != NULL) {
if (dev[i].type == DEV_TPM)
disable_file_or_dir(dev[i].dev_fname);
i++;
}
}
void fs_dev_disable_u2f(void) {
int i = 0;
while (dev[i].dev_fname != NULL) {

View file

@ -155,6 +155,7 @@ int arg_noprofile = 0; // use default.profile if none other found/specified
int arg_memory_deny_write_execute = 0; // block writable and executable memory
int arg_notv = 0; // --notv
int arg_nodvd = 0; // --nodvd
int arg_notpm = 0; // --notpm
int arg_nou2f = 0; // --nou2f
int arg_noinput = 0; // --noinput
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) {
arg_notv = 1;
else if (strcmp(argv[i], "--nodvd") == 0)
arg_nodvd = 1;
else if (strcmp(argv[i], "--notpm") == 0)
arg_notpm = 1;
else if (strcmp(argv[i], "--nou2f") == 0)
arg_nou2f = 1;
else if (strcmp(argv[i], "--noinput") == 0)

View file

@ -618,6 +618,10 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
#endif
return 1;
}
else if (strcmp(ptr, "notpm") == 0) {
arg_notpm = 1;
return 0;
}
else if (strcmp(ptr, "nou2f") == 0) {
arg_nou2f = 1;
return 0;

View file

@ -1101,6 +1101,9 @@ int sandbox(void* sandbox_arg) {
if (arg_nodvd)
fs_dev_disable_dvd();
if (arg_notpm)
fs_dev_disable_tpm();
if (arg_nou2f)
fs_dev_disable_u2f();

View file

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

View file

@ -383,10 +383,10 @@ Set working directory inside the jail. Full directory path is required. Symbolic
.TP
\fBprivate-dev
Create a new /dev directory.
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tty,
urandom, usb, video and zero devices are available.
Use the options no3d, nodvd, nosound, notv, nou2f and novideo for additional
restrictions.
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tpm,
tty, urandom, usb, video and zero devices are available.
Use the options no3d, nodvd, nosound, notpm, notv, nou2f and novideo for
additional restrictions.
.TP
\fBprivate-etc file,directory
@ -819,6 +819,9 @@ Disable input devices.
\fBnosound
Disable sound system.
.TP
\fBnotpm
Disable Trusted Platform Module (TPM) devices.
.TP
\fBnotv
Disable DVB (Digital Video Broadcasting) TV devices.
.TP

View file

@ -1918,6 +1918,16 @@ Example:
.br
$ firejail \-\-nosound firefox
.TP
\fB\-\-notpm
Disable Trusted Platform Module (TPM) devices.
.br
.br
Example:
.br
$ firejail \-\-notpm
.TP
\fB\-\-notv
Disable DVB (Digital Video Broadcasting) TV devices.
@ -2173,10 +2183,10 @@ $ pwd
.TP
\fB\-\-private-dev
Create a new /dev directory.
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tty,
urandom, usb, video and zero devices are available.
Use the options \-\-no3d, \-\-nodvd, \-\-nosound, \-\-notv, \-\-nou2f and
\-\-novideo for additional restrictions.
Only disc, dri, dvb, full, hidraw, log, null, ptmx, pts, random, shm, snd, tpm,
tty, urandom, usb, video and zero devices are available.
Use the options \-\-no3d, \-\-nodvd, \-\-nosound, \-\-notpm, \-\-notv,
\-\-nou2f and \-\-novideo for additional restrictions.
.br
.br

View file

@ -134,6 +134,7 @@ _firejail_args=(
'--nonewprivs[sets the NO_NEW_PRIVS prctl]'
'--noprinters[disable printers]'
'--nosound[disable sound system]'
'--notpm[disable TPM devices]'
'--nou2f[disable U2F devices]'
'--novideo[disable video devices]'
'--private[temporary home directory]'