Skip to content

Commit ee17d11

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 5dfbc53 commit ee17d11

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
*/
@@ -1990,6 +1996,11 @@ __latent_entropy struct task_struct *copy_process(
19901996
return ERR_PTR(-EINVAL);
19911997
}
19921998

1999+
if ((clone_flags & CLONE_NEWUSER) && !unprivileged_userns_clone) {
2000+
if (!capable(CAP_SYS_ADMIN))
2001+
return ERR_PTR(-EPERM);
2002+
}
2003+
19932004
/*
19942005
* Force any signals received before this point to be delivered
19952006
* before the fork happens. Collect up signals sent to multiple
@@ -3025,6 +3036,10 @@ static int check_unshare_flags(unsigned long unshare_flags)
30253036
if (!current_is_single_threaded())
30263037
return -EINVAL;
30273038
}
3039+
if ((unshare_flags & CLONE_NEWUSER) && !unprivileged_userns_clone) {
3040+
if (!capable(CAP_SYS_ADMIN))
3041+
return -EPERM;
3042+
}
30283043

30293044
return 0;
30303045
}
@@ -3255,6 +3270,15 @@ static const struct ctl_table fork_sysctl_table[] = {
32553270
.mode = 0644,
32563271
.proc_handler = sysctl_max_threads,
32573272
},
3273+
#ifdef CONFIG_USER_NS
3274+
{
3275+
.procname = "unprivileged_userns_clone",
3276+
.data = &unprivileged_userns_clone,
3277+
.maxlen = sizeof(int),
3278+
.mode = 0644,
3279+
.proc_handler = proc_dointvec,
3280+
},
3281+
#endif
32583282
};
32593283

32603284
static int __init init_fork_sysctl(void)

0 commit comments

Comments
 (0)