Skip to content

Commit 4f003da

Browse files
author
netblue30
committed
prevent leaking user information by modifying /home directory, /etc/passwd and /etc/group
1 parent bd16cb3 commit 4f003da

File tree

4 files changed

+344
-54
lines changed

4 files changed

+344
-54
lines changed

RELNOTES

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
firejail (0.9.34) baseline; urgency=low
1+
firejail (0.9.35) baseline; urgency=low
22
* added unbound and dnscrypt-proxy profiles
33
* added --noblacklist option
44
* whitelist command enhancements
5+
* prevent leaking user information by modifying /home directory,
6+
/etc/passwd and /etc/group
57
* bugfixes
68
-- netblue30 <[email protected]> ongoing development
79

src/firejail/firejail.h

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#define RESOLVCONF_FILE "/run/firejail/mnt/resolv.conf"
5353
#define LDPRELOAD_FILE "/run/firejail/mnt/ld.so.preload"
5454
#define UTMP_FILE "/run/firejail/mnt/utmp"
55+
#define PASSWD_FILE "/run/firejail/mnt/passwd"
56+
#define GROUP_FILE "/run/firejail/mnt/group"
5557

5658
// profiles
5759
#define DEFAULT_USER_PROFILE "generic"
@@ -468,5 +470,10 @@ void protocol_store(const char *prlist);
468470
void protocol_filter(void);
469471
void protocol_filter_save(void);
470472
void protocol_filter_load(const char *fname);
473+
474+
// restrict_users.c
475+
void restrict_users(void);
476+
477+
471478
#endif
472479

src/firejail/fs.c

+6-53
Original file line numberDiff line numberDiff line change
@@ -539,49 +539,6 @@ void fs_proc_sys_dev_boot(void) {
539539
}
540540
}
541541

542-
static void sanitize_home(void) {
543-
assert(getuid() != 0); // this code works only for regular users
544-
545-
if (arg_debug)
546-
printf("Cleaning /home directory\n");
547-
548-
struct stat s;
549-
if (stat(cfg.homedir, &s) == -1) {
550-
// cannot find home directory, just return
551-
fprintf(stderr, "Warning: cannot find home directory\n");
552-
return;
553-
}
554-
555-
fs_build_mnt_dir();
556-
if (mkdir(WHITELIST_HOME_DIR, 0755) == -1)
557-
errExit("mkdir");
558-
559-
// keep a copy of the user home directory
560-
if (mount(cfg.homedir, WHITELIST_HOME_DIR, NULL, MS_BIND|MS_REC, NULL) < 0)
561-
errExit("mount bind");
562-
563-
// mount tmpfs in the new home
564-
if (mount("tmpfs", "/home", "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0)
565-
errExit("mount tmpfs");
566-
567-
// create user home directory
568-
if (mkdir(cfg.homedir, 0755) == -1)
569-
errExit("mkdir");
570-
571-
// set mode and ownership
572-
if (chown(cfg.homedir, s.st_uid, s.st_gid) == -1)
573-
errExit("chown");
574-
if (chmod(cfg.homedir, s.st_mode) == -1)
575-
errExit("chmod");
576-
577-
// mount user home directory
578-
if (mount(WHITELIST_HOME_DIR, cfg.homedir, NULL, MS_BIND|MS_REC, NULL) < 0)
579-
errExit("mount bind");
580-
581-
// mask home dir under /run
582-
if (mount("tmpfs", WHITELIST_HOME_DIR, "tmpfs", MS_NOSUID | MS_NODEV | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0)
583-
errExit("mount tmpfs");
584-
}
585542

586543
// build a basic read-only filesystem
587544
void fs_basic_fs(void) {
@@ -605,9 +562,8 @@ void fs_basic_fs(void) {
605562
fs_var_cache();
606563
fs_var_utmp();
607564

608-
// only in user mode
609-
if (getuid())
610-
sanitize_home();
565+
// don't leak user information
566+
restrict_users();
611567
}
612568

613569

@@ -751,9 +707,8 @@ void fs_overlayfs(void) {
751707
fs_var_cache();
752708
fs_var_utmp();
753709

754-
// only in user mode
755-
if (getuid())
756-
sanitize_home();
710+
// don't leak user information
711+
restrict_users();
757712

758713
// cleanup and exit
759714
free(option);
@@ -874,10 +829,8 @@ void fs_chroot(const char *rootdir) {
874829
fs_var_cache();
875830
fs_var_utmp();
876831

877-
// only in user mode
878-
if (getuid())
879-
sanitize_home();
880-
832+
// don't leak user information
833+
restrict_users();
881834
}
882835
#endif
883836

0 commit comments

Comments
 (0)