]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: error out on too many mappings
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 16 Oct 2017 10:50:49 +0000 (12:50 +0200)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 17 Oct 2017 05:47:04 +0000 (01:47 -0400)
The kernel only allows 4k writes to most files in /proc including {g,u}id_map
so let's not try to write partial mappings. (This will obviously become a lot
more relevant when my patch to extend the idmap limit in the kernel is merged.)

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index 56d5cc080a1275c18380dc887cc1dcab8de6394d..91816bebb3a2ae7f86a3da029eb0a07e9df408b1 100644 (file)
@@ -2621,9 +2621,6 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
                        pos += sprintf(mapbuf, "new%cidmap %d", u_or_g, pid);
 
                lxc_list_for_each(iterator, idmap) {
-                       /* The kernel only takes <= 4k for writes to
-                        * /proc/<nr>/[ug]id_map
-                        */
                        map = iterator->elem;
                        if (map->idtype != type)
                                continue;
@@ -2635,8 +2632,13 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
                                        use_shadow ? " " : "", map->nsid,
                                        map->hostid, map->range,
                                        use_shadow ? "" : "\n");
-                       if (fill <= 0 || fill >= left)
-                               SYSERROR("Too many {g,u}id mappings defined.");
+                       if (fill <= 0 || fill >= left) {
+                               /* The kernel only takes <= 4k for writes to
+                                * /proc/<pid>/{g,u}id_map
+                                */
+                               SYSERROR("Too many %cid mappings defined", u_or_g);
+                               return -1;
+                       }
 
                        pos += fill;
                }