Since Linux 3.19-rc1, it is necessary to disable setgroups permissions
before writing to gid_map. Silently ignore if 'setgroups' can't be
opened or written to.
Signed-off-by: Daniel Mack <daniel@zonque.org>
const char *map_uid,
const char *map_gid)
{
- int ret;
+ int fd, ret;
char file_id[128] = {'\0'};
snprintf(file_id, sizeof(file_id), "/proc/%ld/uid_map",
if (ret < 0)
return ret;
+ snprintf(file_id, sizeof(file_id), "/proc/%ld/setgroups",
+ (long) pid);
+
+ fd = open(file_id, O_WRONLY);
+ if (fd >= 0) {
+ write(fd, "deny\n", 5);
+ close(fd);
+ }
+
snprintf(file_id, sizeof(file_id), "/proc/%ld/gid_map",
(long) pid);