Commit d1838f34 by Miquel van Smoorenburg Committed by Serge Hallyn

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: 's avatarMiquel van Smoorenburg <mikevs@xs4all.net> Signed-off-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent ee165ff8
...@@ -3115,7 +3115,7 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid) ...@@ -3115,7 +3115,7 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
} }
pos = buf; pos = buf;
if (!am_root) if (!am_root)
pos += sprintf(buf, "new%cidmap %d ", pos += sprintf(buf, "new%cidmap %d",
type == ID_TYPE_UID ? 'u' : 'g', type == ID_TYPE_UID ? 'u' : 'g',
pid); pid);
...@@ -3127,24 +3127,27 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid) ...@@ -3127,24 +3127,27 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
had_entry = 1; had_entry = 1;
left = 4096 - (pos - buf); left = 4096 - (pos - buf);
fill = snprintf(pos, left, " %lu %lu %lu", map->nsid, fill = snprintf(pos, left, "%s%lu %lu %lu%s",
map->hostid, map->range); am_root ? "" : " ",
map->nsid, map->hostid, map->range,
am_root ? "\n" : "");
if (fill <= 0 || fill >= left) if (fill <= 0 || fill >= left)
SYSERROR("snprintf failed, too many mappings"); SYSERROR("snprintf failed, too many mappings");
pos += fill; pos += fill;
} }
if (!had_entry) if (!had_entry)
continue; 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); 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); ret = system(buf);
}
if (ret) if (ret)
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment