[PATCH] jfs: validate l2nbperpage in diMount to prevent shift-out-of-bounds
From: Tristan Madani
Date: Sat Apr 18 2026 - 09:10:36 EST
From: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
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.
Reported-by: syzbot+13ba7f3e9a17f77250fe@xxxxxxxxxxxxxxxxxxxxxxxxx
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
---
fs/jfs/jfs_imap.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
index b84ba4d7dfb44..eafbd2b55df75 100644
--- a/fs/jfs/jfs_imap.c
+++ b/fs/jfs/jfs_imap.c
@@ -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);
--
2.47.3