[lxc-devel] lxc.id_map bug when writing directly to /proc/pid/[ug]id_map [PATCH]

Serge Hallyn serge.hallyn at ubuntu.com
Thu Feb 6 04:36:49 UTC 2014


Quoting Miquel van Smoorenburg (mikevs at xs4all.net):
> 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 <mikevs at xs4all.net>

Odd, I thought I had already pushed this patch a few weeks ago?  I'll
re-test (once I recover some vms) and push.  Thanks.
(Note, the bug sets in when there is >1 uid or gid mapping in the
am_root case)

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

(Please don't push until I get a chance to test, though I don't
expect any problems)

> --- lxc-1.0.0~beta1.orig/src/lxc/conf.c
> +++ lxc-1.0.0~beta1/src/lxc/conf.c
> @@ -3147,7 +3147,7 @@ int lxc_map_ids(struct lxc_list *idmap,
>  		}
>  		pos = buf;
>  		if (!am_root)
> -			pos += sprintf(buf, "new%cidmap %d ",
> +			pos += sprintf(buf, "new%cidmap %d",
>  				type == ID_TYPE_UID ? 'u' : 'g',
>  				pid);
>  
> @@ -3159,24 +3159,27 @@ int lxc_map_ids(struct lxc_list *idmap,
>  
>  			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;
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list