From: Miquel van Smoorenburg Date: Wed, 5 Feb 2014 22:38:11 +0000 (+0100) Subject: lxc.id_map bug when writing directly to /proc/pid/[ug]id_map [PATCH] X-Git-Tag: lxc-1.0.0.beta4~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1838f34596635ca0684618a029cd691d8e3437d;p=thirdparty%2Flxc.git lxc.id_map bug when writing directly to /proc/pid/[ug]id_map [PATCH] lxc.id_map bug when writing directly to /proc/pid/[ug]id_map There's some code in src/lxc/conf.c that sets up the UID/GID mapping. It can use the external newuidmap/newgidmap tools, or it can write to /proc/pid/[ug]id_map directly. The latter case is broken: lines are written without a newline (\n) at the end. This patch fixes that. Note that I did not check if the newuidmap/newgidmap case still works. It should, but I wasn't able to test it. Signed-off-by: Miquel van Smoorenburg Signed-off-by: Serge Hallyn --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index fed532737..3e16cc822 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3115,7 +3115,7 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid) } pos = buf; if (!am_root) - pos += sprintf(buf, "new%cidmap %d ", + pos += sprintf(buf, "new%cidmap %d", type == ID_TYPE_UID ? 'u' : 'g', pid); @@ -3127,24 +3127,27 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid) had_entry = 1; left = 4096 - (pos - buf); - fill = snprintf(pos, left, " %lu %lu %lu", map->nsid, - map->hostid, map->range); + fill = snprintf(pos, left, "%s%lu %lu %lu%s", + am_root ? "" : " ", + map->nsid, map->hostid, map->range, + am_root ? "\n" : ""); if (fill <= 0 || fill >= left) SYSERROR("snprintf failed, too many mappings"); pos += fill; } if (!had_entry) continue; - left = 4096 - (pos - buf); - fill = snprintf(pos, left, "\n"); - if (fill <= 0 || fill >= left) - SYSERROR("snprintf failed, too many mappings"); - pos += fill; - if (am_root) + if (am_root) { ret = write_id_mapping(type, pid, buf, pos-buf); - else + } else { + left = 4096 - (pos - buf); + fill = snprintf(pos, left, "\n"); + if (fill <= 0 || fill >= left) + SYSERROR("snprintf failed, too many mappings"); + pos += fill; ret = system(buf); + } if (ret) break;