[10/11] xfs: improve ondisk dquot flags checking
diff mbox series

Message ID 159488198306.3813063.16348101518917273554.stgit@magnolia
State Superseded
Headers show
Series
  • xfs: separate dquot type from flags
Related show

Commit Message

Darrick J. Wong July 16, 2020, 6:46 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Create an XFS_DQTYPE_ANY mask for ondisk dquots flags, and use that to
ensure that we never accept any garbage flags when we're loading dquots.
While we're at it, restructure the quota type flag checking to use the
proper masking.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/libxfs/xfs_dquot_buf.c |   11 ++++++++---
 fs/xfs/libxfs/xfs_format.h    |    2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

Comments

Dave Chinner July 17, 2020, 12:13 a.m. UTC | #1
On Wed, Jul 15, 2020 at 11:46:23PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Create an XFS_DQTYPE_ANY mask for ondisk dquots flags, and use that to
> ensure that we never accept any garbage flags when we're loading dquots.
> While we're at it, restructure the quota type flag checking to use the
> proper masking.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/libxfs/xfs_dquot_buf.c |   11 ++++++++---
>  fs/xfs/libxfs/xfs_format.h    |    2 ++
>  2 files changed, 10 insertions(+), 3 deletions(-)

Ok, I looked at this and questioned why it existed and why the
code didn't just use XFS_DQTYPE_REC_MASK directly. I think this
change exists because you plan on adding a new on-disk flag for
bigtime support and hence XFS_DQTYPE_ANY will grow to include the
new flag, right?

If so, can you add that to the commit message?

Code looks fine assuming I've understood this correctly...

Cheers,

Dave.
Darrick J. Wong July 17, 2020, 1:05 a.m. UTC | #2
On Fri, Jul 17, 2020 at 10:13:59AM +1000, Dave Chinner wrote:
> On Wed, Jul 15, 2020 at 11:46:23PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Create an XFS_DQTYPE_ANY mask for ondisk dquots flags, and use that to
> > ensure that we never accept any garbage flags when we're loading dquots.
> > While we're at it, restructure the quota type flag checking to use the
> > proper masking.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  fs/xfs/libxfs/xfs_dquot_buf.c |   11 ++++++++---
> >  fs/xfs/libxfs/xfs_format.h    |    2 ++
> >  2 files changed, 10 insertions(+), 3 deletions(-)
> 
> Ok, I looked at this and questioned why it existed and why the
> code didn't just use XFS_DQTYPE_REC_MASK directly. I think this
> change exists because you plan on adding a new on-disk flag for
> bigtime support and hence XFS_DQTYPE_ANY will grow to include the
> new flag, right?

Correct.

> If so, can you add that to the commit message?

Ok, will do.

--D

> Code looks fine assuming I've understood this correctly...
> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
Dave Chinner July 17, 2020, 1:11 a.m. UTC | #3
On Thu, Jul 16, 2020 at 06:05:28PM -0700, Darrick J. Wong wrote:
> On Fri, Jul 17, 2020 at 10:13:59AM +1000, Dave Chinner wrote:
> > On Wed, Jul 15, 2020 at 11:46:23PM -0700, Darrick J. Wong wrote:
> > > From: Darrick J. Wong <darrick.wong@oracle.com>
> > > 
> > > Create an XFS_DQTYPE_ANY mask for ondisk dquots flags, and use that to
> > > ensure that we never accept any garbage flags when we're loading dquots.
> > > While we're at it, restructure the quota type flag checking to use the
> > > proper masking.
> > > 
> > > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > > ---
> > >  fs/xfs/libxfs/xfs_dquot_buf.c |   11 ++++++++---
> > >  fs/xfs/libxfs/xfs_format.h    |    2 ++
> > >  2 files changed, 10 insertions(+), 3 deletions(-)
> > 
> > Ok, I looked at this and questioned why it existed and why the
> > code didn't just use XFS_DQTYPE_REC_MASK directly. I think this
> > change exists because you plan on adding a new on-disk flag for
> > bigtime support and hence XFS_DQTYPE_ANY will grow to include the
> > new flag, right?
> 
> Correct.
> 
> > If so, can you add that to the commit message?
> 
> Ok, will do.

Thanks. With that:

Reviewed-by: Dave Chinner <dchinner@redhat.com>

Patch
diff mbox series

diff --git a/fs/xfs/libxfs/xfs_dquot_buf.c b/fs/xfs/libxfs/xfs_dquot_buf.c
index 75c164ed141c..39d64fbc6b87 100644
--- a/fs/xfs/libxfs/xfs_dquot_buf.c
+++ b/fs/xfs/libxfs/xfs_dquot_buf.c
@@ -39,6 +39,8 @@  xfs_dquot_verify(
 	struct xfs_disk_dquot	*ddq,
 	xfs_dqid_t		id)	/* used only during quotacheck */
 {
+	__u8			ddq_type;
+
 	/*
 	 * We can encounter an uninitialized dquot buffer for 2 reasons:
 	 * 1. If we crash while deleting the quotainode(s), and those blks got
@@ -59,9 +61,12 @@  xfs_dquot_verify(
 	if (ddq->d_version != XFS_DQUOT_VERSION)
 		return __this_address;
 
-	if (ddq->d_flags != XFS_DQTYPE_USER &&
-	    ddq->d_flags != XFS_DQTYPE_PROJ &&
-	    ddq->d_flags != XFS_DQTYPE_GROUP)
+	if (ddq->d_flags & ~XFS_DQTYPE_ANY)
+		return __this_address;
+	ddq_type = ddq->d_flags & XFS_DQTYPE_REC_MASK;
+	if (ddq_type != XFS_DQTYPE_USER &&
+	    ddq_type != XFS_DQTYPE_PROJ &&
+	    ddq_type != XFS_DQTYPE_GROUP)
 		return __this_address;
 
 	if (id != -1 && id != be32_to_cpu(ddq->d_id))
diff --git a/fs/xfs/libxfs/xfs_format.h b/fs/xfs/libxfs/xfs_format.h
index 0fa969f6202c..29564bd32bef 100644
--- a/fs/xfs/libxfs/xfs_format.h
+++ b/fs/xfs/libxfs/xfs_format.h
@@ -1158,6 +1158,8 @@  static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
 				 XFS_DQTYPE_PROJ | \
 				 XFS_DQTYPE_GROUP)
 
+#define XFS_DQTYPE_ANY		(XFS_DQTYPE_REC_MASK)
+
 /*
  * This is the main portion of the on-disk representation of quota information
  * for a user.  We pad this with some more expansion room to construct the on