xfs
[Top] [All Lists]

Re: [PATCH] xfs_repair: fix verify_ag_bno() overflow

To: xfs-oss <xfs@xxxxxxxxxxx>, Jesse Stroik <jstroik@xxxxxxxxxxxxx>
Subject: Re: [PATCH] xfs_repair: fix verify_ag_bno() overflow
From: Eric Sandeen <sandeen@xxxxxxxxxxx>
Date: Wed, 01 Jul 2009 17:15:33 -0500
In-reply-to: <4A4BC7FF.6050004@xxxxxxxxxxx>
References: <4A4BC7FF.6050004@xxxxxxxxxxx>
User-agent: Thunderbird 2.0.0.22 (Macintosh/20090605)
Argh self-nak on that one, stupid thinko; it always returns
1 for a non-last AG :/  Just add the cast and don't get fancy!

V2 below:

-------

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;

Reported-by: Jesse Stroik <jstroik@xxxxxxxxxxxxx>
Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxxx>
---

diff --git a/repair/dinode.c b/repair/dinode.c
index fdf52db..84e1d05 100644
--- a/repair/dinode.c
+++ b/repair/dinode.c
@@ -319,7 +319,8 @@ verify_ag_bno(xfs_sb_t *sbp,
                return (agbno >= sbp->sb_agblocks);
        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;
 }
 

<Prev in Thread] Current Thread [Next in Thread>