[PATCH] Check for dmap corruption before using leafidx (6 of 6)
[email protected] Wed, 7 Jul 2004 16:41:35 -0500
| Newsgroups | gmane.comp.file-systems.jfs.patches |
|---|---|
| Message-ID | <[email protected]> |
# This is a BitKeeper generated diff -Nru style patch. # # ChangeSet # 2004/07/07 16:04:45-05:00 [email protected] # JFS: Check for dmap corruption before using leafidx # # Signed-off-by: Dave Kleikamp <[email protected]> # diff -Nru a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c --- a/fs/jfs/jfs_dmap.c 2004-07-07 16:38:11 -05:00 +++ b/fs/jfs/jfs_dmap.c 2004-07-07 16:38:11 -05:00 @@ -1204,6 +1204,12 @@ s8 *leaf; u32 mask; + if (dp->tree.leafidx != cpu_to_le32(LEAFIND)) { + jfs_error(bmp->db_ipbmap->i_sb, + "dbAllocNext: Corrupt dmap page"); + return -EIO; + } + /* pick up a pointer to the leaves of the dmap tree. */ leaf = dp->tree.stree + le32_to_cpu(dp->tree.leafidx); @@ -1327,6 +1333,13 @@ struct dmap * dp, s64 blkno, int nblocks, int l2nb, s64 * results) { int word, lword, rc; + + if (dp->tree.leafidx != cpu_to_le32(LEAFIND)) { + jfs_error(bmp->db_ipbmap->i_sb, + "dbAllocNear: Corrupt dmap page"); + return -EIO; + } + s8 *leaf = dp->tree.stree + le32_to_cpu(dp->tree.leafidx); /* determine the word within the dmap that holds the hint @@ -1489,6 +1502,13 @@ dcp = (struct dmapctl *) mp->data; budmin = dcp->budmin; + if (dcp->leafidx != cpu_to_le32(CTLLEAFIND)) { + jfs_error(bmp->db_ipbmap->i_sb, + "dbAllocAG: Corrupt dmapctl page"); + release_metapage(mp); + return -EIO; + } + /* search the subtree(s) of the dmap control page that describes * the allocation group, looking for sufficient free space. to begin, * determine how many allocation groups are represented in a dmap @@ -1697,6 +1717,13 @@ dcp = (struct dmapctl *) mp->data; budmin = dcp->budmin; + if (dcp->leafidx != cpu_to_le32(CTLLEAFIND)) { + jfs_error(bmp->db_ipbmap->i_sb, + "dbFindCtl: Corrupt dmapctl page"); + release_metapage(mp); + return -EIO; + } + /* search the tree within the dmap control page for * sufficent free space. if sufficient free space is found, * dbFindLeaf() returns the index of the leaf at which @@ -2458,6 +2485,13 @@ if (mp == NULL) return -EIO; dcp = (struct dmapctl *) mp->data; + + if (dcp->leafidx != cpu_to_le32(CTLLEAFIND)) { + jfs_error(bmp->db_ipbmap->i_sb, + "dbAdjCtl: Corrupt dmapctl page"); + release_metapage(mp); + return -EIO; + } /* determine the leaf number corresponding to the block and * the index within the dmap control tree.