+2017-11-18 Christian Brauner <christian.brauner@ubuntu.com>
+
+ * support/support_become_root.c (setup_uid_gid_mapping): Don't fail
+ when /proc/<pid>/setgroups does not exist.
+
2017-11-18 Florian Weimer <fweimer@redhat.com>
* sysdeps/unix/sysv/linux/tst-ttyname.c
#include <support/namespace.h>
+#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <stdio.h>
xwrite (fd, buf, ret);
xclose (fd);
- /* Disable setgroups before mapping groups, otherwise that would
- fail with EPERM. */
- fd = xopen ("/proc/self/setgroups", O_WRONLY, 0);
- xwrite (fd, "deny\n", strlen ("deny\n"));
- xclose (fd);
+ /* Linux 3.19 introduced the setgroups file. We need write "deny" to this
+ * file otherwise writing to gid_map will fail with EPERM. */
+ fd = open64 ("/proc/self/setgroups", O_WRONLY, 0);
+ if (fd < 0)
+ {
+ if (errno != ENOENT)
+ FAIL_EXIT1 ("open64 (\"/proc/self/setgroups\", 0x%x, 0%o): %m",
+ O_WRONLY, 0);
+ /* This kernel doesn't expose the setgroups file so simply move on. */
+ }
+ else
+ {
+ xwrite (fd, "deny\n", strlen ("deny\n"));
+ xclose (fd);
+ }
/* Now map our own GID, like we did for the user ID. */
fd = xopen ("/proc/self/gid_map", O_WRONLY, 0);