Skip to content

mv xattr preservation TOCTOU on cross-device moves #10014

Closed

Description

@sylvestre

Component

mv (cross-device fallback) and uucore::fsxattr

Description

When moving files across filesystem boundaries, mv falls back to copy-then-delete. During this fallback, extended attribute preservation uses path-based operations (xattr::list, xattr::get, xattr::set) that repeatedly re-resolve source and destination paths with each syscall. This means the xattrs copied are not an atomic snapshot, and concurrent path manipulation (renames, replacements) can redirect individual syscalls to different inodes mid-operation.

The implementation is not inode-stable. Each xattr operation walks the path again instead of operating on a pinned file descriptor. For regular files, copy_xattrs(source, dest) iterates attributes and performs separate path lookups per get/set. For directories, retrieve_xattrs and apply_xattrs similarly resolve paths multiple times.

Test / Reproduction Steps

# Observe non-atomic snapshot behavior
touch /tmp/src
setfattr -n user.test -v original /tmp/src
while true; do setfattr -n user.test -v modified /tmp/src 2>/dev/null; done &
mv /tmp/src /mnt/otherfs/dst  # Cross-device move
getfattr -n user.test /mnt/otherfs/dst

Impact

This is primarily a correctness issue, but becomes security-relevant when privileged processes move files carrying security xattrs (SELinux labels, capabilities). Content and metadata can be observed or manipulated at different times during the operation.

Activity

  1. added 8 commits that reference this issue on Mar 16, 2026
    41cd49f
  2. 15 remaining items

  3. sylvestre commented on May 24, 2026

    @sylvestre
    SponsorContributorAuthor

    Fixed by #12170 (commit 54877ac "uucore/mv: fd-based xattr copy for cross-device moves").

  4. added 5 commits that reference this issue on Aug 13, 2026
    3a611c5
    dc76973
    9744580
    5b4f730
    6372fd3
  5. added a commit that references this issue on Sep 28, 2026
    9a3c0d8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions