coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

tests/cp/preserve-gid: `cp -p` fails to preserve group

Open drinkcat opened this issue 5 months ago • 1 comments

Looks like I didn't fix everything in #8380...

Steps (assumes users/groups 1002/1003/1004 don't exist):

mkdir t
chmod a+rwx t
touch t/b1 && sudo chown 1002:1004 t/b1
rm -f t/b
sudo chroot --skip-chdir --user=+1002:+1003 --groups=+1003,+1004 / cp -p t/b1 t/b
ls -l t
total 0
-rw-r--r-- 1 1002 1004 0 Aug  8 18:33 b
-rw-r--r-- 1 1002 1004 0 Aug  8 18:33 b1
rm -f t/b
sudo chroot --skip-chdir --user=+1002:+1003 --groups=+1003,+1004 / target/debug/cp -p t/b1 t/b
ls -l t
total 0
-rw-r--r-- 1 1002 1003 0 Aug  8 18:37 b
-rw-r--r-- 1 1002 1004 0 Aug  8 18:33 b1

drinkcat avatar Aug 08 '25 10:08 drinkcat

I think the problem is that canonicalize fails if the user doesn't have read access to the entirety of the path (which is what that chroot thing causes).

This was introduced in #6446, I can easily workaround the issue but I want to check all uses of canonicalize...

This is also broken:

mkdir t/x1 && sudo chown 1002:1004 t/x1 && sudo chmod 0707 t/x1
touch t/x1/b1 && sudo chown 1002:1004 t/x1/b1
sudo rm -rf t/x; mkdir -m 0777 t/x; sudo chroot --skip-chdir --user=+1002:+1003 --groups=+1003,+1004 / target/debug/cp --parents -p t/x1 t/x; ls -lR t

drinkcat avatar Aug 08 '25 11:08 drinkcat