Skip to contentSkip to conversation

Check block magic number so we scan only valid blocks.

PATCH In review Peter Watkins 2 participants 3 messages Jul 7, 2010 – Jul 8, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Check block magic number so we scan only valid blocks.

Hello,

Occasionally I've hit a SEGV while querying free space in xfs_db on a mounted file system. In scanfunc_bno, block->bb_numrecs has crazy values. And bb_magic is not XFS_ABTB_MAGIC.

Does a check like this, similiar to other places, make sense? Should scanfunc_cnt make a similiar check?

---
 db/freesp.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
db/freesp.c +3 -0
index e1902c6..7825628 100644
@@ -286,6 +286,9 @@ scanfunc_bno(
 	xfs_alloc_ptr_t		*pp;
 	xfs_alloc_rec_t		*rp;
 
+	if (be32_to_cpu(block->bb_magic) != XFS_ABTB_MAGIC)
+		return;
+
 	if (level == 0) {
 		rp = XFS_ALLOC_REC_ADDR(mp, block, 1);
 		for (i = 0; i < be16_to_cpu(block->bb_numrecs); i++)
Signature · 6 lines
1.6.0.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 7 lines · Peter Watkins

Hello,

Occasionally I've hit a SEGV while querying free space in xfs_db on a mounted file system. In scanfunc_bno, block->bb_numrecs has crazy values. And bb_magic is not XFS_ABTB_MAGIC.

Does a check like this, similiar to other places, make sense?

Yes, it's reasonable. As long as you'd don't expect directly poking at a life partition giving correct results..

Quoted 1 line

Should scanfunc_cnt make a similiar check?

Yes.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw

PATCH 1/1 Check block magic number so we scan only valid blocks.

OK, thanks for taking a look.

Here's the complete patch in case anyone is interested.

-Peter

---
 db/freesp.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
db/freesp.c +6 -0
index e1902c6..c4dabad 100644
@@ -286,6 +286,9 @@ scanfunc_bno(
 	xfs_alloc_ptr_t		*pp;
 	xfs_alloc_rec_t		*rp;
 
+	if (be32_to_cpu(block->bb_magic) != XFS_ABTB_MAGIC)
+		return;
+
 	if (level == 0) {
 		rp = XFS_ALLOC_REC_ADDR(mp, block, 1);
 		for (i = 0; i < be16_to_cpu(block->bb_numrecs); i++)
@@ -310,6 +313,9 @@ scanfunc_cnt(
 	xfs_alloc_ptr_t		*pp;
 	xfs_alloc_rec_t		*rp;
 
+	if (be32_to_cpu(block->bb_magic) != XFS_ABTC_MAGIC)
+		return;
+
 	if (level == 0) {
 		rp = XFS_ALLOC_REC_ADDR(mp, block, 1);
 		for (i = 0; i < be16_to_cpu(block->bb_numrecs); i++)
Signature · 6 lines
1.6.0.4

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs