Util-Linux package development
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: Daniel Gerber <dg@atufi.org>
Cc: dottedmag@dottedmag.net, id@mbekkema.name, jpeach@apache.org,
	kzak@redhat.com, util-linux@vger.kernel.org
Subject: Re: [PATCH v2 0/6] unshare: Add support for mapping ranges of user/group IDs
Date: Fri, 14 Jan 2022 09:42:32 -0500	[thread overview]
Message-ID: <73850170-db69-7d64-ca9e-6e41dfa4eab9@gmail.com> (raw)
In-Reply-To: <874k664nlq.fsf@atufi.org>

On 1/14/22 5:29 AM, Daniel Gerber wrote:
> Hi,
> 
> Thanks for this feature. I've been trying it out... (This is with lib-musl-x86_64.)
> 
> Automatic mapping works:
> 
> $ unshare --map-users=auto cat /proc/self/uid_map
>           0     100000      65536
> 
> But parsing id ranges does not:
> 
> $ unshare --map-users=100000,0,65536 cat /proc/self/uid_map
> unshare: could not parse ID: '100000,0,65536'
> 
> Fix:
> ---
> diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c
> index 443358952..52bd9702a 100644
> --- a/sys-utils/unshare.c
> +++ b/sys-utils/unshare.c
> @@ -388,7 +388,7 @@ static int uint_to_id(const char *name, size_t sz)
>   	char buf[UID_BUFSIZ];
> 
>   	mem2strcpy(buf, name, sz, sizeof(buf));
> -	return strtoul_or_err(name, _("could not parse ID"));
> +	return strtoul_or_err(buf, _("could not parse ID"));
>   }
> 
>   /**
> ---
> Then, the value passed to newuidmap is still incorrect:
> 
> $ unshare --map-users=100000,0,65536 cat /proc/self/uid_map
> newuidmap: uid range [0-655360) -> [100000-755360) not allowed
> 
> $ unshare --map-users=100000,0,0065536 cat /proc/self/uid_map
>           0     100000      65536
> 
> The count value gets zero-padded to the right at some place I've not pinned down.

It's stack garbage. Try

diff --git i/sys-utils/unshare.c w/sys-utils/unshare.c
index 3cdd90329..5ac7af3de 100644
--- i/sys-utils/unshare.c
+++ w/sys-utils/unshare.c
@@ -385,10 +385,10 @@ struct map_range {
   */
  static int uint_to_id(const char *name, size_t sz)
  {
-       char buf[UID_BUFSIZ];
+       char buf[UID_BUFSIZ] = {0};
  
-       mem2strcpy(buf, name, sz, sizeof(buf));
-       return strtoul_or_err(name, _("could not parse ID"));
+       memcpy(buf, name, min(sz, sizeof(buf) - 1));
+       return strtoul_or_err(buf, _("could not parse ID"));
  }
  
  /**
--

(actually, I have no idea what mem2strcpy is for if it doesn't put the nul-terminator at the end of sz)

> Also, I would suggest adopting the same argument order as in /proc/<pid>/uid_map and newuidmap -- inner,outer,count.

I think this is a rather silly order. Since this is a mapping, the "natural" order is

outer -> inner

and only from the new namespace's PoV is it

inner -> outer

It certainly helped me remember things once I reversed the order...

> This doc string has it reversed:

As noted above, this is intended.

> ---
> /**
>   * struct map_range - A range of IDs to map
>   * @outer: First ID inside the namespace
>   * @inner: First ID outside the namespace
> ---
> 
> And this one has inconsistent terminology:
> ---
>   * get_map_range() - Parse a mapping range from a string
>   * @s: A string of the format upper,lower,count
>   *
>   * Parse a string of the form upper,lower,count into a new mapping range.
> ---

And here you can see that I've been reading too much of shadow's man pages :)

--Sean

  reply	other threads:[~2022-01-14 14:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-24 18:26 [PATCH v2 0/6] unshare: Add support for mapping ranges of user/group IDs Sean Anderson
2021-11-24 18:26 ` [PATCH v2 1/6] include/c: Add abs_diff macro Sean Anderson
2021-11-24 18:26 ` [PATCH v2 2/6] unshare: Add waitchild helper Sean Anderson
2021-11-24 18:26 ` [PATCH v2 3/6] unshare: Add some helpers for forking and synchronizing Sean Anderson
2021-11-24 18:26 ` [PATCH v2 4/6] unshare: Add options to map blocks of user/group IDs Sean Anderson
2021-11-24 18:26 ` [PATCH v2 5/6] unshare: Add option to automatically create user and group maps Sean Anderson
2021-11-24 18:26 ` [PATCH v2 6/6] unshare: Document --map-{groups,users,auto} Sean Anderson
2021-12-01 15:16 ` [PATCH v2 0/6] unshare: Add support for mapping ranges of user/group IDs Karel Zak
2022-01-14 10:29 ` Daniel Gerber
2022-01-14 14:42   ` Sean Anderson [this message]
2022-01-14 17:15     ` Daniel Gerber
2022-01-15  0:53       ` Sean Anderson
2022-01-18 11:50   ` Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73850170-db69-7d64-ca9e-6e41dfa4eab9@gmail.com \
    --to=seanga2@gmail.com \
    --cc=dg@atufi.org \
    --cc=dottedmag@dottedmag.net \
    --cc=id@mbekkema.name \
    --cc=jpeach@apache.org \
    --cc=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox