Skip to content

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

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

crazy-max wants to merge 5 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.

@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 60.93750% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.21%. Comparing base (953c7df) to head (d2b7dda).
⚠️ Report is 22 commits behind head on main.

Files with missing lines Patch % Lines
internal/unshare/unshare_linux.go 0.00% 20 Missing ⚠️
archive.go 91.30% 2 Missing ⚠️
xattr_unsupported.go 0.00% 2 Missing ⚠️
xattr_supported_unix.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #125      +/-   ##
==========================================
+ Coverage   65.48%   74.21%   +8.73%     
==========================================
  Files          46       48       +2     
  Lines        2393     2420      +27     
==========================================
+ Hits         1567     1796     +229     
- Misses        605      622      +17     
+ 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
@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.

ChiThang-50Cent and others added 2 commits November 4, 2026 12:19
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)
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 6c0c79c to ef24488 Compare November 4, 2026 11:22
Reuse the locked thread's filesystem context when extraction already runs
inside unshare.Go with CLONE_FS, instead of creating and retiring a thread
for every entry with xattrs. Restore cwd after each callback while retaining
pinned-parent addressing and the isolated-thread fallback for other callers.

This reduces a local 20,000-file chroot extraction benchmark from about
4.3 seconds to 1.7 seconds.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Wrap errors returned by withXattrPath with the archive entry name so that
path resolution and thread-isolation failures identify the affected entry.
Preserve error unwrapping and the existing policy for ignored xattr errors.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Run the dangling-symlink xattr test on Linux, macOS, FreeBSD, and NetBSD.
Compare against the native syscall and verify the restored value when
the platform supports writing xattrs on symlinks.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
@crazy-max
crazy-max marked this pull request as ready for review November 4, 2026 12:04
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