Skip to content

Commit 4013c14

Browse files
committed
usermodehelper: reset umask to default before executing user process
Kernel threads intentionally do CLONE_FS in order to follow any changes that 'init' does to set up the root directory (or cwd). It is admittedly a bit odd, but it avoids the situation where 'init' does some extensive setup to initialize the system environment, and then we execute a usermode helper program, and it uses the original FS setup from boot time that may be very limited and incomplete. [ Both Al Viro and Eric Biederman point out that 'pivot_root()' will follow the root regardless, since it fixes up other users of root (see chroot_fs_refs() for details), but overmounting root and doing a chroot() would not. ] However, Vegard Nossum noticed that the CLONE_FS not only means that we follow the root and current working directories, it also means we share umask with whatever init changed it to. That wasn't intentional. Just reset umask to the original default (0022) before actually starting the usermode helper program. Reported-by: Vegard Nossum <[email protected]> Cc: Al Viro <[email protected]> Acked-by: Eric W. Biederman <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent d1a819a commit 4013c14

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

kernel/umh.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/cred.h>
1515
#include <linux/file.h>
1616
#include <linux/fdtable.h>
17+
#include <linux/fs_struct.h>
1718
#include <linux/workqueue.h>
1819
#include <linux/security.h>
1920
#include <linux/mount.h>
@@ -71,6 +72,14 @@ static int call_usermodehelper_exec_async(void *data)
7172
flush_signal_handlers(current, 1);
7273
spin_unlock_irq(&current->sighand->siglock);
7374

75+
/*
76+
* Initial kernel threads share ther FS with init, in order to
77+
* get the init root directory. But we've now created a new
78+
* thread that is going to execve a user process and has its own
79+
* 'struct fs_struct'. Reset umask to the default.
80+
*/
81+
current->fs->umask = 0022;
82+
7483
/*
7584
* Our parent (unbound workqueue) runs with elevated scheduling
7685
* priority. Avoid propagating that into the userspace child.

0 commit comments

Comments
 (0)