Skip to content

Commit 1387fe8

Browse files
hallynheftig
authored andcommitted
add sysctl to allow disabling unprivileged CLONE_NEWUSER
This is a short-term patch. Unprivileged use of CLONE_NEWUSER is certainly an intended feature of user namespaces. However for at least saucy we want to make sure that, if any security issues are found, we have a fail-safe. [bwh: Remove unneeded binary sysctl bits] [bwh: Keep this sysctl, but change the default to enabled] [heftig: correct commit subject to reduce confusion] [heftig: for 6.17, move all code into kernel/fork.c]
1 parent 1bfd0fa commit 1387fe8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

kernel/fork.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@
123123

124124
#include <kunit/visibility.h>
125125

126+
#ifdef CONFIG_USER_NS
127+
static int unprivileged_userns_clone = 1;
128+
#else
129+
#define unprivileged_userns_clone 1
130+
#endif
131+
126132
/*
127133
* Minimum number of threads to boot the kernel
128134
*/
@@ -1982,6 +1988,11 @@ __latent_entropy struct task_struct *copy_process(
19821988
return ERR_PTR(-EINVAL);
19831989
}
19841990

1991+
if ((clone_flags & CLONE_NEWUSER) && !unprivileged_userns_clone) {
1992+
if (!capable(CAP_SYS_ADMIN))
1993+
return ERR_PTR(-EPERM);
1994+
}
1995+
19851996
/*
19861997
* Force any signals received before this point to be delivered
19871998
* before the fork happens. Collect up signals sent to multiple
@@ -3023,6 +3034,10 @@ static int check_unshare_flags(unsigned long unshare_flags)
30233034
if (!current_is_single_threaded())
30243035
return -EINVAL;
30253036
}
3037+
if ((unshare_flags & CLONE_NEWUSER) && !unprivileged_userns_clone) {
3038+
if (!capable(CAP_SYS_ADMIN))
3039+
return -EPERM;
3040+
}
30263041

30273042
return 0;
30283043
}
@@ -3253,6 +3268,15 @@ static const struct ctl_table fork_sysctl_table[] = {
32533268
.mode = 0644,
32543269
.proc_handler = sysctl_max_threads,
32553270
},
3271+
#ifdef CONFIG_USER_NS
3272+
{
3273+
.procname = "unprivileged_userns_clone",
3274+
.data = &unprivileged_userns_clone,
3275+
.maxlen = sizeof(int),
3276+
.mode = 0644,
3277+
.proc_handler = proc_dointvec,
3278+
},
3279+
#endif
32563280
};
32573281

32583282
static int __init init_fork_sysctl(void)

0 commit comments

Comments
 (0)