Skip to content

llb: parse chown IDs across the whole uid_t range - #7346

Merged
tonistiigi merged 1 commit into
moby:masterfrom
ump45nose:fix-llb-chown-uid-range
Nov 4, 2026
Merged

tonistiigi merged 1 commit into
moby:masterfrom
ump45nose:fix-llb-chown-uid-range

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

What this PR does / why we need it

llb.WithUser() splits a user:group string and parses each part with
parseUID(), which used strconv.ParseInt(str, 10, 32). uid_t/gid_t span
0..2^32-1, but ParseInt rejects everything from 2^31 up, so a perfectly
valid numeric ID fell into the name branch and was sent to the daemon as a
UserOpt_ByName. readUser() treats "not found in /etc/passwd" as "leave it
alone", so COPY --chown=2147483648 file.txt /a succeeded and silently left
the file owned by root.

The daemon side already parses the same syntax with
strconv.ParseUint(str, 10, 32) (parseUID in executor/oci/user.go), so the
client was the odd one out; this aligns the two.

One side effect: a sign prefix is no longer accepted as an ID. Previously
WithUser("-1") parsed as -1 and marshal() narrowed it to
uint32(-1), i.e. 4294967295. Such a value now stays a name lookup, like any
other non-numeric string.

Which issue(s) this PR fixes / relates to

Refs #7292 — this covers only the client-side numeric ID parsing. The separate
question of readUser() silently ignoring a name that cannot be resolved is
not addressed here.

Testing

  • go test -p 1 -count=1 ./client/llb/... -> ok (llb, llbbuild, llbtest).
  • Two new tests in client/llb/fileop_test.go:
    TestFileOwnerWithUIDAndGIDAboveInt32 and TestFileOwnerWithNegativeUID.
    Both fail on the pre-change tree (the *pb.UserOpt_ByID assertion panics
    because the value arrives as UserOpt_ByName) and pass with the fix.
  • go test -p 1 -count=1 ./frontend/dockerfile/... -> dockerfile2llb,
    instructions, parser, shell, dfgitutil, version all ok. The
    frontend/dockerfile TestIntegration suite fails with "failed to lookup
    registry binary" both before and after this change on this host (it needs a
    container worker/registry), so it was not exercised here.
  • gofmt -l client/llb/ and go vet ./client/llb/ clean.

Breaking change?

No. Values that already parsed keep their meaning; values that previously
produced a silent root ownership now produce the requested ID.

Prepared with AI assistance; the diff and the test results above were reviewed and run by me.

WithUser() split a "user:group" string with parseUID(), which used
strconv.ParseInt(.., 10, 32). Any value in 2^31..2^32-1 is a valid uid_t
or gid_t, but ParseInt rejects it, so the numeric ID fell into the name
branch and the daemon tried to resolve "2147483648" in /etc/passwd. When
that lookup found nothing the copy silently stayed owned by root, so
COPY --chown=2147483648 produced no error and no requested ownership.

Parse the same way the daemon side already does in executor/oci: as an
unsigned 32-bit value. A sign prefix is no longer accepted as an ID,
which also removes the wrap-around that turned "-1" into 4294967295.

Refs moby#7292

Signed-off-by: ump45nose <ump45nose@users.noreply.github.com>
@tonistiigi
tonistiigi merged commit 45d200f into moby:master Nov 4, 2026
213 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants