xfs_repair: skip freelist scan of dodgy agf in no-modify mode
PATCH 1/1 xfs_repair: skip freelist scan of dodgy agf in no-modify mode
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.
---
repair/agheader.c +8 -0
@@ -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),
repair/scan.c +11 -0
@@ -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
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Quoted 20 lines · Eric Sandeen
In no-modify mode (-n),
verify_set_agfdoesn't fix up bad freelist blocks that it finds. When we get toscan_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 <[email protected]>Signed-off-by Eric Sandeen <[email protected]>---
repair/agheader.c +0
-0
repair/agheader.c verify_set_agf(xfs_mount_t *mp, xfs_agf_t *agf, xfs_agnumber_t i) · line 95
Quoted 10 lines
repair/agheader.c +7
-0@@ -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 ); + }
I don't think that test is correct. The free list is circular and is indexed as a pair of head/tail pointers. Hence flfirst > fllast can be actually valid. e.g. flcount = 4, flfirst=126, fllast = 2 is a valid free list.
Quoted 9 lines
repair/agheader.c +1
-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),repair/scan.c +0
-0
repair/scan.c scan_freelist( · line 1075
Quoted 9 lines
repair/scan.c +6
-0@@ -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"),
"skipping freelist scan"
repair/scan.c scan_freelist( · line 1077
Quoted 2 lines
repair/scan.c +2
-0+ i); +return ;
Also, you might be missing a set of {} there - that will always return immediately if no_modify is set....
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 28 lines · Dave Chinner
Quoted 27 lines · Eric Sandeen
In no-modify mode (-n),
verify_set_agfdoesn't fix up bad freelist blocks that it finds. When we get toscan_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 <[email protected]>Signed-off-by Eric Sandeen <[email protected]>---
repair/agheader.c +4
-0@@ -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));
Quoted 9 lines
repair/agheader.c verify_set_agf(xfs_mount_t *mp, xfs_agf_t *agf, xfs_agnumber_t i) · line 95
Quoted 3 lines
repair/agheader.c +3
-0+if (!no_modify) + agf->agf_fllast = agf->agf_flfirst =cpu_to_be32 (0 ); + }I don't think that test is correct. The free list is circular and is indexed as a pair of head/tail pointers. Hence flfirst > fllast can be actually valid. e.g. flcount = 4, flfirst=126, fllast = 2 is a valid free list.
Doh, ok. Will fix.
Quoted 21 lines
Quoted 9 lines
repair/agheader.c +1
-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),repair/scan.c +0
-0repair/scan.c scan_freelist( · line 1075
Quoted 9 lines
repair/scan.c +6
-0@@ -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"),"skipping freelist scan"
Quoted 6 lines
repair/scan.c scan_freelist( · line 1077
Quoted 2 lines
repair/scan.c +2
-0+ i); +return ;Also, you might be missing a set of {} there - that will always return immediately if
no_modifyis set....
Cripes. 1 demerit for me, sorry. Will fix and resend.
Thanks for the embarrassing review. :)
-Eric
Quoted 7 lines
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
PATCH v2 1/1 xfs_repair: skip freelist scan of corrupt agf in no-modify mode
In reply to Eric SandeenIn xfs_repair's 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.
---
V2: Remove dumb mistakes :/
repair/scan.c +12 -0
@@ -1066,6 +1066,18 @@ scan_freelist(return ; } agfl =XFS_BUF_TO_AGFL (agflbuf); + +if (no_modify) { +/* agf values not fixed in verify_set_agf, so recheck */ +if (be32_to_cpu (agf->agf_flfirst) >=XFS_AGFL_SIZE (mp) || +be32_to_cpu (agf->agf_fllast) >=XFS_AGFL_SIZE (mp)) { +do_warn (_ ("agf %d freelist blocks bad, skipping " +"freelist scan\n" ), i); +return ; + } + }else /* should have been fixed in verify_set_agf() */ +ASSERT (0 ); + i =be32_to_cpu (agf->agf_flfirst); count =0 ;for (;;) {
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH V2] xfs_repair: skip freelist scan of corrupt agf in no-modify mode
Quoted 27 lines · Eric Sandeen
In xfs_repair's no-modify mode (-n),
verify_set_agfdoesn't fix up bad freelist blocks that it finds. When we get toscan_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.
Reported-by Ole Tange <[email protected]>Signed-off-by Eric Sandeen <[email protected]>---
V2: Remove dumb mistakes :/
repair/scan.c +5
-0@@ -1066,6 +1066,18 @@ scan_freelist(return ; } agfl =XFS_BUF_TO_AGFL (agflbuf); + +if (no_modify) { +/* agf values not fixed in verify_set_agf, so recheck */ +if (be32_to_cpu (agf->agf_flfirst) >=XFS_AGFL_SIZE (mp) || +be32_to_cpu (agf->agf_fllast) >=XFS_AGFL_SIZE (mp)) {
repair/scan.c scan_freelist( · line 1083
Quoted 10 lines
repair/scan.c +7
-0+do_warn (_ ("agf %d freelist blocks bad, skipping " +"freelist scan\n" ), i); +return ; + } + }else /* should have been fixed in verify_set_agf() */ +ASSERT (0 ); + i =be32_to_cpu (agf->agf_flfirst); count =0 ;for (;;) {
Looks ok, but IIRC there are overruns in these functions for the same reason (i.e. unchecked use of agf->agf_flfirst as an array index)
db/check.c::scan_freelist()
db/freesp.c::scan_freelist()
I found lots of almost-but-not-quite-exact code duplication like this recenty when doing CRC updates to the userspace code....
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH V2] xfs_repair: skip freelist scan of corrupt agf in no-modify mode
In reply to Eric SandeenThis version looks good. ;)
This has been committed.
commit 7e8e3cce00f38ee1533df0e7bda6bcb584b03e96
Author: Eric Sandeen <[email protected]> Date: Sat Mar 2 21:23:12 2013 +0000
xfsprogs: xfs_repair skip freelist scan of corrupt agf in no-modify
mode
In xfs_repair's 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.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH V2] xfs_repair: skip freelist scan of corrupt agf in no-modify mode
Quoted 5 lines · Rich Johnston
This version looks good. ;)
Reviewed-by Rich Johnston <[email protected]>This has been committed.
Thanks; from what Dave said there are probably other spots that need love as well.
-Eric
Quoted 6 lines
commit
7e8e3cce00f38ee1533df0e7bda6bcb584b03e96Author: Eric Sandeen <[email protected]> Date: Sat Mar 2 21:23:12 2013 +0000xfsprogs:
xfs_repairskip freelist scan of corrupt agf in no-modify mode
Quoted 10 lines
In xfs_repair's no-modify mode (-n),
verify_set_agfdoesn't fix up bad freelist blocks that it finds. When we get toscan_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.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH V2] xfs_repair: skip freelist scan of corrupt agf in no-modify mode
In reply to Rich JohnstonQuoted 5 lines · Rich Johnston
This version looks good. ;)
Reviewed-by Rich Johnston <[email protected]>This has been committed.
Except that all review comments have not been addressed. i.e there are two places that have the same bug and they haven't been fixed.
It's great that you want to commit quickly, but commits should not happen while there are unaddressed issues still outstanding....
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH V2] xfs_repair: skip freelist scan of corrupt agf in no-modify mode
Quoted 5 lines · Dave Chinner
Quoted 4 lines · Rich Johnston
This version looks good. ;)
Reviewed-by Rich Johnston <[email protected]>
Quoted 7 lines
Quoted 1 line
This has been committed.
Except that all review comments have not been addressed. i.e there are two places that have the same bug and they haven't been fixed.
It's great that you want to commit quickly, but commits should not happen while there are unaddressed issues still outstanding....
Sorry Dave I misunderstood your comments. I took them to mean you were going to make those changes with your CRC patch. I will make sure to clarify before committing.
Quoted 5 lines
Cheers,
Dave.
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Re: [PATCH V2] xfs_repair: skip freelist scan of corrupt agf in no-modify mode
In reply to Rich JohnstonQuoted 1 line · Rich Johnston
This version looks good. ;)
Actually it's not quite:
scan.c: In function ‘scan_freelist’:
scan.c:1074: warning: ‘i’ may be used uninitialized in this function
I don't know what's wrong with my brain these days. :/
I will send a patch to fix that along w/ the other scan_freelists shortly.
Sorry :/
-Eric
Quoted 20 lines
Reviewed-by Rich Johnston <[email protected]>This has been committed.
commit
7e8e3cce00f38ee1533df0e7bda6bcb584b03e96Author: Eric Sandeen <[email protected]> Date: Sat Mar 2 21:23:12 2013 +0000xfsprogs:
xfs_repairskip freelist scan of corrupt agf in no-modify modeIn xfs_repair's no-modify mode (-n),
verify_set_agfdoesn't fix up bad freelist blocks that it finds. When we get toscan_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.
Quoted 5 lines
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs