public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_repair: skip freelist scan of dodgy agf in no-modify mode
@ 2013-03-01 23:46 Eric Sandeen
  2013-03-02  1:18 ` Dave Chinner
  2013-03-02 21:23 ` [PATCH V2] xfs_repair: skip freelist scan of corrupt " Eric Sandeen
  0 siblings, 2 replies; 10+ messages in thread
From: Eric Sandeen @ 2013-03-01 23:46 UTC (permalink / raw)
  To: xfs-oss; +Cc: Ole Tange

In no-modify mode (-n), verify_set_agf doesn't fix up bad
freelist blocks that it finds.  When we get to scan_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.

To fix this, re-check the values in no-modify mode, and if
they're off, warn about it and skip the scan.

In addition, add a check to verify_set_agf() to ensure that
first <= last.

Reported-by: Ole Tange <tange@binf.ku.dk>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/repair/agheader.c b/repair/agheader.c
index 769022d..68789fe 100644
--- a/repair/agheader.c
+++ b/repair/agheader.c
@@ -86,6 +86,14 @@ verify_set_agf(xfs_mount_t *mp, xfs_agf_t *agf, xfs_agnumber_t i)
 	 * check first/last AGF fields.  if need be, lose the free
 	 * space in the AGFL, we'll reclaim it later.
 	 */
+	if (be32_to_cpu(agf->agf_flfirst) > be32_to_cpu(agf->agf_fllast)) {
+		do_warn(_("flfirst %d in agf %d > fllast %d\n"),
+			be32_to_cpu(agf->agf_flfirst),
+			i, be32_to_cpu(agf->agf_fllast));
+		if (!no_modify)
+			agf->agf_fllast = agf->agf_flfirst = cpu_to_be32(0);
+	}
+
 	if (be32_to_cpu(agf->agf_flfirst) >= XFS_AGFL_SIZE(mp))  {
 		do_warn(_("flfirst %d in agf %d too large (max = %zu)\n"),
 			be32_to_cpu(agf->agf_flfirst),
diff --git a/repair/scan.c b/repair/scan.c
index 5345094..0f83fb4 100644
--- a/repair/scan.c
+++ b/repair/scan.c
@@ -1067,6 +1067,17 @@ scan_freelist(
 	}
 	agfl = XFS_BUF_TO_AGFL(agflbuf);
 	i = be32_to_cpu(agf->agf_flfirst);
+	if (no_modify) {
+		/* agf values not sanitized, so double check */
+		if (i >= XFS_AGFL_SIZE(mp) ||
+		    be32_to_cpu(agf->agf_fllast) >= XFS_AGFL_SIZE(mp) ||
+		    i > be32_to_cpu(agf->agf_fllast))
+			do_warn(_("agf %d freelist blocks bad, skipping scan\n"),
+				i);
+			return;
+	} else /* should have been fixed in verify_set_agf() */
+		ASSERT(0);
+
 	count = 0;
 	for (;;) {
 		bno = be32_to_cpu(agfl->agfl_bno[i]);

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-03-11 12:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-01 23:46 [PATCH] xfs_repair: skip freelist scan of dodgy agf in no-modify mode Eric Sandeen
2013-03-02  1:18 ` Dave Chinner
2013-03-02  1:22   ` Eric Sandeen
2013-03-02 21:23 ` [PATCH V2] xfs_repair: skip freelist scan of corrupt " Eric Sandeen
2013-03-03 23:36   ` Dave Chinner
2013-03-08 20:31   ` Rich Johnston
2013-03-08 20:31     ` Eric Sandeen
2013-03-09  9:00     ` Dave Chinner
2013-03-11 12:20       ` Rich Johnston
2013-03-09 15:00     ` Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox