aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chinner <david@fromorbit.com>2013-09-02 20:06:58 -0400
committerBen Myers <bpm@sgi.com>2013-09-09 18:43:58 -0400
commit0f295a214bb7658ca37bd61a8a1f0cd4a9d86c1f (patch)
treea5909bdca6ea1a287717d6b88dc76b4fd72f3688
parenta30b0367978f75a2659c71b33739e5e445a363c8 (diff)
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: Dave Chinner <dchinner@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ben Myers <bpm@sgi.com>
-rw-r--r--fs/xfs/xfs_dir2_leaf.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/fs/xfs/xfs_dir2_leaf.c b/fs/xfs/xfs_dir2_leaf.c
index 08984eeee159..1021c8356d08 100644
--- a/fs/xfs/xfs_dir2_leaf.c
+++ b/fs/xfs/xfs_dir2_leaf.c
@@ -180,6 +180,11 @@ xfs_dir3_leaf_check_int(
180 return true; 180 return true;
181} 181}
182 182
183/*
184 * We verify the magic numbers before decoding the leaf header so that on debug
185 * kernels we don't get assertion failures in xfs_dir3_leaf_hdr_from_disk() due
186 * to incorrect magic numbers.
187 */
183static bool 188static bool
184xfs_dir3_leaf_verify( 189xfs_dir3_leaf_verify(
185 struct xfs_buf *bp, 190 struct xfs_buf *bp,
@@ -191,24 +196,25 @@ xfs_dir3_leaf_verify(
191 196
192 ASSERT(magic == XFS_DIR2_LEAF1_MAGIC || magic == XFS_DIR2_LEAFN_MAGIC); 197 ASSERT(magic == XFS_DIR2_LEAF1_MAGIC || magic == XFS_DIR2_LEAFN_MAGIC);
193 198
194 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf);
195 if (xfs_sb_version_hascrc(&mp->m_sb)) { 199 if (xfs_sb_version_hascrc(&mp->m_sb)) {
196 struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr; 200 struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr;
201 __uint16_t magic3;
197 202
198 if ((magic == XFS_DIR2_LEAF1_MAGIC && 203 magic3 = (magic == XFS_DIR2_LEAF1_MAGIC) ? XFS_DIR3_LEAF1_MAGIC
199 leafhdr.magic != XFS_DIR3_LEAF1_MAGIC) || 204 : XFS_DIR3_LEAFN_MAGIC;
200 (magic == XFS_DIR2_LEAFN_MAGIC &&
201 leafhdr.magic != XFS_DIR3_LEAFN_MAGIC))
202 return false;
203 205
206 if (leaf3->info.hdr.magic != cpu_to_be16(magic3))
207 return false;
204 if (!uuid_equal(&leaf3->info.uuid, &mp->m_sb.sb_uuid)) 208 if (!uuid_equal(&leaf3->info.uuid, &mp->m_sb.sb_uuid))
205 return false; 209 return false;
206 if (be64_to_cpu(leaf3->info.blkno) != bp->b_bn) 210 if (be64_to_cpu(leaf3->info.blkno) != bp->b_bn)
207 return false; 211 return false;
208 } else { 212 } else {
209 if (leafhdr.magic != magic) 213 if (leaf->hdr.info.magic != cpu_to_be16(magic))
210 return false; 214 return false;
211 } 215 }
216
217 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf);
212 return xfs_dir3_leaf_check_int(mp, &leafhdr, leaf); 218 return xfs_dir3_leaf_check_int(mp, &leafhdr, leaf);
213} 219}
214 220