Skip to content

Commit 898f706

Browse files
mudongliangkleikamp
authored andcommitted
fs: jfs: fix shift-out-of-bounds in dbAllocAG
Syzbot found a crash : UBSAN: shift-out-of-bounds in dbAllocAG. The underlying bug is the missing check of bmp->db_agl2size. The field can be greater than 64 and trigger the shift-out-of-bounds. Fix this bug by adding a check of bmp->db_agl2size in dbMount since this field is used in many following functions. The upper bound for this field is L2MAXL2SIZE - L2MAXAG, thanks for the help of Dave Kleikamp. Note that, for maintenance, I reorganized error handling code of dbMount. Reported-by: [email protected] Signed-off-by: Dongliang Mu <[email protected]> Signed-off-by: Dave Kleikamp <[email protected]>
1 parent bbb8ceb commit 898f706

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

fs/jfs/jfs_dmap.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ int dbMount(struct inode *ipbmap)
155155
struct bmap *bmp;
156156
struct dbmap_disk *dbmp_le;
157157
struct metapage *mp;
158-
int i;
158+
int i, err;
159159

160160
/*
161161
* allocate/initialize the in-memory bmap descriptor
@@ -170,8 +170,8 @@ int dbMount(struct inode *ipbmap)
170170
BMAPBLKNO << JFS_SBI(ipbmap->i_sb)->l2nbperpage,
171171
PSIZE, 0);
172172
if (mp == NULL) {
173-
kfree(bmp);
174-
return -EIO;
173+
err = -EIO;
174+
goto err_kfree_bmp;
175175
}
176176

177177
/* copy the on-disk bmap descriptor to its in-memory version. */
@@ -181,9 +181,8 @@ int dbMount(struct inode *ipbmap)
181181
bmp->db_l2nbperpage = le32_to_cpu(dbmp_le->dn_l2nbperpage);
182182
bmp->db_numag = le32_to_cpu(dbmp_le->dn_numag);
183183
if (!bmp->db_numag) {
184-
release_metapage(mp);
185-
kfree(bmp);
186-
return -EINVAL;
184+
err = -EINVAL;
185+
goto err_release_metapage;
187186
}
188187

189188
bmp->db_maxlevel = le32_to_cpu(dbmp_le->dn_maxlevel);
@@ -194,6 +193,11 @@ int dbMount(struct inode *ipbmap)
194193
bmp->db_agwidth = le32_to_cpu(dbmp_le->dn_agwidth);
195194
bmp->db_agstart = le32_to_cpu(dbmp_le->dn_agstart);
196195
bmp->db_agl2size = le32_to_cpu(dbmp_le->dn_agl2size);
196+
if (bmp->db_agl2size > L2MAXL2SIZE - L2MAXAG) {
197+
err = -EINVAL;
198+
goto err_release_metapage;
199+
}
200+
197201
for (i = 0; i < MAXAG; i++)
198202
bmp->db_agfree[i] = le64_to_cpu(dbmp_le->dn_agfree[i]);
199203
bmp->db_agsize = le64_to_cpu(dbmp_le->dn_agsize);
@@ -214,6 +218,12 @@ int dbMount(struct inode *ipbmap)
214218
BMAP_LOCK_INIT(bmp);
215219

216220
return (0);
221+
222+
err_release_metapage:
223+
release_metapage(mp);
224+
err_kfree_bmp:
225+
kfree(bmp);
226+
return err;
217227
}
218228

219229

0 commit comments

Comments
 (0)