coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

[BUG/Compatibility BUG/Security BUG] File ownership changes when a file is mv'ed by root to a different file system.

Open original-birdman opened this issue 2 weeks ago • 2 comments

If root mv's a file to a new file system (so it's a copy and delete) then the result is that the file ends up owned a root, even when it was not originally owned by root. (The mode flags do seem to be copied OK.)

To show this, create two files (not owned by root) in a directory that is not on the same file-system as /var/tmp then run this as root: ===== test.sh ===== #!/bin/sh

echo "Starting state of files" ls -l test-file? echo

echo "mv to same file-system" mv test-file1 test-mv1 gnumv test-file2 test-mv2 ls -l test-mv? echo

echo "mv to another file-system" mv test-mv1 /var/tmp/test-mv1 gnumv test-mv2 /var/tmp/test-mv2 cd /var/tmp/ ls -l test-mv? ===== =====

The result (for me - on Kubuntu 25.10) is:

root@gmllaptop:/local/users/gml4410# ./test.sh Starting state of files -r--r--r-- 1 gml4410 ukgcs 0 Dec 11 16:40 test-file1 -r--r--r-- 1 gml4410 ukgcs 0 Dec 11 16:40 test-file2

mv to same file-system -r--r--r-- 1 gml4410 ukgcs 0 Dec 11 16:40 test-mv1 -r--r--r-- 1 gml4410 ukgcs 0 Dec 11 16:40 test-mv2

mv to another file-system -r--r--r-- 1 root root 0 Dec 11 16:40 test-mv1 -r--r--r-- 1 gml4410 ukgcs 0 Dec 11 16:40 test-mv2

The ownership of test-mv1 has been changed by the rust core-utils mv command.

original-birdman avatar Dec 11 '25 16:12 original-birdman

Just noticed that if the file is originally setuid to a non-root account, then this bug results in it ending up as setuid root.

So it's a security issue too.

original-birdman avatar Dec 11 '25 16:12 original-birdman