All of lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <djwong@kernel.org>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 3/4] xfs: validate extsz hints against rt extent size when rtinherit is set
Date: Fri, 14 May 2021 14:51:50 -0400	[thread overview]
Message-ID: <YJ7GxqPURmuPiIbE@bfoster> (raw)
In-Reply-To: <20210514182253.GN9675@magnolia>

On Fri, May 14, 2021 at 11:22:53AM -0700, Darrick J. Wong wrote:
> On Fri, May 14, 2021 at 08:38:35AM -0400, Brian Foster wrote:
> > On Wed, May 12, 2021 at 06:01:58PM -0700, Darrick J. Wong wrote:
> > > From: Darrick J. Wong <djwong@kernel.org>
> > > 
> > > The RTINHERIT bit can be set on a directory so that newly created
> > > regular files will have the REALTIME bit set to store their data on the
> > > realtime volume.  If an extent size hint (and EXTSZINHERIT) are set on
> > > the directory, the hint will also be copied into the new file.
> > > 
> > > As pointed out in previous patches, for realtime files we require the
> > > extent size hint be an integer multiple of the realtime extent, but we
> > > don't perform the same validation on a directory with both RTINHERIT and
> > > EXTSZINHERIT set, even though the only use-case of that combination is
> > > to propagate extent size hints into new realtime files.  This leads to
> > > inode corruption errors when the bad values are propagated.
> > > 
> > > Strengthen the validation routine to avoid this situation and fix the
> > > open-coded unit conversion while we're at it.  Note that this is
> > > technically a breaking change to the ondisk format, but the risk should
> > > be minimal because (a) most vendors disable realtime, (b) letting
> > > unaligned hints propagate to new files would immediately crash the
> > > filesystem, and (c) xfs_repair flags such filesystems as corrupt, so
> > > anyone with such a configuration is broken already anyway.
> > > 
> > > Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> > > ---
> > 
> > Ok, so this looks more like a proper fix, but does this turn an existing
> > directory with (rtinherit && extszinherit) and a badly aligned extsz
> > hint into a read validation error?
> 
> Hmm, you're right.  This fix needs to be more targeted in its nature.
> For non-rt filesystems, the rtinherit bit being set on a directory is
> benign because we won't set the realtime bit on new files, so there's no
> need to introduce a new verifier error that will fail existing
> filesystems.
> 
> We /do/ need to trap the misconfiguration for filesystems with an rt
> volume because those filesystems will fail if the propagation happens.
> 
> I think the solution here is to change the verifier check here to
> prevent the spread of bad extent size hints:
> 
> 	if (rt_flag || (xfs_sb_version_hasrealtime(&mp->m_sb) &&
> 			rtinherit_flag && inherit_flag))
> 		blocksize_bytes = XFS_FSB_TO_B(mp, mp->m_sb.sb_rextsize);
> 	else
> 		blocksize_bytes = mp->m_sb.sb_blocksize;
> 
> ...and add a check to xfs_ioctl_setattr_check_extsize to prevent
> sysadmins from misconfiguring directories in the first place.
> 

It definitely makes sense to prevent this misconfiguration going
forward, but I'm a little confused on the intended behavior for
filesystems where this is already present (and not benign). ISTM the
previous patch is intended to allow the filesystem to continue running
with the added behavior that we restrict further propagation of
preexisting misconfigured extent size hints, but would this patch
trigger a verifier failure on read of such a misconfigured directory
inode..?

Brian

> --D
> 
> > Brian
> > 
> > >  fs/xfs/libxfs/xfs_inode_buf.c |    7 ++++---
> > >  1 file changed, 4 insertions(+), 3 deletions(-)
> > > 
> > > 
> > > diff --git a/fs/xfs/libxfs/xfs_inode_buf.c b/fs/xfs/libxfs/xfs_inode_buf.c
> > > index 5c9a7440d9e4..25261dd73290 100644
> > > --- a/fs/xfs/libxfs/xfs_inode_buf.c
> > > +++ b/fs/xfs/libxfs/xfs_inode_buf.c
> > > @@ -569,19 +569,20 @@ xfs_inode_validate_extsize(
> > >  	uint16_t			mode,
> > >  	uint16_t			flags)
> > >  {
> > > -	bool				rt_flag;
> > > +	bool				rt_flag, rtinherit_flag;
> > >  	bool				hint_flag;
> > >  	bool				inherit_flag;
> > >  	uint32_t			extsize_bytes;
> > >  	uint32_t			blocksize_bytes;
> > >  
> > >  	rt_flag = (flags & XFS_DIFLAG_REALTIME);
> > > +	rtinherit_flag = (flags & XFS_DIFLAG_RTINHERIT);
> > >  	hint_flag = (flags & XFS_DIFLAG_EXTSIZE);
> > >  	inherit_flag = (flags & XFS_DIFLAG_EXTSZINHERIT);
> > >  	extsize_bytes = XFS_FSB_TO_B(mp, extsize);
> > >  
> > > -	if (rt_flag)
> > > -		blocksize_bytes = mp->m_sb.sb_rextsize << mp->m_sb.sb_blocklog;
> > > +	if (rt_flag || (rtinherit_flag && inherit_flag))
> > > +		blocksize_bytes = XFS_FSB_TO_B(mp, mp->m_sb.sb_rextsize);
> > >  	else
> > >  		blocksize_bytes = mp->m_sb.sb_blocksize;
> > >  
> > > 
> > 
> 


  reply	other threads:[~2021-05-14 18:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-13  1:01 [PATCHSET 0/4] xfs: strengthen validation of extent size hints Darrick J. Wong
2021-05-13  1:01 ` [PATCH 1/4] xfs: standardize extent size hint validation Darrick J. Wong
2021-05-14 12:38   ` Brian Foster
2021-05-13  1:01 ` [PATCH 2/4] xfs: don't propagate invalid extent size hints to new files Darrick J. Wong
2021-05-14 12:38   ` Brian Foster
2021-05-14 15:55     ` Darrick J. Wong
2021-05-13  1:01 ` [PATCH 3/4] xfs: validate extsz hints against rt extent size when rtinherit is set Darrick J. Wong
2021-05-14 12:38   ` Brian Foster
2021-05-14 18:22     ` Darrick J. Wong
2021-05-14 18:51       ` Brian Foster [this message]
2021-05-14 20:30         ` Darrick J. Wong
2021-05-13  1:02 ` [PATCH 4/4] xfs: apply rt extent alignment constraints to cow extsize hint Darrick J. Wong
2021-05-14 17:24   ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YJ7GxqPURmuPiIbE@bfoster \
    --to=bfoster@redhat.com \
    --cc=djwong@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.