public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_repair: fix verify_ag_bno() overflow
@ 2009-07-01 20:33 Eric Sandeen
  2009-07-01 22:15 ` Eric Sandeen
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Sandeen @ 2009-07-01 20:33 UTC (permalink / raw)
  To: xfs-oss, Jesse Stroik

The last test in verify_ag_bno() may overflow:

return (agbno >= (sbp->sb_dblocks -
		((sbp->sb_agcount - 1) * sbp->sb_agblocks)));

because sb_agcount & sb_agblocks are 32-bit integers; this
may then miss corrupt agbnos for the last ag, which can in
turn lead to out of bounds memory accesses later, for example
when the block nr is used to offset in set_agbno_state():

	addr = ba_bmap[(agno)] + (ag_blockno)/XR_BB_NUM;

Also make the first test simpler; agbno > sb_agblocks
is -always- bad, regardless of the agno.  This may even
speed it up a tiny bit.

Reported-by: Jesse Stroik <jstroik@ssec.wisc.edu>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
---

diff --git a/repair/dinode.c b/repair/dinode.c
index fdf52db..f50f1ad 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -315,11 +315,14 @@ verify_ag_bno(xfs_sb_t *sbp,
 		xfs_agnumber_t agno,
 		xfs_agblock_t agbno)
 {
-	if (agno < (sbp->sb_agcount - 1)) 
-		return (agbno >= sbp->sb_agblocks);
-	if (agno == (sbp->sb_agcount - 1)) 
+	/* in all cases bno >= agblocks is bad */
+	if (agbno >= sbp->sb_agblocks)
+		return 1;
+	/* last ag may be smaller */
+	if (agno == (sbp->sb_agcount - 1))
 		return (agbno >= (sbp->sb_dblocks -
-				((sbp->sb_agcount - 1) * sbp->sb_agblocks)));
+				((xfs_drfsbno_t)(sbp->sb_agcount - 1) *
+				 sbp->sb_agblocks)));
 	return 1;
 }
 

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

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

end of thread, other threads:[~2009-07-02  5:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-01 20:33 [PATCH] xfs_repair: fix verify_ag_bno() overflow Eric Sandeen
2009-07-01 22:15 ` Eric Sandeen
2009-07-02  4:13   ` [PATCH V3] xfs_repair: fix agcount*agblocks overflows Eric Sandeen
2009-07-02  5:24     ` Felix Blyakher

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