Skip to contentSkip to conversation

UBSAN: array-index-out-of-bounds in dbFindLeaf (2)

syzbot New syzbot 2 participants 7 messages Jan 8 – Sep 17 JFS filesystem

lore
Share & tools
lore

syzbot

author syzbot
#0 lore raw

Hello,

syzbot found the following issue on:

HEAD commit:    f0b9d8eb98df Merge tag 'nfsd-6.19-3' of git://git.kernel.o..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=130f7e9a580000
kernel config:  https://syzkaller.appspot.com/x/.config?x=1f2b6fe1fdf1a00b
dashboard link: https://syzkaller.appspot.com/bug?extid=1afe7ef2d0062e19eeb3
compiler:       Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=16e4ee9a580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=1491c922580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/cbc651b8fda7/disk-f0b9d8eb.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/c3b1f0bf4b6c/vmlinux-f0b9d8eb.xz
kernel image: https://storage.googleapis.com/syzbot-assets/e102a718f8b0/bzImage-f0b9d8eb.xz
mounted in repro: https://storage.googleapis.com/syzbot-assets/c8289184ec3d/mount_0.gz
fsck result: failed (log: https://syzkaller.appspot.com/x/fsck.log?x=12e4ee9a580000)

IMPORTANT: if you fix the issue, please add the following tag to the commit:

Reported-by [email protected]
------------[ cut here ]------------
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]')
CPU: 1 UID: 0 PID: 6059 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT_{RT,(full)} 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/25/2025
Call Trace:
 <TASK>
 dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
 ubsan_epilogue+0xa/0x40 lib/ubsan.c:233
 __ubsan_handle_out_of_bounds+0xe9/0xf0 lib/ubsan.c:455
 dbFindLeaf+0x308/0x520 fs/jfs/jfs_dmap.c:2976
 dbFindCtl+0x267/0x520 fs/jfs/jfs_dmap.c:1717
 dbAllocAny fs/jfs/jfs_dmap.c:1527 [inline]
 dbAlloc+0x5fa/0xba0 fs/jfs/jfs_dmap.c:878
 diNewIAG fs/jfs/jfs_imap.c:2510 [inline]
 diAllocExt fs/jfs/jfs_imap.c:1905 [inline]
 diAllocAG+0xd45/0x1df0 fs/jfs/jfs_imap.c:1669
 diAlloc+0x1d4/0x1670 fs/jfs/jfs_imap.c:1590
 ialloc+0x8c/0x8f0 fs/jfs/jfs_inode.c:56
 jfs_mkdir+0x193/0xa70 fs/jfs/namei.c:225
 vfs_mkdir+0x52d/0x5d0 fs/namei.c:5130
 do_mkdirat+0x27a/0x4b0 fs/namei.c:5164
 __do_sys_mkdirat fs/namei.c:5186 [inline]
 __se_sys_mkdirat fs/namei.c:5184 [inline]
 __x64_sys_mkdirat+0x87/0xa0 fs/namei.c:5184
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xec/0xf80 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7efe6c5ade97
Code: 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 b8 02 01 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007efe6bbf4e68 EFLAGS: 00000246 ORIG_RAX: 0000000000000102
RAX: ffffffffffffffda RBX: 00007efe6bbf4ef0 RCX: 00007efe6c5ade97
RDX: 00000000000001ff RSI: 00002000000002c0 RDI: 00000000ffffff9c
RBP: 0000200000000200 R08: 00002000000000c0 R09: 0000000000000000
R10: 0000200000000200 R11: 0000000000000246 R12: 00002000000002c0
R13: 00007efe6bbf4eb0 R14: 0000000000000000 R15: 0000000000000000
 </TASK>
---[ end trace ]---

---
This report is generated by a bot. It may contain errors. See https://goo.gl/tpsmEJ for more information about syzbot. syzbot engineers can be reached at [email protected].

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

#1 lore raw

PATCH 1/1 jfs: fix oob in dbFindLeaf

The initial value of x is ti, and there is a potential risk that the value of ti might equal max_size. The existing boundary checks have been improved to prevent the out-of-bounds (OOB) issue [1] reported by syzbot.

[1]

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]')
Call Trace:
 dbFindLeaf+0x308/0x520 fs/jfs/jfs_dmap.c:2976
 dbFindCtl+0x267/0x520 fs/jfs/jfs_dmap.c:1717
 dbAllocAny fs/jfs/jfs_dmap.c:1527 [inline]
---
 fs/jfs/jfs_dmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dmap.c +1 -1
