jfs: validate l2nbperpage in diMount to prevent shift-out-of-bounds
PATCH 1/1 jfs: validate l2nbperpage in diMount to prevent shift-out-of-bounds
From: Tristan Madani <[email protected]>
diMount() reads l2nbperpage from the disk inode aggregate without validation. A corrupted filesystem image can set this field to a value exceeding the bit width of the shift operand in jfs_statfs(), causing UBSAN shift-out-of-bounds.
Add validation of l2nbperpage against reasonable bounds before using it in arithmetic operations.
--- fs/jfs/jfs_imap.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
fs/jfs/jfs_imap.c +12 -0
@@ -124,6 +124,18 @@ int diMount(struct inode *ipimap)atomic_set (&imap->im_numfree,le32_to_cpu (dinom_le->in_numfree)); imap->im_nbperiext =le32_to_cpu (dinom_le->in_nbperiext); imap->im_l2nbperiext =le32_to_cpu (dinom_le->in_l2nbperiext); + +if (imap->im_l2nbperiext <0 || + imap->im_l2nbperiext >30 || + imap->im_nbperiext != (1 << imap->im_l2nbperiext)) { +jfs_err ("diMount: invalid imap parameters: " +"nbperiext(%d) l2nbperiext(%d)" , + imap->im_nbperiext, imap->im_l2nbperiext); +release_metapage (mp); +kfree (imap); +return -EINVAL ; + } +for (index =0 ; index <MAXAG ; index++) { imap->im_agctl[index].inofree =le32_to_cpu (dinom_le->in_agctl[index].inofree);
Signature · 1 line
2.47.3
Quoted 2 lines · Tristan Madani
Add validation of l2nbperpage against reasonable bounds before using it in arithmetic operations.
The fix looks correct to me. Minor nit: the subject and commit message say "l2nbperpage" but the actual field being validated is "im_l2nbperiext" (and im_nbperiext). Could you respin with the corrected naming?