Skip to content

cp: pass the directory to tar via -C instead of the working directory - #5238

Merged
AkihiroSuda merged 1 commit into
containerd:mainfrom
AkihiroSuda:fix-5237
Oct 1, 2026
Merged

AkihiroSuda merged 1 commit into
containerd:mainfrom
AkihiroSuda:fix-5237

Conversation

@AkihiroSuda

Copy link
Copy Markdown
Member

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 cp part)

Assisted-by: Claude Opus 5.5 (1M context) noreply@anthropic.com

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
AkihiroSuda marked this pull request as ready for review September 30, 2026 22:13
@AkihiroSuda
AkihiroSuda requested a review from a team September 30, 2026 22:13

@ChengyuZhu6 ChengyuZhu6 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AkihiroSuda
AkihiroSuda merged commit c90038a into containerd:main Oct 1, 2026
114 of 128 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.

almalinux-8 CI: TestComposeCopy, TestCopyFromContainer, etc. failing

2 participants