Skip to content

user: fix ToHost treating a non-root uid equal to the remapped-root base as the remapped root - #242

Open
okhowang wants to merge 1 commit into
moby:mainfrom
okhowang:fix/identity-mapping-tohost-low-base-remap
Open

user: fix ToHost treating a non-root uid equal to the remapped-root base as the remapped root#242
okhowang wants to merge 1 commit into
moby:mainfrom
okhowang:fix/identity-mapping-tohost-low-base-remap

Conversation

@okhowang

@okhowang okhowang commented Aug 4, 2026

Copy link
Copy Markdown

fixes #241

ToHost translated container ids to host ids, but special-cased the
container root by skipping the id-map lookup whenever the container uid
matched the host remapped-root base (RootPair). That comparison was
wrong: the input is a container-namespace id, so it must never be
compared against a host value.

When the subuid/subgid base is below 65536 (e.g. 'rootless:1000:65536',
used to align dind-rootless container uids), a non-root container uid
that equals the base (e.g. 1000) was incorrectly left unmapped and
therefore appeared as root inside the container.

Drop the special case entirely and always translate every id through
toHost. toHost(0) already resolves to the host remapped-root base (which
is exactly what RootPair returns), so the container root is handled
correctly without any guard. An empty (nil) mapping is treated as
identity.

Add a regression test covering standard, low-base, and empty mappings.

@okhowang okhowang changed the title user: fix ToHost treating a non-root uid equal to the remapped-root b… user: fix ToHost treating a non-root uid equal to the remapped-root base as the remapped root Aug 4, 2026
@okhowang
okhowang force-pushed the fix/identity-mapping-tohost-low-base-remap branch 2 times, most recently from 41cf740 to 89c80ea Compare August 4, 2026 07:54
…se unmapped

ToHost translated container ids to host ids, but special-cased the
container root by skipping the id-map lookup whenever the container uid
matched the host remapped-root base (RootPair). That comparison was
wrong: the input is a container-namespace id, so it must never be
compared against a host value.

When the subuid/subgid base is below 65536 (e.g. 'rootless:1000:65536',
used to align dind-rootless container uids), a non-root container uid
that equals the base (e.g. 1000) was incorrectly left unmapped and
therefore appeared as root inside the container.

Drop the special case entirely and always translate every id through
toHost. toHost(0) already resolves to the host remapped-root base (which
is exactly what RootPair returns), so the container root is handled
correctly without any guard. An empty (nil) mapping is treated as
identity.

Add a regression test covering standard, low-base, and empty mappings.

Signed-off-by: okhowang(王沛文) <okhowang@tencent.com>
@okhowang
okhowang force-pushed the fix/identity-mapping-tohost-low-base-remap branch from 89c80ea to 5d658c5 Compare August 4, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[userns-remap] Bug: ToHost incorrectly maps non-root container UID to root when it collides with RootPair

1 participant