mv: fail closed when recreating a cross-device directory destination - #13627
Open
sylvestre wants to merge 1 commit into
Open
mv: fail closed when recreating a cross-device directory destination#13627sylvestre wants to merge 1 commit into
sylvestre wants to merge 1 commit into
Conversation
|
GNU testsuite comparison: |
The EXDEV directory fallback removes the destination, then recreates it with create_dir_all. create_dir_all treats an existing symlink-to-directory as success, so anything planted at the path in the gap redirects the entire moved tree through the link, outside the destination. Measured with a tight symlink() loop (which only succeeds while the path is absent, i.e. exactly in that gap), 30 rounds of a cross-device `mv -T srcdir dest`: uutils before 30/30 rounds wrote the source files inside the off-tree victim uutils after 0/30 GNU 9.10 0/30 Use create_dir instead, at the top-level destination and for each subdirectory, so a path that reappeared is refused with EEXIST rather than followed. Normal cross-device moves are unaffected: dest-absent, into-existing-dir, and -T onto an existing empty dir all still behave as before and match GNU.
sylvestre
force-pushed
the
mv-cross-device-dir-fail-closed
branch
from
July 29, 2026 08:49
c801766 to
42bc8b2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The EXDEV directory fallback removes the destination, then recreates it with create_dir_all. create_dir_all treats an existing symlink-to-directory as success, so anything planted at the path in the gap redirects the entire moved tree through the link, outside the destination.