Skip to content

Commit 29471c8

Browse files
committed
Set a safer umask(2) when running as a daemon.
When running as a daemon. unit currently sets umask(0), i.e no umask. This is resulting in various directories being created with a mode of 0777, e.g rwxrwxrwx this is currently affecting cgroup and rootfs directories, which are being created with a mode of 0777, and when running as a daemon as there is no umask to restrict the permissions. This also affects the language modules (the umask is inherited over fork(2)) whereby unless something explicitly sets a umask, files and directories will be created with full permissions, 0666 (rw-rw-rw-)/ 0777 (rwxrwxrwx) respectively. This could be an unwitting security issue. My original idea was to just remove the umask(0) call and thus inherit the umask from the executing shell/program. However there was some concern about just inheriting whatever umask was in effect. Alex suggested that rather than simply removing the umask(0) call we change it to a value of 022 (which is a common default), which will result in directories and files with permissions at most of 0755 (rwxr-xr-x) & 0644 (rw-r--r--). If applications need some other umask set, they can (as they always have been able to) set their own umask(2). Suggested-by: Alejandro Colomar <[email protected]> Reviewed-by: Liam Crilly <[email protected]> Signed-off-by: Andrew Clayton <[email protected]>
1 parent 5c9113d commit 29471c8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/nxt_process.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,10 +1156,10 @@ nxt_process_daemon(nxt_task_t *task)
11561156
}
11571157

11581158
/*
1159-
* Reset file mode creation mask: any access
1160-
* rights can be set on file creation.
1159+
* Set a sefe umask to give at most 755/644 permissions on
1160+
* directories/files.
11611161
*/
1162-
umask(0);
1162+
umask(0022);
11631163

11641164
/* Redirect STDIN and STDOUT to the "/dev/null". */
11651165

0 commit comments

Comments
 (0)