Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set file mode during zfs_write #11576

Merged
merged 1 commit into from
Feb 8, 2021
Merged

Conversation

aerusso
Copy link
Contributor

@aerusso aerusso commented Feb 7, 2021

Motivation and Context

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.

Description

This patch restores that initialization.

How Has This Been Tested?

On a VM, it addresses the reproducer in #11474.

  • We may want to generate a reproducer for the ZTS.
  • I need a sanity check on this, @mattmacy @freqlabs @behlendorf .

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Library ABI change (libzfs, libzfs_core, libnvpair, libuutil and libzfsbootenv)
  • Documentation (a change to man pages or other documentation)

Checklist:

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.

Signed-off-by: Antonio Russo <aerusso@aerusso.net>
Closes openzfs#11474
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof. Nice work finding that one.

@ghost ghost added the Status: Code Review Needed Ready for review and testing label Feb 8, 2021
@ghost
Copy link

ghost commented Feb 8, 2021

If you can come up with a test case we can incorporate in ZTS great, but I'd like to see this merged either way.

Copy link
Contributor

@behlendorf behlendorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix here looks good, thanks for running this one down. I agree it'd be nice to have a ZTS test for this, but I don't think it needs to hold up merging this since the fix is straightforward. I think the only somewhat subtle thing is that it is import that ip->i_mode also be updated but that will be handled in zfs_inode_update() a little latter in the function.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels Feb 8, 2021
@behlendorf behlendorf merged commit f8ce8ae into openzfs:master Feb 8, 2021
behlendorf pushed a commit that referenced this pull request Feb 8, 2021
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
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this pull request Feb 9, 2021
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

Obtained from:	openzfs/zfs@f8ce8aed0
MFC after:	0 days
Sponsored by:	iXsystems, Inc.
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this pull request Feb 9, 2021
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

Obtained from:	openzfs/zfs@f8ce8aed0
MFC after:	0 days
Sponsored by:	iXsystems, Inc.

(cherry picked from commit e9d419a)
uqs pushed a commit to freebsd/freebsd-ports that referenced this pull request Feb 9, 2021
See openzfs/zfs#11576 for details.

Reviewed by:	wg
Approved by:	wg (ports)
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D28554


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@564796 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this pull request Feb 9, 2021
See openzfs/zfs#11576 for details.

Reviewed by:	wg
Approved by:	wg (ports)
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D28554
uqs pushed a commit to freebsd/freebsd-ports that referenced this pull request Feb 9, 2021
sysutils/openzfs*: Bump to fix mode issue in zfs_write

See openzfs/zfs#11576 for details.

Approved by:	portmgr (blanket, security/stability)
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D28554
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this pull request Feb 9, 2021
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)
Jehops pushed a commit to Jehops/freebsd-ports-legacy that referenced this pull request Feb 9, 2021
See openzfs/zfs#11576 for details.

Reviewed by:	wg
Approved by:	wg (ports)
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D28554


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@564796 35697150-7ecd-e111-bb59-0022644237b5
@mjguzik
Copy link
Contributor

mjguzik commented Feb 9, 2021

If I read this right the problem may have resulted in files with garbage mode hitting storage. Does 'scrub' or whatever other method scan and fix them? I presume some files might have received accidentally correct but unintended mode and that may be impossible to detect, but the rest should be fixable?

dch pushed a commit to skunkwerks/ports that referenced this pull request Feb 10, 2021
See openzfs/zfs#11576 for details.

Reviewed by:	wg
Approved by:	wg (ports)
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D28554
@wizeman wizeman mentioned this pull request Feb 14, 2021
10 tasks
jsai20 pushed a commit to jsai20/zfs that referenced this pull request Mar 30, 2021
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 openzfs#11474 
Closes openzfs#11576
uqs pushed a commit to freebsd/freebsd-ports that referenced this pull request Apr 1, 2021
sysutils/openzfs*: Bump to fix mode issue in zfs_write

See openzfs/zfs#11576 for details.

Approved by:	portmgr (blanket, security/stability)
Sponsored by:	iXsystems, Inc.
Differential Revision:	https://reviews.freebsd.org/D28554
sempervictus pushed a commit to sempervictus/zfs that referenced this pull request May 31, 2021
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 openzfs#11474 
Closes openzfs#11576
brooksdavis pushed a commit to CTSRD-CHERI/cheribsd that referenced this pull request Oct 27, 2021
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

Obtained from:	openzfs/zfs@f8ce8aed0
MFC after:	0 days
Sponsored by:	iXsystems, Inc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants