Skip to contentSkip to conversation

xfsprogs: skip freelist scans of corrupt agf

PATCH In review Eric Sandeen 3 participants 3 messages Mar 9, 2013 – Mar 11, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfsprogs: skip freelist scans of corrupt agf

If an agf has bad values in the freelist, this can wreak havoc if, for example, first > last and the loop never exits; we index agfl->agfl_bno[i] off into the weeds.

If they're off, warn about it and skip the scan.

Thisis done both in xfs_check and xfs_db's freespace cmd.

Also fix uninit'd variable "i" from previous, similar fix for xfs_repair.

---

db/check.c +10 -0
index e601e0a..35325b7 100644
@@ -4112,6 +4112,16 @@ scan_freelist(
 		return;
 	}
 	i = be32_to_cpu(agf->agf_flfirst);
+
+	/* verify agf values before proceeding */
+	if (be32_to_cpu(agf->agf_flfirst) >= XFS_AGFL_SIZE(mp) ||
+	    be32_to_cpu(agf->agf_fllast) >= XFS_AGFL_SIZE(mp)) {
+		dbprintf(_("agf %d freelist blocks bad, skipping "
+			  "freelist scan\n"), i);
+		pop_cur();
+		return;
+	}
+
 	count = 0;
 	for (;;) {
 		bno = be32_to_cpu(agfl->agfl_bno[i]);
db/freesp.c +10 -0
index c4dabad..472b1f7 100644
@@ -239,6 +239,16 @@ scan_freelist(
 				XFS_FSS_TO_BB(mp, 1), DB_RING_IGN, NULL);
 	agfl = iocur_top->data;
 	i = be32_to_cpu(agf->agf_flfirst);
+
+	/* verify agf values before proceeding */
+	if (be32_to_cpu(agf->agf_flfirst) >= XFS_AGFL_SIZE(mp) ||
+	    be32_to_cpu(agf->agf_fllast) >= XFS_AGFL_SIZE(mp)) {
+		dbprintf(_("agf %d freelist blocks bad, skipping "
+			  "freelist scan\n"), i);
+		pop_cur();
+		return;
+	}
+
 	for (;;) {
 		bno = be32_to_cpu(agfl->agfl_bno[i]);
 		addtohist(seqno, bno, 1);
repair/scan.c +1 -1
index 1d39bdc..6a62dff 100644
@@ -1066,6 +1066,7 @@ scan_freelist(
 		return;
 	}
 	agfl = XFS_BUF_TO_AGFL(agflbuf);
+	i = be32_to_cpu(agf->agf_flfirst);
 
 	if (no_modify) {
 		/* agf values not fixed in verify_set_agf, so recheck */
@@ -1078,7 +1079,6 @@ scan_freelist(
 	} else /* should have been fixed in verify_set_agf() */
 		ASSERT(0);
 
-	i = be32_to_cpu(agf->agf_flfirst);
 	count = 0;
 	for (;;) {
 		bno = be32_to_cpu(agfl->agfl_bno[i]);

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

Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Eric Sandeen

If an agf has bad values in the freelist, this can wreak havoc if, for example, first > last and the loop never exits; we index agfl->agfl_bno[i] off into the weeds.

If they're off, warn about it and skip the scan.

Thisis done both in xfs_check and xfs_db's freespace cmd.

Also fix uninit'd variable "i" from previous, similar fix for xfs_repair.

Looks good.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by Dave Chinner on v1 1/1
#2 lore raw
In reply to Eric Sandeen

This has been commited.

Thanks
--Rich

commit a529cc7f0e5bd1632e5169d015c54e3a6122ee0f

Author: Eric Sandeen <[email protected]>
Date:   Sat Mar 9 15:21:55 2013 +0000

xfsprogs: skip freelist scans of corrupt agf

If an agf has bad values in the freelist, this can wreak havoc if, for example, first > last and the loop never exits; we index agfl->agfl_bno[i] off into the weeds.

If they're off, warn about it and skip the scan.

This is done both in xfs_check and xfs_db's freespace cmd.

Also fix uninit'd variable "i" from previous, similar fix for xfs_repair.

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