Skip to content

Commit

Permalink
Set file mode during zfs_write
Browse files Browse the repository at this point in the history
Apply openzfs/zfs#11576

Direct commit from upstream openzfs. Full commit message below:

Set file mode during zfs_write

3d40b65 refactored zfs_vnops.c, which shared much code verbatim between
Linux and BSD.  After a successful write, the suid/sgid bits are reset,
and the mode to be written is stored in newmode.  On Linux, this was
propagated to both the in-memory inode and znode, which is then updated
with sa_update.

3d40b65 accidentally removed the initialization of newmode, which
happened to occur on the same line as the inode update (which has been
moved out of the function).

The uninitialized newmode can be saved to disk, leading to a crash on
stat() of that file, in addition to a merely incorrect file mode.

Reviewed-by: Ryan Moeller <ryan@ixsystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes #11474
Closes #11576

Approved by:	re (gdb)
Obtained from:	openzfs/zfs@f8ce8aed0
Sponsored by:	iXsystems, Inc.

(cherry picked from commit e9d419a)
(cherry picked from commit 618dee6)
  • Loading branch information
aerusso authored and Ryan Moeller committed Feb 9, 2021
1 parent f69cd08 commit 7100be1
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions sys/contrib/openzfs/module/zfs/zfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ zfs_write(znode_t *zp, uio_t *uio, int ioflag, cred_t *cr)
((zp->z_mode & S_ISUID) != 0 && uid == 0)) != 0) {
uint64_t newmode;
zp->z_mode &= ~(S_ISUID | S_ISGID);
newmode = zp->z_mode;
(void) sa_update(zp->z_sa_hdl, SA_ZPL_MODE(zfsvfs),
(void *)&newmode, sizeof (uint64_t), tx);
}
Expand Down

0 comments on commit 7100be1

Please sign in to comment.