From 82552fbafc58a28daaa588e61b8494de1fb7f75a Mon Sep 17 00:00:00 2001 From: jc_gargma Date: Sat, 25 May 2019 10:54:21 -0700 Subject: Add 0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch --- ...to-disallow-unprivileged-CLONE_NEWUSER-by.patch | 102 +++++++++++++++++++++ PKGBUILD | 5 +- 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch diff --git a/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch b/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch new file mode 100644 index 0000000..e7432e3 --- /dev/null +++ b/0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch @@ -0,0 +1,102 @@ +From e71668257d1353a7bd428ec90f0871b038db813b Mon Sep 17 00:00:00 2001 +From: Serge Hallyn +Date: Fri, 31 May 2013 19:12:12 +0100 +Subject: [PATCH 1/3] add sysctl to disallow unprivileged CLONE_NEWUSER by + default + +Signed-off-by: Serge Hallyn +[bwh: Remove unneeded binary sysctl bits] +Signed-off-by: Daniel Micay +--- + kernel/fork.c | 15 +++++++++++++++ + kernel/sysctl.c | 12 ++++++++++++ + kernel/user_namespace.c | 3 +++ + 3 files changed, 30 insertions(+) + +diff --git a/kernel/fork.c b/kernel/fork.c +index b69248e6f0e0..3b1cd11dc6dc 100644 +--- a/kernel/fork.c ++++ b/kernel/fork.c +@@ -104,6 +104,11 @@ + + #define CREATE_TRACE_POINTS + #include ++#ifdef CONFIG_USER_NS ++extern int unprivileged_userns_clone; ++#else ++#define unprivileged_userns_clone 0 ++#endif + + /* + * Minimum number of threads to boot the kernel +@@ -1695,6 +1700,10 @@ static __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. +@@ -2528,6 +2537,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; +diff --git a/kernel/sysctl.c b/kernel/sysctl.c +index ba4d9e85feb8..e88b93a850df 100644 +--- a/kernel/sysctl.c ++++ b/kernel/sysctl.c +@@ -106,6 +106,9 @@ extern int core_uses_pid; + extern char core_pattern[]; + extern unsigned int core_pipe_limit; + #endif ++#ifdef CONFIG_USER_NS ++extern int unprivileged_userns_clone; ++#endif + extern int pid_max; + extern int pid_max_min, pid_max_max; + extern int percpu_pagelist_fraction; +@@ -515,6 +518,15 @@ static struct ctl_table kern_table[] = { + .proc_handler = proc_dointvec, + }, + #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 = "tainted", +diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c +index 923414a246e9..6b9dbc257e34 100644 +--- a/kernel/user_namespace.c ++++ b/kernel/user_namespace.c +@@ -26,6 +26,9 @@ + #include + #include + ++/* sysctl */ ++int unprivileged_userns_clone; ++ + static struct kmem_cache *user_ns_cachep __read_mostly; + static DEFINE_MUTEX(userns_state_mutex); + +-- +2.21.0 + diff --git a/PKGBUILD b/PKGBUILD index abce91c..9511bde 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -33,6 +33,7 @@ conflicts=('linux-libre') options=('!strip') source=( https://www.kernel.org/pub/linux/kernel/v5.x/linux-$pkgver.tar.{xz,sign} + 0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch enable_additional_cpu_optimizations-$_gcc_more_v.tar.gz::https://github.com/graysky2/kernel_gcc_patch/archive/$_gcc_more_v.tar.gz bdver2-fix-for-graysky.patch ath9k-regdom-hack.patch @@ -44,6 +45,7 @@ source=( ) sha256sums=('d79f90f5ca97befbfee4e247204b2ac4f45e7bb03d63a79184bc748cf3cf6ddb' 'SKIP' + '91fafa76bf9cb32159ac7f22191b3589278b91e65bc4505cf2fc6013b8037bf3' '226e30068ea0fecdb22f337391385701996bfbdba37cdcf0f1dbf55f1080542d' 'd35338c92d0dbf27ffedaf100bd852dd13fd9b5d49b12a10b91194a2ae654447' 'e7ebf050c22bcec0028c0b3c79fd6d3913b0370ecc6a23dfe78ce475630cf503' @@ -69,7 +71,8 @@ prepare() { # fi # Hotfixes - # msg2 "Applying hotfixes" + msg2 "Applying hotfixes" + patch -p1 -i ../0001-add-sysctl-to-disallow-unprivileged-CLONE_NEWUSER-by.patch # graysky2 gcc patch msg2 "Applying graysky2 cpu patch" -- cgit v1.2.1