Skip to content

Commit 64933ab

Browse files
juntongdengkleikamp
authored andcommitted
fs/jfs: Add validity check for db_maxag and db_agpref
Both db_maxag and db_agpref are used as the index of the db_agfree array, but there is currently no validity check for db_maxag and db_agpref, which can lead to errors. The following is related bug reported by Syzbot: UBSAN: array-index-out-of-bounds in fs/jfs/jfs_dmap.c:639:20 index 7936 is out of range for type 'atomic_t[128]' Add checking that the values of db_maxag and db_agpref are valid indexes for the db_agfree array. Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=38e876a8aa44b7115c76 Signed-off-by: Juntong Deng <[email protected]> Signed-off-by: Dave Kleikamp <[email protected]>
1 parent 525b861 commit 64933ab

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/jfs/jfs_dmap.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ int dbMount(struct inode *ipbmap)
195195
bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel);
196196
bmp->db_maxag = le32_to_cpu(dbmp_le->dn_maxag);
197197
bmp->db_agpref = le32_to_cpu(dbmp_le->dn_agpref);
198+
if (bmp->db_maxag >= MAXAG || bmp->db_maxag < 0 ||
199+
bmp->db_agpref >= MAXAG || bmp->db_agpref < 0) {
200+
err = -EINVAL;
201+
goto err_release_metapage;
202+
}
203+
198204
bmp->db_aglevel = le32_to_cpu(dbmp_le->dn_aglevel);
199205
bmp->db_agheight = le32_to_cpu(dbmp_le->dn_agheight);
200206
bmp->db_agwidth = le32_to_cpu(dbmp_le->dn_agwidth);

0 commit comments

Comments
 (0)