Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f295a21 authored by Dave Chinner's avatar Dave Chinner Committed by Ben Myers
Browse files

xfs: check magic numbers in dir3 leaf verifier first



Calling xfs_dir3_leaf_hdr_from_disk() in a verifier before
validating the magic numbers in the buffer results in ASSERT
failures due to mismatching magic numbers when a corruption occurs.
Seeing as the verifier is supposed to catch the corruption and pass
it back to the caller, having the verifier assert fail on error
defeats the purpose of detecting the errors in the first place.

Check the magic numbers direct from the buffer before decoding the
header.

Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarBen Myers <bpm@sgi.com>
parent a30b0367
Loading
Loading
Loading
Loading
+13 −7
Original line number Original line Diff line number Diff line
@@ -180,6 +180,11 @@ xfs_dir3_leaf_check_int(
	return true;
	return true;
}
}


/*
 * We verify the magic numbers before decoding the leaf header so that on debug
 * kernels we don't get assertion failures in xfs_dir3_leaf_hdr_from_disk() due
 * to incorrect magic numbers.
 */
static bool
static bool
xfs_dir3_leaf_verify(
xfs_dir3_leaf_verify(
	struct xfs_buf		*bp,
	struct xfs_buf		*bp,
@@ -191,24 +196,25 @@ xfs_dir3_leaf_verify(


	ASSERT(magic == XFS_DIR2_LEAF1_MAGIC || magic == XFS_DIR2_LEAFN_MAGIC);
	ASSERT(magic == XFS_DIR2_LEAF1_MAGIC || magic == XFS_DIR2_LEAFN_MAGIC);


	xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf);
	if (xfs_sb_version_hascrc(&mp->m_sb)) {
	if (xfs_sb_version_hascrc(&mp->m_sb)) {
		struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr;
		struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr;
		__uint16_t		magic3;


		if ((magic == XFS_DIR2_LEAF1_MAGIC &&
		magic3 = (magic == XFS_DIR2_LEAF1_MAGIC) ? XFS_DIR3_LEAF1_MAGIC
		     leafhdr.magic != XFS_DIR3_LEAF1_MAGIC) ||
							 : XFS_DIR3_LEAFN_MAGIC;
		    (magic == XFS_DIR2_LEAFN_MAGIC &&
		     leafhdr.magic != XFS_DIR3_LEAFN_MAGIC))
			return false;


		if (leaf3->info.hdr.magic != cpu_to_be16(magic3))
			return false;
		if (!uuid_equal(&leaf3->info.uuid, &mp->m_sb.sb_uuid))
		if (!uuid_equal(&leaf3->info.uuid, &mp->m_sb.sb_uuid))
			return false;
			return false;
		if (be64_to_cpu(leaf3->info.blkno) != bp->b_bn)
		if (be64_to_cpu(leaf3->info.blkno) != bp->b_bn)
			return false;
			return false;
	} else {
	} else {
		if (leafhdr.magic != magic)
		if (leaf->hdr.info.magic != cpu_to_be16(magic))
			return false;
			return false;
	}
	}

	xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf);
	return xfs_dir3_leaf_check_int(mp, &leafhdr, leaf);
	return xfs_dir3_leaf_check_int(mp, &leafhdr, leaf);
}
}