Skip to content

Commit a42e392

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 ad8a3ed commit a42e392

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
*/
@@ -2030,6 +2036,11 @@ __latent_entropy struct task_struct *copy_process(
20302036
return ERR_PTR(-EINVAL);
20312037
}
20322038

2039+
if ((clone_flags & CLONE_NEWUSER) && !unprivileged_userns_clone) {
2040+
if (!capable(CAP_SYS_ADMIN))
2041+
return ERR_PTR(-EPERM);
2042+
}
2043+
20332044
/*
20342045
* Force any signals received before this point to be delivered
20352046
* before the fork happens. Collect up signals sent to multiple
@@ -3066,6 +3077,10 @@ static int check_unshare_flags(unsigned long unshare_flags)
30663077
if (!current_is_single_threaded())
30673078
return -EINVAL;
30683079
}
3080+
if ((unshare_flags & CLONE_NEWUSER) && !unprivileged_userns_clone) {
3081+
if (!capable(CAP_SYS_ADMIN))
3082+
return -EPERM;
3083+
}
30693084

30703085
return 0;
30713086
}
@@ -3296,6 +3311,15 @@ static const struct ctl_table fork_sysctl_table[] = {
32963311
.mode = 0644,
32973312
.proc_handler = sysctl_max_threads,
32983313
},
3314+
#ifdef CONFIG_USER_NS
3315+
{
3316+
.procname = "unprivileged_userns_clone",
3317+
.data = &unprivileged_userns_clone,
3318+
.maxlen = sizeof(int),
3319+
.mode = 0644,
3320+
.proc_handler = proc_dointvec,
3321+
},
3322+
#endif
32993323
};
33003324

33013325
static int __init init_fork_sysctl(void)

0 commit comments

Comments
 (0)