mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] jfs: validate l2nbperpage in diMount to prevent shift-out-of-bounds
@ 2026-04-18 13:10 Tristan Madani
  2026-06-01 12:43 ` Yun Zhou
  0 siblings, 1 reply; 2+ messages in thread
From: Tristan Madani @ 2026-04-18 13:10 UTC (permalink / raw)
  To: shaggy; +Cc: jfs-discussion, linux-kernel, syzbot+13ba7f3e9a17f77250fe

From: Tristan Madani <tristan@talencesecurity.com>

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@syzkaller.appspotmail.com
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
 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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] jfs: validate l2nbperpage in diMount to prevent shift-out-of-bounds
  2026-04-18 13:10 [PATCH] jfs: validate l2nbperpage in diMount to prevent shift-out-of-bounds Tristan Madani
@ 2026-06-01 12:43 ` Yun Zhou
  0 siblings, 0 replies; 2+ messages in thread
From: Yun Zhou @ 2026-06-01 12:43 UTC (permalink / raw)
  To: tristmd; +Cc: jfs-discussion, linux-kernel, shaggy, syzbot+13ba7f3e9a17f77250fe

On Fri, Apr 18, 2026, Tristan Madani <tristmd@gmail.com> wrote:
> 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?

Reviewed-by: Yun Zhou <yun.zhou@windriver.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-01 12:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-18 13:10 [PATCH] jfs: validate l2nbperpage in diMount to prevent shift-out-of-bounds Tristan Madani
2026-06-01 12:43 ` Yun Zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®