]> git.ipfire.org Git - thirdparty/util-linux.git/commit
unshare: Don't waste an ID when -r is used with --map-auto
authorChris Webb <chris@arachsys.com>
Wed, 24 Aug 2022 11:52:55 +0000 (12:52 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 1 Sep 2022 09:30:03 +0000 (11:30 +0200)
commit07935158b78b2275bb14557a2f80da8d27747a86
tree0cbfc297b10d8d47698a0c3b3c30c6d98d220c1d
parentc62b21208058dd279b25fa2b32ebf02ad427a4f4
unshare: Don't waste an ID when -r is used with --map-auto

When --map-root-user or --map-current-user are used with --map-auto, one of
the IDs from the first range in /etc/subuid and /etc/subgid is wasted and
left unmapped:

  $ cat /etc/subuid
  1000:65536:100
  $ unshare --map-auto cat /proc/self/uid_map
           0      65536        100
  $ unshare --map-root-user --map-auto cat /proc/self/uid_map
           0       1000          1
           1      65536         99

In the second unshare, only 99 of the 100 UIDs available from /etc/subuid
are actually mapped, whereas in the first unshare, all 100 delegated UIDs
are correctly mapped.

Distinguish auto mappings from manually-specified ones so they can be
handled correctly, while still ensuring explicit --map-users/groups that
overlap with the single mapping are correctly reduced in length because
of the hole that's punched:

  $ unshare --map-auto cat /proc/self/uid_map
           0      65536        100
  $ unshare  --map-root-user --map-auto cat /proc/self/uid_map
           0       1000          1
           1      65536        100

Signed-off-by: Chris Webb <chris@arachsys.com>
sys-utils/unshare.c