Skip to content

Commit f0b3127

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 6a75390 commit f0b3127

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

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
@@ -3067,6 +3078,10 @@ static int check_unshare_flags(unsigned long unshare_flags)
30673078
if (!current_is_single_threaded())
30683079
return -EINVAL;
30693080
}
3081+
if ((unshare_flags & CLONE_NEWUSER) && !unprivileged_userns_clone) {
3082+
if (!capable(CAP_SYS_ADMIN))
3083+
return -EPERM;
3084+
}
30703085

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

33023326
static int __init init_fork_sysctl(void)

0 commit comments

Comments
 (0)