linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: linux-xfs@vger.kernel.org, Dave Chinner <david@fromorbit.com>
Subject: [PATCH v2 10/11] xfs: improve ondisk dquot flags checking
Date: Thu, 16 Jul 2020 18:12:55 -0700	[thread overview]
Message-ID: <20200717011255.GM3151642@magnolia> (raw)
In-Reply-To: <159488198306.3813063.16348101518917273554.stgit@magnolia>

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.

Note that I plan to add y2038 support soon, which will require a new
xfs_dqtype_t flag for extended timestamp support, hence all the work to
make the type masking work correctly.

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

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

  parent reply	other threads:[~2020-07-17  1:13 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-16  6:45 [PATCH v5 00/11] xfs: separate dquot type from flags Darrick J. Wong
2020-07-16  6:45 ` [PATCH 01/11] xfs: drop the type parameter from xfs_dquot_verify Darrick J. Wong
2020-07-16 23:32   ` Dave Chinner
2020-07-21 14:54   ` Christoph Hellwig
2020-07-16  6:45 ` [PATCH 02/11] xfs: rename XFS_DQ_{USER,GROUP,PROJ} to XFS_DQTYPE_* Darrick J. Wong
2020-07-16 23:36   ` Dave Chinner
2020-07-21 14:54   ` Christoph Hellwig
2020-07-16  6:45 ` [PATCH 03/11] xfs: refactor testing if a particular dquot is being enforced Darrick J. Wong
2020-07-16 23:47   ` Dave Chinner
2020-07-21 14:55   ` Christoph Hellwig
2020-07-16  6:45 ` [PATCH 04/11] xfs: remove the XFS_QM_IS[UGP]DQ macros Darrick J. Wong
2020-07-16 23:49   ` Dave Chinner
2020-07-21 14:55   ` Christoph Hellwig
2020-07-16  6:45 ` [PATCH 05/11] xfs: refactor quota type testing Darrick J. Wong
2020-07-16 23:51   ` Dave Chinner
2020-07-21 14:56   ` Christoph Hellwig
2020-07-16  6:45 ` [PATCH 06/11] xfs: always use xfs_dquot_type when extracting type from a dquot Darrick J. Wong
2020-07-16 23:57   ` Dave Chinner
2020-07-21 14:56   ` Christoph Hellwig
2020-07-16  6:46 ` [PATCH 07/11] xfs: remove unnecessary quota type masking Darrick J. Wong
2020-07-17  0:01   ` Dave Chinner
2020-07-21 14:57   ` Christoph Hellwig
2020-07-16  6:46 ` [PATCH 08/11] xfs: replace a few open-coded XFS_DQTYPE_REC_MASK uses Darrick J. Wong
2020-07-17  0:02   ` Dave Chinner
2020-07-17  1:07     ` Darrick J. Wong
2020-07-17  1:18       ` Dave Chinner
2020-07-21 14:57   ` Christoph Hellwig
2020-07-16  6:46 ` [PATCH 09/11] xfs: create xfs_dqtype_t to represent quota types Darrick J. Wong
2020-07-17  0:08   ` Dave Chinner
2020-07-21 14:58   ` Christoph Hellwig
2020-07-16  6:46 ` [PATCH 10/11] xfs: improve ondisk dquot flags checking Darrick J. Wong
2020-07-17  0:13   ` Dave Chinner
2020-07-17  1:05     ` Darrick J. Wong
2020-07-17  1:11       ` Dave Chinner
2020-07-17  1:12   ` Darrick J. Wong [this message]
2020-07-17  1:18     ` [PATCH v2 " Dave Chinner
2020-07-21 14:58     ` Christoph Hellwig
2020-07-16  6:46 ` [PATCH 11/11] xfs: rename the ondisk dquot d_flags to d_type Darrick J. Wong
2020-07-17  0:15   ` Dave Chinner
2020-07-21 14:59   ` Christoph Hellwig

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=20200717011255.GM3151642@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).