Skip to content

Commit e63866a

Browse files
name2965kleikamp
authored andcommitted
jfs: fix out-of-bounds in dbNextAG() and diAlloc()
In dbNextAG() , there is no check for the case where bmp->db_numag is greater or same than MAXAG due to a polluted image, which causes an out-of-bounds. Therefore, a bounds check should be added in dbMount(). And in dbNextAG(), a check for the case where agpref is greater than bmp->db_numag should be added, so an out-of-bounds exception should be prevented. Additionally, a check for the case where agno is greater or same than MAXAG should be added in diAlloc() to prevent out-of-bounds. Reported-by: Jeongjun Park <[email protected]> Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Jeongjun Park <[email protected]> Signed-off-by: Dave Kleikamp <[email protected]>
1 parent b0b2fc8 commit e63866a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

fs/jfs/jfs_dmap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int dbMount(struct inode *ipbmap)
187187
}
188188

189189
bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag);
190-
if (!bmp->db_numag) {
190+
if (!bmp->db_numag || bmp->db_numag >= MAXAG) {
191191
err = -EINVAL;
192192
goto err_release_metapage;
193193
}
@@ -652,7 +652,7 @@ int dbNextAG(struct inode *ipbmap)
652652
* average free space.
653653
*/
654654
for (i = 0 ; i < bmp->db_numag; i++, agpref++) {
655-
if (agpref == bmp->db_numag)
655+
if (agpref >= bmp->db_numag)
656656
agpref = 0;
657657

658658
if (atomic_read(&bmp->db_active[agpref]))

fs/jfs/jfs_imap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ int diAlloc(struct inode *pip, bool dir, struct inode *ip)
13601360
/* get the ag number of this iag */
13611361
agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb));
13621362
dn_numag = JFS_SBI(pip->i_sb)->bmap->db_numag;
1363-
if (agno < 0 || agno > dn_numag)
1363+
if (agno < 0 || agno > dn_numag || agno >= MAXAG)
13641364
return -EIO;
13651365

13661366
if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) {

0 commit comments

Comments
 (0)