mv: moving a special file across filesystems deletes the destination on failure

Open
#13,145 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust

Research direction

Start by tracing mv's cross-filesystem fallback for special files and reproduce the failure with a socket on one filesystem and a destination on another. Verify that a failed move preserves the existing destination, and add or run coverage for the reported repro and error behavior if the relevant test location is identified.

Written by the indexing model from the issue text.

Description

U - mv

Reported by @HackingRepo via security advisory GHSA-xw28-j282-p74c. We don't consider this a security issue, so we're tracking it as a regular bug.

Description
When mv falls back to the copy path (cross-filesystem / EXDEV) for a special file (e.g. a socket) and the operation fails, the existing destination is removed entirely, causing data loss.

Repro (socket on tmpfs, dest on a different filesystem to force the copy path)

$ echo important > a
$ mv /path/on/tmpfs/sock a
mv: Permission denied (os error 13)
$ cat a
cat: a: No such file or directory      # 'a' was deleted

GNU leaves a in place (recreated as a socket) rather than deleting it.

Expected: on a failed cross-fs move of a special file, the existing destination must not be destroyed.
Actual: destination is removed, original contents lost.

(Also: the error carries (os error 13) and lacks the 'src' to 'dest' context GNU prints.)

Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from uutils/coreutils

All issues in uutils/coreutils

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.