Skip to content

fix xattrs on dangling symlinks and pin Linux xattr destinations - #125

Draft
crazy-max wants to merge 2 commits into
moby:mainfrom
crazy-max:fix-dangling-symlink-xattrs
Draft

crazy-max wants to merge 2 commits into
moby:mainfrom
crazy-max:fix-dangling-symlink-xattrs

Conversation

@crazy-max

@crazy-max crazy-max commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

This applies extended attributes to the archive entry itself, so labeled dangling symlinks such as bin -> usr/bin can be extracted before their targets exist.

The Linux implementation adapts the pinned-parent approach from moby/buildkit#7034, opening the parent through os.Root before applying xattrs without following the final component. This avoids resolving the parent pathname again at the syscall boundary. When procfs is unavailable, restoration uses an isolated filesystem context, including for direct callers without prepared chroot options. This requires permission to call unshare(CLONE_FS); extraction returns an error if that operation is blocked. Existing xattr error handling is preserved, and diagnostics include the logical archive entry name.

Resolve only the parent path before applying PAX extended attributes, preserving lsetxattr's no-follow behavior for the final archive entry.

Add deterministic coverage for the xattr syscall path and retain the SELinux integration test.

Fixes moby#109
Related to moby/moby#53616

Signed-off-by: thangnc <chithang.nydo@gmail.com>
(cherry picked from commit e0a7b3a)
@crazy-max crazy-max changed the title Fix dangling symlink xattrs fix xattrs on dangling symlinks and pin Linux xattr destinations Oct 7, 2026
@codecov-commenter

codecov-commenter commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.55102% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.66%. Comparing base (953c7df) to head (6c0c79c).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
xattr_supported_unix.go 0.00% 5 Missing ⚠️
archive.go 90.90% 2 Missing ⚠️
xattr_supported_linux.go 90.00% 2 Missing ⚠️
xattr_unsupported.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #125      +/-   ##
==========================================
+ Coverage   65.48%   74.66%   +9.18%     
==========================================
  Files          46       48       +2     
  Lines        2393     2396       +3     
==========================================
+ Hits         1567     1789     +222     
  Misses        605      605              
+ Partials      221        2     -219     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@crazy-max
crazy-max requested review from thaJeztah and vvoland October 7, 2026 13:31
@crazy-max
crazy-max marked this pull request as ready for review October 7, 2026 13:31
@crazy-max
crazy-max marked this pull request as draft October 7, 2026 13:44
Pin the parent directory through os.Root before applying xattrs so that
Linux extraction preserves no-follow semantics without resolving the
parent pathname again.

Apply xattrs in an isolated filesystem context when procfs is unavailable,
including direct callers without prepared chroot options. Restoring xattrs
in that case requires permission to call unshare(CLONE_FS); retain an
explicit error when the operation is blocked.

Keep the existing xattr error policy, include logical entry names in
diagnostics, and cover dangling symlinks, replaced parents, root renames,
symlinked parents, and extraction without procfs.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
@crazy-max
crazy-max force-pushed the fix-dangling-symlink-xattrs branch from d607fbf to 6c0c79c Compare October 7, 2026 14:33
@thaJeztah

Copy link
Copy Markdown
Member

@crazy-max still draft? Was something wrong with the patch?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Security-sensitive path resolution and per-thread filesystem isolation warrant final human validation.

0 open findings

What changed in this PR

Fixes xattr restoration for dangling symlinks while preserving extraction-root confinement.

Changes:

  • Preserves final-component no-follow semantics for xattrs.
  • Pins Linux parent directories, with an isolated-filesystem fallback when procfs is unavailable.
  • Adds regression, confinement, and chroot coverage.
File Description
archive.go Centralizes xattr application and improves diagnostics.
xattr_supported_linux.go Implements pinned-parent Linux restoration.
xattr_supported_unix.go Preserves final components on supported Unix systems.
xattr_unsupported.go Adds the no-op unsupported-platform abstraction.
archive_linux_test.go Tests dangling symlinks and path confinement.
archive_linux_chrooted_test.go Tests restoration without procfs.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants