]> git.ipfire.org Git - thirdparty/shadow.git/commit
copy_tree: carefully treat permissions
authorSamanta Navarro <ferivoz@riseup.net>
Sat, 10 Sep 2022 11:58:15 +0000 (11:58 +0000)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Wed, 14 Sep 2022 08:11:32 +0000 (10:11 +0200)
commitcde221b8587193f9dc300c0799a530e846c75961
treed102ccd92503d1d7bb4d6f71aff1e6827dd45d41
parentf33e7def06537995f3a68cab528b5c65a4c0d011
copy_tree: carefully treat permissions

The setuid, setgid, and sticky bits are not copied during copy_tree.

Also start with very restrictive permissions before setting ownerships.

This prevents situations in which users in a group with less permissions
than others could win a race in opening the file before permissions are
removed again.

Proof of concept:

$ echo $HOME
/home/uwu
$ install -o uwu -g fandom -m 604 /dev/null /home/uwu/owo
$ ls -l /home/uwu/owo
-rw----r-- 1 uwu fandom 0 Sep  4 00:00 /home/uwu/owo

If /tmp is on another filesystem, then "usermod -md /tmp/uwu uwu" leads
to this temporary situation:

$ ls -l /tmp/uwu/owo
-rw----r-- 1 root root  0 Sep  4 00:00 /tmp/uwu/owo

This means that between openat and chownat_if_needed a user of group
fandom could open /tmp/uwu/owo and read the content when it is finally
written into the file.
libmisc/copydir.c