All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: xfs <linux-xfs@vger.kernel.org>
Subject: [PATCH] xfs: abort extended attribute list operation if btree is obviously weird
Date: Mon, 23 Oct 2017 17:28:24 -0700	[thread overview]
Message-ID: <20171024002824.GL5483@magnolia> (raw)

Abort an attribute list operation if the attr btree has obvious problems
like loops back to the root or pointers don't point down the tree.
Found by fuzzing btree[0].before to zero in xfs/402.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_attr_list.c |   54 ++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 43 insertions(+), 11 deletions(-)

diff --git a/fs/xfs/xfs_attr_list.c b/fs/xfs/xfs_attr_list.c
index 5816786..9f6fcc6 100644
--- a/fs/xfs/xfs_attr_list.c
+++ b/fs/xfs/xfs_attr_list.c
@@ -205,18 +205,21 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context)
 }
 
 STATIC int
-xfs_attr_node_list(xfs_attr_list_context_t *context)
+xfs_attr_node_list(
+	struct xfs_attr_list_context	*context)
 {
-	attrlist_cursor_kern_t *cursor;
-	xfs_attr_leafblock_t *leaf;
-	xfs_da_intnode_t *node;
-	struct xfs_attr3_icleaf_hdr leafhdr;
-	struct xfs_da3_icnode_hdr nodehdr;
-	struct xfs_da_node_entry *btree;
-	int error, i;
-	struct xfs_buf *bp;
-	struct xfs_inode	*dp = context->dp;
-	struct xfs_mount	*mp = dp->i_mount;
+	struct xfs_attr3_icleaf_hdr	leafhdr;
+	struct xfs_da3_icnode_hdr	nodehdr;
+	struct attrlist_cursor_kern	*cursor;
+	struct xfs_attr_leafblock	*leaf;
+	struct xfs_da_intnode		*node;
+	struct xfs_da_node_entry	*btree;
+	struct xfs_buf			*bp;
+	struct xfs_inode		*dp = context->dp;
+	struct xfs_mount		*mp = dp->i_mount;
+	int				i;
+	unsigned int			expected_level;
+	int				error;
 
 	trace_xfs_attr_node_list(context);
 
@@ -277,6 +280,7 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
 	 * Note that start of node block is same as start of leaf block.
 	 */
 	if (bp == NULL) {
+		expected_level = -1U;
 		cursor->blkno = 0;
 		for (;;) {
 			uint16_t magic;
@@ -302,6 +306,30 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
 			}
 
 			dp->d_ops->node_hdr_from_disk(&nodehdr, node);
+
+			/* Tree taller than we can handle; bail out! */
+			if (nodehdr.level >= XFS_DA_NODE_MAXDEPTH) {
+				xfs_trans_brelse(context->tp, bp);
+				return -EFSCORRUPTED;
+			}
+
+			if (cursor->blkno == 0) {
+				/*
+				 * This is the root node, set up for the
+				 * next level we want to see.
+				 */
+				expected_level = nodehdr.level - 1;
+			} else if (expected_level != nodehdr.level) {
+				/*
+				 * Not the level we were expecting, which
+				 * implies that the tree is bad.
+				 */
+				xfs_trans_brelse(context->tp, bp);
+				return -EFSCORRUPTED;
+			} else {
+				expected_level--;
+			}
+
 			btree = dp->d_ops->node_tree_p(node);
 			for (i = 0; i < nodehdr.count; btree++, i++) {
 				if (cursor->hashval
@@ -317,6 +345,10 @@ xfs_attr_node_list(xfs_attr_list_context_t *context)
 				return 0;
 			}
 			xfs_trans_brelse(context->tp, bp);
+
+			/* We can't point back to the root. */
+			if (cursor->blkno == 0)
+				return -EFSCORRUPTED;
 		}
 	}
 	ASSERT(bp != NULL);

             reply	other threads:[~2017-10-24  0:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-24  0:28 Darrick J. Wong [this message]
2017-10-24 12:53 ` [PATCH] xfs: abort extended attribute list operation if btree is obviously weird Brian Foster
2017-10-24 17:00   ` 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=20171024002824.GL5483@magnolia \
    --to=darrick.wong@oracle.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 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.