Skip to content

Commit 2cc7cc0

Browse files
pskrgagkleikamp
authored andcommitted
jfs: fix divide error in dbNextAG
Syzbot reported divide error in dbNextAG(). The problem was in missing validation check for malicious image. Syzbot crafted an image with bmp->db_numag equal to 0. There wasn't any validation checks, but dbNextAG() blindly use bmp->db_numag in divide expression Fix it by validating bmp->db_numag in dbMount() and return an error if image is malicious Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-and-tested-by: syzbot+46f5c25af73eb8330eb6@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
1 parent b47d5a4 commit 2cc7cc0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/jfs/jfs_dmap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ static const s8 budtab[256] = {
148148
* 0 - success
149149
* -ENOMEM - insufficient memory
150150
* -EIO - i/o error
151+
* -EINVAL - wrong bmap data
151152
*/
152153
int dbMount(struct inode *ipbmap)
153154
{
@@ -179,6 +180,12 @@ int dbMount(struct inode *ipbmap)
179180
bmp->db_nfree = le64_to_cpu(dbmp_le->dn_nfree);
180181
bmp->db_l2nbperpage = le32_to_cpu(dbmp_le->dn_l2nbperpage);
181182
bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag);
183+
if (!bmp->db_numag) {
184+
release_metapage(mp);
185+
kfree(bmp);
186+
return -EINVAL;
187+
}
188+
182189
bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel);
183190
bmp->db_maxag = le32_to_cpu(dbmp_le->dn_maxag);
184191
bmp->db_agpref = le32_to_cpu(dbmp_le->dn_agpref);

0 commit comments

Comments
 (0)