]> git.proxmox.com Git - mirror_zfs.git/commit
Fix clearing set-uid and set-gid bits on a file when replying a write
authorPawel Jakub Dawidek <pawel@dawidek.net>
Thu, 3 Feb 2022 22:37:57 +0000 (14:37 -0800)
committerGitHub <noreply@github.com>
Thu, 3 Feb 2022 22:37:57 +0000 (14:37 -0800)
commit3d244b488155e04ec059e66752d7138aa75e7e48
treeea29349eea084539d30180d5638874e66e17d1f8
parent63652e154643cfe596fe077c13de0e7be34dd863
Fix clearing set-uid and set-gid bits on a file when replying a write

POSIX requires that set-uid and set-gid bits to be removed when an
unprivileged user writes to a file and ZFS does that during normal
operation.

The problem arrises when the write is stored in the ZIL and replayed.
During replay we have no access to original credentials of the process
doing the write, so zfs_write() will be performed with the root
credentials. When root is doing the write set-uid and set-gid bits
are not removed from the file.

To correct that, log a separate TX_SETATTR entry that removed those bits
on first write to such file.

Idea from: Christian Schwarz

Add test for ZIL replay of setuid/setgid clearing.

Improve various edge cases when clearing setid bits:
- The setid bits can be readded during a single write, so make sure to check
  for them on every chunk write.
- Log TX_SETATTR record at most once per transaction group (if the setid bits
  are keep coming back).
- Move zfs_log_setattr() outside of zp->z_acl_lock.

Reviewed-by: Dan McDonald <danmcd@joyent.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Co-authored-by: Christian Schwarz <me@cschwarz.com>
Signed-off-by: Pawel Jakub Dawidek <pawel@dawidek.net>
Closes #13027
module/zfs/zfs_vnops.c
tests/runfiles/common.run
tests/zfs-tests/tests/functional/suid/Makefile.am
tests/zfs-tests/tests/functional/suid/suid_write_to_file.c
tests/zfs-tests/tests/functional/suid/suid_write_to_none.ksh
tests/zfs-tests/tests/functional/suid/suid_write_to_sgid.ksh
tests/zfs-tests/tests/functional/suid/suid_write_to_suid.ksh
tests/zfs-tests/tests/functional/suid/suid_write_to_suid_sgid.ksh
tests/zfs-tests/tests/functional/suid/suid_write_zil_replay.ksh [new file with mode: 0755]