cp: pass the directory to tar via -C instead of the working directory - #5238
Merged
Merged
Conversation
AkihiroSuda
force-pushed
the
fix-5237
branch
from
September 30, 2026 14:19
94d090d to
48e9e58
Compare
GNU tar 1.30-13.el8_10 (AlmaLinux 8, released 2026-09-18) aborts with
"Cannot getcwd: No such file or directory" when its working directory
is under /proc/<pid>/root of a container, as the path is unreachable
from the host mount namespace (the kernel returns "(unreachable)/...",
and glibc turns it into ENOENT).
The regression comes from the combination of two upstream tar commits
as backported to RHEL/AlmaLinux 8's tar 1.30:
- 56fb4a96 ("chdir_id refactoring"), backported in 1.30-12 as part of
the CVE-2025-45582 fix, introduced grow_wd(). Upstream initializes
wd[0].abspath lazily (NULL), but the 1.30 backport keeps calling
xgetcwd() eagerly and fails fatally on error.
- 1b91f5f6 ("Draft patch for openat2 changes vs --one-top-level"),
backported in 1.30-13, adds an unconditional
`chdir_do (chdir_arg (".", ...), false)` to name_init(), so
grow_wd() (and thus getcwd) is now reached on every invocation,
not only when -C is specified.
AlmaLinux 8 went from 1.30-11 directly to 1.30-13.
Upstream tar is not affected (getcwd is lazy there), and neither commit
is in an upstream release as of v1.35.
Using `-C <dir>` keeps the tar process's working directory on the host
while tar opens the directory by itself.
As the tar process no longer chdirs into the extraction directory, an
inaccessible destination is now checked with access(2) beforehand, so
that it is still reported as ErrTargetIsReadOnly.
Fixes containerd#5237 (the `nerdctl cp` part)
Assisted-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
AkihiroSuda
force-pushed
the
fix-5237
branch
from
September 30, 2026 14:24
48e9e58 to
a29119b
Compare
AkihiroSuda
marked this pull request as ready for review
September 30, 2026 22:13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GNU tar 1.30-13.el8_10 (AlmaLinux 8, released 2026-09-18) aborts with "Cannot getcwd: No such file or directory" when its working directory is under /proc//root of a container, as the path is unreachable from the host mount namespace (the kernel returns "(unreachable)/...", and glibc turns it into ENOENT).
The regression comes from the combination of two upstream tar commits as backported to RHEL/AlmaLinux 8's tar 1.30:
56fb4a96 ("chdir_id refactoring"), backported in 1.30-12 as part of the CVE-2025-45582 fix, introduced grow_wd(). Upstream initializes wd[0].abspath lazily (NULL), but the 1.30 backport keeps calling xgetcwd() eagerly and fails fatally on error.
1b91f5f6 ("Draft patch for openat2 changes vs --one-top-level"), backported in 1.30-13, adds an unconditional
chdir_do (chdir_arg (".", ...), false)to name_init(), so grow_wd() (and thus getcwd) is now reached on every invocation, not only when -C is specified.AlmaLinux 8 went from 1.30-11 directly to 1.30-13. Upstream tar is not affected (getcwd is lazy there), and neither commit is in an upstream release as of v1.35.
Using
-C <dir>keeps the tar process's working directory on the host while tar opens the directory by itself.Fixes #5237 (the
nerdctl cppart)Assisted-by: Claude Opus 5.5 (1M context) noreply@anthropic.com