summaryrefslogtreecommitdiffstats
path: root/sys-utils/unshare.c
diff options
context:
space:
mode:
authorEric W. Biederman2014-12-18 00:06:03 +0100
committerKarel Zak2015-01-09 10:32:33 +0100
commit0bf159413bdb9e324864a422b7aecb081e739119 (patch)
tree25ffb116d0a5e47a0861f1208e3af50677f4993b /sys-utils/unshare.c
parentMerge branch '2015wk01' of https://github.com/kerolasa/lelux-utiliteetit (diff)
downloadkernel-qcow2-util-linux-0bf159413bdb9e324864a422b7aecb081e739119.tar.gz
kernel-qcow2-util-linux-0bf159413bdb9e324864a422b7aecb081e739119.tar.xz
kernel-qcow2-util-linux-0bf159413bdb9e324864a422b7aecb081e739119.zip
unshare: Fix --map-root-user to work on new kernels
In rare cases droping groups with setgroups(0, NULL) is an operation that can grant a user additional privileges. User namespaces were allwoing that operation to unprivileged users and that had to be fixed. Update unshare --map-root-user to disable the setgroups operation before setting the gid_map. This is needed as after the security fix gid_map is restricted to privileged users unless setgroups has been disabled. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Diffstat (limited to 'sys-utils/unshare.c')
-rw-r--r--sys-utils/unshare.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c
index fccdba2f6..9fdce931f 100644
--- a/sys-utils/unshare.c
+++ b/sys-utils/unshare.c
@@ -39,6 +39,24 @@
#include "pathnames.h"
#include "all-io.h"
+static void disable_setgroups(void)
+{
+ const char *file = _PATH_PROC_SETGROUPS;
+ const char *deny = "deny";
+ int fd;
+
+ fd = open(file, O_WRONLY);
+ if (fd < 0) {
+ if (errno == ENOENT)
+ return;
+ err(EXIT_FAILURE, _("cannot open %s"), file);
+ }
+
+ if (write_all(fd, deny, strlen(deny)))
+ err(EXIT_FAILURE, _("write failed %s"), file);
+ close(fd);
+}
+
static void map_id(const char *file, uint32_t from, uint32_t to)
{
char *buf;
@@ -181,6 +199,7 @@ int main(int argc, char *argv[])
}
if (maproot) {
+ disable_setgroups();
map_id(_PATH_PROC_UIDMAP, 0, real_euid);
map_id(_PATH_PROC_GIDMAP, 0, real_egid);
}