Skip to content

Commit

Permalink
feature: keep ntsync char device when private-dev is used
Browse files Browse the repository at this point in the history
feature: add nontsync argument to blacklist /dev/ntsync
  • Loading branch information
weebnix committed Feb 22, 2025
1 parent 733f9a9 commit 14f2995
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions contrib/syntax/lists/profile_commands_arg0.list
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ nodvd
nogroups
noinput
nonewprivs
nontsync
noprinters
noroot
nosound
Expand Down
1 change: 1 addition & 0 deletions src/fbuilder/build_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void build_profile(int argc, char **argv, int index, FILE *fp) {
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");
fprintf(fp, "#nontsync\t# disable ntsync char device\n");
build_protocol(trace_output, fp);
fprintf(fp, "seccomp !chroot\t# allowing chroot, just in case this is an Electron app\n");
fprintf(fp, "#tracelog\t# send blacklist violations to syslog\n");
Expand Down
2 changes: 2 additions & 0 deletions src/firejail/firejail.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ extern int arg_scan; // arp-scan all interfaces
extern int arg_whitelist; // whitelist command
extern int arg_nosound; // disable sound
extern int arg_novideo; //disable video devices in /dev
extern int arg_nontsync; // disable ntsync char device in /dev
extern int arg_no3d; // disable 3d hardware acceleration
extern int arg_noprinters; // disable printers
extern int arg_quiet; // no output for scripting
Expand Down Expand Up @@ -645,6 +646,7 @@ void fs_private_dev(void);
void fs_dev_disable_sound(void);
void fs_dev_disable_3d(void);
void fs_dev_disable_video(void);
void fs_dev_disable_ntsync(void);
void fs_dev_disable_tv(void);
void fs_dev_disable_dvd(void);
void fs_dev_disable_tpm(void);
Expand Down
16 changes: 14 additions & 2 deletions src/firejail/fs_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ typedef enum {
DEV_DVD,
DEV_TPM,
DEV_U2F,
DEV_INPUT
DEV_INPUT,
DEV_NTSYNC
} DEV_TYPE;


Expand Down Expand Up @@ -98,6 +99,7 @@ static DevEntry dev[] = {
{"/dev/hidraw9", RUN_DEV_DIR "/hidraw9", DEV_U2F},
{"/dev/usb", RUN_DEV_DIR "/usb", DEV_U2F}, // USB devices such as Yubikey, U2F
{"/dev/input", RUN_DEV_DIR "/input", DEV_INPUT},
{"/dev/ntsync", RUN_DEV_DIR "/ntsync", DEV_NTSYNC},
{NULL, NULL, DEV_NONE}
};

Expand All @@ -114,7 +116,8 @@ static void deventry_mount(void) {
(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)) {
(dev[i].type == DEV_INPUT && arg_noinput == 0) ||
(dev[i].type == DEV_NTSYNC && arg_nontsync == 0)) {

int dir = is_dir(dev[i].run_fname);
if (arg_debug)
Expand Down Expand Up @@ -365,6 +368,15 @@ void fs_dev_disable_video(void) {
}
}

void fs_dev_disable_ntsync(void) {
int i = 0;
while (dev[i].dev_fname != NULL) {
if (dev[i].type == DEV_NTSYNC)
disable_file_or_dir(dev[i].dev_fname);
i++;
}
}

void fs_dev_disable_3d(void) {
int i = 0;
while (dev[i].dev_fname != NULL) {
Expand Down
3 changes: 3 additions & 0 deletions src/firejail/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ int arg_scan = 0; // arp-scan all interfaces
int arg_whitelist = 0; // whitelist command
int arg_nosound = 0; // disable sound
int arg_novideo = 0; //disable video devices in /dev
int arg_nontsync = 0; // disable ntsync char device in /dev
int arg_no3d; // disable 3d hardware acceleration
int arg_noprinters = 0; // disable printers
int arg_quiet = 0; // no output for scripting
Expand Down Expand Up @@ -2209,6 +2210,8 @@ int main(int argc, char **argv, char **envp) {
arg_keep_config_pulse = 1;
else if (strcmp(argv[i], "--novideo") == 0)
arg_novideo = 1;
else if (strcmp(argv[i], "--nontsync") == 0)
arg_nontsync = 1;
else if (strcmp(argv[i], "--no3d") == 0)
arg_no3d = 1;
else if (strcmp(argv[i], "--noprinters") == 0) {
Expand Down
4 changes: 4 additions & 0 deletions src/firejail/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
arg_novideo = 1;
return 0;
}
else if (strcmp(ptr, "nontsync") == 0) {
arg_nontsync = 1;
return 0;
}
else if (strcmp(ptr, "no3d") == 0) {
arg_no3d = 1;
return 0;
Expand Down
3 changes: 3 additions & 0 deletions src/firejail/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,9 @@ int sandbox(void* sandbox_arg) {
if (arg_novideo)
fs_dev_disable_video();

if (arg_nontsync)
fs_dev_disable_ntsync();

if (arg_noinput)
fs_dev_disable_input();

Expand Down
1 change: 1 addition & 0 deletions src/firejail/usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ static const char *const usage_str =
#endif
" --nosound - disable sound system.\n"
" --novideo - disable video devices.\n"
" --nontsync - disable ntsync char device.\n"
" --notpm - disable TPM devices.\n"
" --nou2f - disable U2F devices.\n"
" --nowhitelist=filename - disable whitelist for file or directory.\n"
Expand Down
3 changes: 3 additions & 0 deletions src/man/firejail-profile.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,9 @@ Disable U2F devices.
\fBnovideo
Disable video capture devices.
.TP
\fBnontsync
Disable ntsync char device.
.TP
\fBmachine-id
Spoof id number in /etc/machine-id file - a new random id is generated inside the sandbox.
#ifdef HAVE_NETWORK
Expand Down
5 changes: 5 additions & 0 deletions src/man/firejail.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,11 @@ $ firejail \-\-nou2f
Disable video devices.
.br

.TP
\fB\-\-nontsync
Disable ntsync char device.
.br

.TP
\fB\-\-nowhitelist=dirname_or_filename
Disable whitelist for this directory or file.
Expand Down
1 change: 1 addition & 0 deletions src/zsh_completion/_firejail.in
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ _firejail_args=(
'--notpm[disable TPM devices]'
'--nou2f[disable U2F devices]'
'--novideo[disable video devices]'
'--nontsync[disable ntsync char device]'
'--private[temporary home directory]'
'--private=-[use directory as user home]: :_files -/'
'--private-bin=-[build a new /bin in a temporary filesystem, and copy the programs in the list]: :_files -W /usr/bin'
Expand Down

0 comments on commit 14f2995

Please sign in to comment.