index cdfa699cd7c8..18a7dc58f289 100644
@@ -2971,7 +2971,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;
Signature · 1 line
2.43.0
author syzbot
#2 lore raw

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

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected], [email protected].

For archival purposes, forwarding an incoming command email to [email protected], [email protected].

***

Subject: [PATCH] jfs: fix off-by-one in dbFindLeaf tree bounds check
Author: [email protected]

From: Tristan Madani <[email protected]>

#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 [email protected]
Fixes 22cad8bc1d36 ("jfs: fix array-index-out-of-bounds in dbFindLeaf")
---
 fs/jfs/jfs_dmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dmap.c +1 -1
index XXXXXXX..XXXXXXX 100644
@@ -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

author syzbot
#3 lore raw

Forwarded: Re: [syzbot] UBSAN: array-index-out-of-bounds in dbFindLeaf

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected], [email protected].

For archival purposes, forwarding an incoming command email to [email protected], [email protected].

***

Subject: Re: [syzbot] UBSAN: array-index-out-of-bounds in dbFindLeaf
Author: [email protected]

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

Quoted 1 line

From 9fdbd0cb4943449d1104e60ec721d8dbe92a56ff Mon Sep 17 00:00:00 2001

From: Tristan Madani <[email protected]>
Date: Fri, 17 Apr 2026 16:15:14 +0000
Subject: [PATCH] jfs: fix array-index-out-of-bounds in dbFindLeaf dbFindLeaf() uses an off-by-one comparison when checking array
bounds: if (x + n > max_size) should be >= max_size since array indices are 0-based and max_size is the total element count. When x + n equals max_size, the access tp->dmt_stree[x + n] reads one element past the end of the array.
Fix by using >= instead of > in the bounds check.

---
 fs/jfs/jfs_dmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/jfs/jfs_dmap.c +1 -1
index a841cf2..cbdcc8d 100644
@@ -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;
Signature · 1 line
2.47.3
author syzbot
#4 lore raw

Forwarded: [PATCH] UBSAN: array-index-out-of-bounds in dbFindLeaf (2)

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected].

For archival purposes, forwarding an incoming command email to [email protected].

***

Subject: [PATCH] UBSAN: array-index-out-of-bounds in dbFindLeaf (2)
Author: [email protected]

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

Reported-by [email protected]
fs/jfs/jfs_dmap.c +5 -1
index cdfa699cd..53642b1ec 100644
@@ -2971,7 +2971,11 @@ 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)
+			/* stree[] holds max_size entries, so max_size is
+			 * already one past the last valid index.  Use >=
+			 * to reject it and avoid an out-of-bounds read.
+			 */
+			if (x + n >= max_size)
 				return -ENOSPC;
 			if (l2nb <= tp->dmt_stree[x + n])
 				break;
author syzbot
#5 lore raw

Forwarded: [PATCH] UBSAN: array-index-out-of-bounds in dbFindLeaf (2)

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected].

For archival purposes, forwarding an incoming command email to [email protected].

***

Subject: [PATCH] UBSAN: array-index-out-of-bounds in dbFindLeaf (2)
Author: [email protected]

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

Reported-by [email protected]
fs/jfs/jfs_dmap.c +5 -1
index cdfa699cd..53642b1ec 100644
@@ -2971,7 +2971,11 @@ 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)
+			/* stree[] holds max_size entries, so max_size is
+			 * already one past the last valid index.  Use >=
+			 * to reject it and avoid an out-of-bounds read.
+			 */
+			if (x + n >= max_size)
 				return -ENOSPC;
 			if (l2nb <= tp->dmt_stree[x + n])
 				break;
author syzbot
#6 lore raw

Forwarded: [PATCH] UBSAN: array-index-out-of-bounds in dbFindLeaf (2)

In reply to syzbot
For archival purposes, forwarding an incoming command email to [email protected].

For archival purposes, forwarding an incoming command email to [email protected].

***

Subject: [PATCH] UBSAN: array-index-out-of-bounds in dbFindLeaf (2)
Author: [email protected]

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

Reported-by [email protected]
fs/jfs/jfs_dmap.c +7 -1
index cdfa699cd..0edb70b01 100644
@@ -2971,7 +2971,13 @@ 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)
+			/* max_size is the number of elements in the
+			 * stree array, so the last valid index is
+			 * max_size - 1.  Use >= to reject a corrupted
+			 * tree height that would otherwise push the
+			 * index one past the end of the array.
+			 */
+			if (x + n >= max_size)
 				return -ENOSPC;
 			if (l2nb <= tp->dmt_stree[x + n])
 				break;