UBUNTU: SAUCE: add a sysctl to disable unprivileged user namespace unsharing

It is turned on by default, but can be turned off if admins prefer or,
more importantly, if a security vulnerability is found.

The intent is to use this as mitigation so long as Ubuntu is on the
cutting edge of enablement for things like unprivileged filesystem
mounting.

(This patch is tweaked from the one currently still in Debian sid, which
in turn came from the patch we had in saucy)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
[bwh: Remove unneeded binary sysctl bits]
[ saf: move extern unprivileged_userns_clone declaration to
  include/linux/user_namespace.h to conform with 2374c09b1c
  "sysctl: remove all extern declaration from sysctl.c" ]
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
[ arighi: adjust context for v6.7 ]
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
This commit is contained in:
Serge Hallyn
2016-01-05 20:12:21 +00:00
committed by Paolo Pisati
parent 485c67c209
commit 7170d7853f
4 changed files with 33 additions and 0 deletions
+2
View File
@@ -187,6 +187,8 @@ extern bool in_userns(const struct user_namespace *ancestor,
const struct user_namespace *child);
extern bool current_in_userns(const struct user_namespace *target_ns);
struct ns_common *ns_get_owner(struct ns_common *ns);
extern int unprivileged_userns_clone;
#else
static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
+15
View File
@@ -112,6 +112,11 @@
#define CREATE_TRACE_POINTS
#include <trace/events/task.h>
#ifdef CONFIG_USER_NS
extern int unprivileged_userns_clone;
#else
#define unprivileged_userns_clone 0
#endif
/*
* Minimum number of threads to boot the kernel
@@ -2260,6 +2265,10 @@ __latent_entropy struct task_struct *copy_process(
if ((clone_flags & (CLONE_NEWUSER|CLONE_FS)) == (CLONE_NEWUSER|CLONE_FS))
return ERR_PTR(-EINVAL);
if ((clone_flags & CLONE_NEWUSER) && !unprivileged_userns_clone)
if (!capable(CAP_SYS_ADMIN))
return ERR_PTR(-EPERM);
/*
* Thread groups must share signals as well, and detached threads
* can only be started up within the thread group.
@@ -3406,6 +3415,12 @@ int ksys_unshare(unsigned long unshare_flags)
if (unshare_flags & CLONE_NEWNS)
unshare_flags |= CLONE_FS;
if ((unshare_flags & CLONE_NEWUSER) && !unprivileged_userns_clone) {
err = -EPERM;
if (!capable(CAP_SYS_ADMIN))
goto bad_unshare_out;
}
err = check_unshare_flags(unshare_flags);
if (err)
goto bad_unshare_out;
+10
View File
@@ -63,6 +63,7 @@
#include <linux/mount.h>
#include <linux/userfaultfd_k.h>
#include <linux/pid.h>
#include <linux/user_namespace.h>
#include "../lib/kstrtox.h"
@@ -1766,6 +1767,15 @@ static struct ctl_table kern_table[] = {
.proc_handler = sysrq_sysctl_handler,
},
#endif
#ifdef CONFIG_USER_NS
{
.procname = "unprivileged_userns_clone",
.data = &unprivileged_userns_clone,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = proc_dointvec,
},
#endif
#ifdef CONFIG_PROC_SYSCTL
{
.procname = "cad_pid",
+6
View File
@@ -22,6 +22,12 @@
#include <linux/bsearch.h>
#include <linux/sort.h>
/*
* sysctl determining whether unprivileged users may unshare a new
* userns. Allowed by default
*/
int unprivileged_userns_clone = 1;
static struct kmem_cache *user_ns_cachep __ro_after_init;
static DEFINE_MUTEX(userns_state_mutex);