Forwarded: [PATCH] jfs: fix off-by-one in dbFindLeaf tree bounds check

From: syzbot

Date: Fri Apr 17 2026 - 06:14:33 EST


For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx, syzkaller-bugs@xxxxxxxxxxxxxxxx.

***

Subject: [PATCH] jfs: fix off-by-one in dbFindLeaf tree bounds check
Author: tristmd@xxxxxxxxx

From: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>

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


The bounds check in dbFindLeaf() uses a strict greater-than comparison
(x + n > max_size) to guard access to the dmt_stree[] array. However,
max_size is set to the array size itself (TREESIZE or CTLTREESIZE), so
valid indices are 0 through max_size-1. When x + n equals max_size, the
check passes but the subsequent array access tp->dmt_stree[x + n] reads
one element past the end of the array.

This is reached when a corrupted filesystem image has an invalid
dmt_height value that causes the tree walk loop to descend beyond the
actual tree depth, pushing the starting index ti to exactly max_size.
For the dmapctl case (CTLTREESIZE = 1365), a height of 6 instead of the
valid maximum of 5 produces: ti = 1 -> 5 -> 21 -> 85 -> 341 -> 1365,
and the access at stree[1365] is one past the s8[1365] array.

UBSAN reports:
UBSAN: array-index-out-of-bounds in fs/jfs/jfs_dmap.c:2976:16
index 1365 is out of range for type 's8[1365]' (aka 'signed char[1365]')

Fix the off-by-one by changing '>' to '>=' so that the boundary index is
correctly treated as out-of-bounds.

Reported-by: syzbot+1afe7ef2d0062e19eeb3@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=1afe7ef2d0062e19eeb3
Fixes: 22cad8bc1d36 ("jfs: fix array-index-out-of-bounds in dbFindLeaf")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tristan Madani <tristan@xxxxxxxxxxxxxxxxxxx>
---
fs/jfs/jfs_dmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

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
@@ -3058,7 +3058,7 @@ static int dbFindLeaf(dmtree_t *tp, int l2nb, int *leafidx, bool is_ctl)
/* sufficient free space found. move to the next
* level (or quit if this is the last level).
*/
- if (x + n > max_size)
+ if (x + n >= max_size)
return -ENOSPC;
if (l2nb <= tp->dmt_stree[x + n])
break;
--
2.43.0