Forwarded: [PATCH] jfs: fix shift-out-of-bounds in dbJoin

syzbot
2026-04-17T10:12:00Z

For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] jfs: fix shift-out-of-bounds in dbJoin
Author: tristmd@gmail.com

From: Tristan Madani <tristan@talencesecurity.com>

#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

dbJoin() computes a buddy size via BUDSIZE(newval, budmin), which
expands to 1 << (newval - budmin). If the on-disk tree metadata is
corrupted such that the leaf values or free counts are inconsistent,
newval can exceed budmin + 31, causing a shift-out-of-bounds:

UBSAN: shift-out-of-bounds in fs/jfs/jfs_dmap.c:2882:11
shift exponent 132 is too large for 32-bit type 'int'

The maximum meaningful newval for a given tree is budmin + l2nleafs,
since BUDSIZE at that point equals nleafs and the while loop would not
execute. Any value beyond that indicates corrupted metadata.

Add a sanity check before the BUDSIZE call: if newval exceeds
budmin + l2nleafs, return -EIO.

Reported-by: syzbot+fa603ae6b02658401ca7@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=fa603ae6b02658401ca7
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@vger.kernel.org
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
fs/jfs/jfs_dmap.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index XXXXXXX..XXXXXXX 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -2864,6 +2864,14 @@ static int dbJoin(dmtree_t *tp, int leafno, int newval, bool is_ctl)
if (newval >= tp->dmt_budmin) {
/* pickup a pointer to the leaves of the tree.
*/
+
+ /* Validate newval to prevent shift-out-of-bounds in
+ * BUDSIZE. The maximum meaningful value is budmin +
+ * l2nleafs; anything beyond indicates corrupted metadata.
+ */
+ if (newval > tp->dmt_budmin +
+ le32_to_cpu(tp->dmt_l2nleafs))
+ return -EIO;
leaf = tp->dmt_stree + le32_to_cpu(tp->dmt_leafidx);

/* try to join the specified leaf into a large binary
--
2.39.5