Skip to contentSkip to conversation

xfs: check da node magic in _node_lookup_int

PATCH In review Darrick J. Wong 2 participants 3 messages Jul 31, 2018 – Aug 1, 2018 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: check da node magic in _node_lookup_int

From: Darrick J. Wong <[email protected]>

Before we start processing what we /think/ is a da3 node block, actually check the magic to make sure that we're looking at a node block. This way we won't blow the asserts in _node_hdr_from_disk on corrupted metadata.

---
 fs/xfs/libxfs/xfs_da_btree.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_da_btree.c +4 -1
index 9efbd2038ffb..70e7da634f3e 100644
@@ -1522,8 +1522,11 @@ xfs_da3_node_lookup_int(
 			break;
 		}
 
-		blk->magic = XFS_DA_NODE_MAGIC;
+		if (blk->magic != XFS_DA_NODE_MAGIC &&
+		    blk->magic != XFS_DA3_NODE_MAGIC)
+			return -EFSCORRUPTED;
 
+		blk->magic = XFS_DA_NODE_MAGIC;
 
 		/*
 		 * Search an intermediate node for a match.
#1 lore raw
Quoted 17 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Before we start processing what we /think/ is a da3 node block, actually check the magic to make sure that we're looking at a node block. This way we won't blow the asserts in _node_hdr_from_disk on corrupted metadata.

---
 fs/xfs/libxfs/xfs_da_btree.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_da_btree.c +0 -0
index 9efbd2038ffb..70e7da634f3e 100644

fs/xfs/libxfs/xfs_da_btree.c xfs_da3_node_lookup_int( · line 1529

Quoted 9 lines
fs/xfs/libxfs/xfs_da_btree.c +4 -1
@@ -1522,8 +1522,11 @@ xfs_da3_node_lookup_int(
 			break;
 		}
 
-		blk->magic = XFS_DA_NODE_MAGIC;
+		if (blk->magic != XFS_DA_NODE_MAGIC &&
+		    blk->magic != XFS_DA3_NODE_MAGIC)
+			return -EFSCORRUPTED;
 
+		blk->magic = XFS_DA_NODE_MAGIC;

Can we please use a temporary variable for the on-disk magic number checks, then? blk->magic isn't supposed to hold the on disk format magic number - it's just an indication of the format the current state block points at - so using it to temporarily store the on disk magic number for checks like this is just wrong....

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw
Quoted 26 lines · Dave Chinner
Quoted 25 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

Before we start processing what we /think/ is a da3 node block, actually check the magic to make sure that we're looking at a node block. This way we won't blow the asserts in _node_hdr_from_disk on corrupted metadata.

---
 fs/xfs/libxfs/xfs_da_btree.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/xfs/libxfs/xfs_da_btree.c +3 -1
index 9efbd2038ffb..70e7da634f3e 100644
@@ -1522,8 +1522,11 @@ xfs_da3_node_lookup_int(
 			break;
 		}
 
-		blk->magic = XFS_DA_NODE_MAGIC;
+		if (blk->magic != XFS_DA_NODE_MAGIC &&
+		    blk->magic != XFS_DA3_NODE_MAGIC)
+			return -EFSCORRUPTED;
 
Quoted 7 lines

fs/xfs/libxfs/xfs_da_btree.c xfs_da3_node_lookup_int( · line 1529

Quoted 1 line
fs/xfs/libxfs/xfs_da_btree.c +1 -0
+		blk->magic = XFS_DA_NODE_MAGIC;

Can we please use a temporary variable for the on-disk magic number checks, then? blk->magic isn't supposed to hold the on disk format magic number - it's just an indication of the format the current state block points at - so using it to temporarily store the on disk magic number for checks like this is just wrong....

Ok.

--D

Quoted 10 lines

Cheers,

Dave.

Signature · 6 lines
Dave Chinner
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html