Skip to content

Comments

Fix rootfs-upper tar to preserve opaque xattrs#12633

Open
danielnorberg wants to merge 2 commits intogoogle:masterfrom
danielnorberg:fix-tar-rootfs-upper-opaque-xattr
Open

Fix rootfs-upper tar to preserve opaque xattrs#12633
danielnorberg wants to merge 2 commits intogoogle:masterfrom
danielnorberg:fix-tar-rootfs-upper-opaque-xattr

Conversation

@danielnorberg
Copy link

@danielnorberg danielnorberg commented Feb 22, 2026

Summary

  • The runsc tar rootfs-upper command was not preserving extended attributes (xattrs) during serialization. This caused trusted.overlay.opaque to be lost, resulting in stale lower-layer files being resurrected when restoring from a tar snapshot.
  • Xattrs are now serialized to PAXRecords using the standard SCHILY.xattr. prefix during tar creation, and restored during tar extraction.
  • Added RawXattrs/SetRawXattrs methods to SimpleExtendedAttributes for unchecked access in the kernel serialization path.

Test plan

  • Added TestTarRootfsUpperLayerOpaqueDir regression test that deletes /usr/share (which has lower-layer files), recreates it with only a marker file, tars the upper layer, restores it, and verifies no stale files leak through.
  • Verify the regression test fails on the parent commit (without the fix) by checking out HEAD~1 and running the test.
  • Run the full container test suite to check for regressions.

🤖 Generated with Claude Code

@google-cla
Copy link

google-cla bot commented Feb 22, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

The runsc tar rootfs-upper command does not preserve extended attributes
(specifically trusted.overlay.opaque) on directories. When a directory
from the lower layer is deleted and recreated, the overlay marks it as
opaque to prevent lower layer contents from showing through. Without
preserving this xattr in the tar, restoring from the snapshot causes
stale files from the lower layer to be resurrected.

This test reproduces the issue by:
1. Starting a container with overlay2 root:memory
2. Deleting /usr/share (which has files in the lower layer)
3. Recreating /usr/share with only a marker file
4. Tarring the upper layer and restoring into a new container
5. Verifying that only the marker file is visible (no stale files)
The tar serialization of the upper layer was not preserving extended
attributes, causing trusted.overlay.opaque xattrs to be lost. When a
directory tree in the lower layer is deleted and partially recreated,
the overlay sets trusted.overlay.opaque=y on the new directory to
prevent lower layer contents from showing through. Without this xattr
in the tar, restoring from the snapshot would resurrect stale files
from the lower layer.

Fix by serializing xattrs to PAXRecords using the standard
SCHILY.xattr. prefix during tar creation, and restoring them during
tar extraction. This is done for all inode types: directories, regular
files, symlinks, FIFOs, and device files.

Two new unchecked accessor methods (RawXattrs/SetRawXattrs) are added
to SimpleExtendedAttributes for use by the serialization path, which
operates within the kernel and does not need credential checks.
@danielnorberg danielnorberg force-pushed the fix-tar-rootfs-upper-opaque-xattr branch from 8bcb467 to 4c7c190 Compare February 22, 2026 07:56
@danielnorberg danielnorberg marked this pull request as ready for review February 22, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant