UBSAN: array-index-out-of-bounds in dtDelete

Status: upstream: reported C repro on 2025/03/18 19:54
Subsystems: jfs
Labels: prio:high
[Documentation on labels]
Reported-by: syzbot+4f9c823a6f63d87491ba@syzkaller.appspotmail.com
First crash: 632d, last: 264d
✨ AI-generated root cause summary:

In dtDelete() (fs/jfs/jfs_dtree.c), when deleting the last entry of a non-root leaf page with DO_INDEX(ip) enabled and p->header.next != 0, the kernel loads the next sibling leaf page np via DT_GETPAGE() and immediately accesses np->slot[stbl[0]] to read ldtentry->index. However, DT_GETPAGE() only validates nextindex <= maxslot and maxslot <= DTPAGEMAXSLOT (128), without checking np->header.nextindex > 0, np->header.stblindex, !(np->header.flag & BT_ROOT), or that stbl entries lie within [0, 127]. Moreover, dtDelete() declares stbl as u8 * and performs no bounds check before indexing np->slot[stbl[0]]. On a corrupted JFS image where stbl[0] is 240 (0xf0), this triggers an out-of-bounds read past the 128-slot dtpage_t (struct dtslot slot[128]).

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit e3a854b577cb:

Root Cause Analysis

The UBSAN array-index-out-of-bounds failure occurs in dtDelete() (fs/jfs/jfs_dtree.c:2132) during jfs_rename() (fs/jfs/namei.c:1239) when deleting a directory entry from a corrupted JFS directory B+-tree.

Involved Functions, Structs, and Fields

  • jfs_rename() (fs/jfs/namei.c:1239): Calls dtDelete(tid, old_dir, &old_dname, &ino, JFS_REMOVE) to remove the old directory entry after inserting/updating the target entry.
  • dtDelete() (fs/jfs/jfs_dtree.c:2077-2145):
    • Declares u8 *stbl; (fs/jfs/jfs_dtree.c:2091), even though DT_GETSTBL() (fs/jfs/jfs_dtree.h:221) returns s8 *.
    • When DO_INDEX(ip) is enabled and the entry being deleted is the last entry on the current leaf page (index == (p->header.nextindex - 1)), and p is neither the root page nor the rightmost leaf page (!(p->header.flag & BT_ROOT) && p->header.next != 0), dtDelete() needs the directory index of the first entry on the next sibling leaf page to pass as next_index to free_index(tid, ip, table_index, next_index).
    • It loads the next sibling page np at le64_to_cpu(p->header.next) via DT_GETPAGE(ip, le64_to_cpu(p->header.next), nmp, PSIZE, np, rc) (fs/jfs/jfs_dtree.c:2125) and then executes (fs/jfs/jfs_dtree.c:2130-2135):
      stbl = DT_GETSTBL(np);
      ldtentry = (struct ldtentry *) & np->slot[stbl[0]];
      next_index = le32_to_cpu(ldtentry->index);
      
  • dtpage_t (fs/jfs/jfs_dtree.h:180-198): A 4096-byte directory page defined as a union of header and struct dtslot slot[128] (DTPAGEMAXSLOT == 128, each dtslot / ldtentry is 32 bytes).
  • DT_GETPAGE() (fs/jfs/jfs_dtree.c:114-128): Only checks that header.nextindex <= header.maxslot (or DTROOTMAXSLOT for root) and header.maxslot <= DTPAGEMAXSLOT.

Trigger Mechanism and Violated Invariants

  1. Insufficient validation in DT_GETPAGE(): When reading np from le64_to_cpu(p->header.next), DT_GETPAGE() does not verify:
    • np->header.nextindex > 0 (if nextindex == 0, stbl[0] does not correspond to a valid entry);
    • np->header.stblindex is within valid slot bounds (< np->header.maxslot / < DTPAGEMAXSLOT) and !(np->header.flag & BT_ROOT) for bn != 0 (otherwise DT_GETSTBL(np) can point out of bounds or misinterpret the page header as a dtroot_t);
    • np->header.flag & BT_LEAF.
  2. Missing stbl bounds validation in dtDelete(): Unlike jfs_readdir() (fs/jfs/jfs_dtree.c:2894) and dtReadFirst() (fs/jfs/jfs_dtree.c:3098), which check stbl[i] < 0 || stbl[i] > 127 before indexing p->slot[], dtDelete() neither validates np->header.nextindex > 0 / np->header.stblindex nor checks that stbl[0] is within [0, DTPAGEMAXSLOT - 1] (or < np->header.maxslot). Because stbl is typed as u8 *, an invalid signed slot index (e.g., -16 / 0xf0) or corrupt/uninitialized byte in stbl[0] evaluates to 240.
  3. Out-of-bounds access: Indexing np->slot[240] exceeds struct dtslot slot[128], triggering the UBSAN array-index-out-of-bounds report at fs/jfs/jfs_dtree.c:2132 and reading ldtentry->index out of bounds past the 4 KB dtpage_t metapage. (Note that dtDelete() also indexes p->slot[stbl[index + 1]] at line 2141 without checking stbl[index + 1].)
▶ ▼ ✨ AI Jobs (11)
ID Workflow Result Correct Bug Created Started Finished Revision
54ea0445 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ✅ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ UBSAN: array-index-out-of-bounds in dtDelete 2026/12/05 18:19 2026/12/05 18:19 2026/12/05 18:48 3a4d724d
dc567619 assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/11/05 03:31 2026/11/05 03:31 2026/11/05 04:06 73438ed0
79d83162 assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/10/05 03:54 2026/10/05 03:54 2026/10/05 04:30 57bbd979
e783285d assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/09/04 03:16 2026/09/04 03:16 2026/09/04 03:43 d2e5fb95
4487b55d assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/08/05 00:02 2026/08/05 00:02 2026/08/05 00:02 d4abbeac
d1b3f03d assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/07/05 03:41 2026/07/05 03:41 2026/07/05 04:10 93f57954
af7107df assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/06/18 03:07 2026/06/18 03:07 2026/06/18 03:36 b62b3ded
bb71c57d assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/06/09 23:19 2026/06/09 23:19 2026/06/09 23:47 c36c07f6
a456529c assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/06/04 01:05 2026/06/04 01:05 2026/06/04 01:25 62fe1528
5c9073d6 assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/06/01 08:23 2026/06/01 08:23 2026/06/01 08:57 6b4a8443
07139ebd assessment-security 💥 UBSAN: array-index-out-of-bounds in dtDelete 2026/05/15 10:47 2026/05/15 10:47 2026/05/15 10:48 9cd3beaa
▶ ▼ Discussions (4)
Title Replies (including bot) Last reply
[PATCH] jfs: Add check for array bounds in dtDelete 1 (1) 2025/09/19 22:50
[syzbot] [jfs?] UBSAN: array-index-out-of-bounds in dtDelete 0 (3) 2025/09/19 15:23
[PATCH] jfs: Add check for array bounds in dtDelete 1 (2) 2025/09/18 21:27
Re: [syzbot] [jfs?] UBSAN: array-index-out-of-bounds in dtDelete 1 (2) 2025/03/19 02:43
▶ ▼ Last patch testing requests (13)
Created Duration User Patch Repo Result
2026/10/13 02:42 16m retest repro upstream report job log log
2026/08/04 02:15 21m retest repro upstream error
2026/05/26 00:51 23m retest repro upstream log
2026/03/16 23:51 19m retest repro upstream report log
2026/01/05 23:21 14m retest repro upstream report log
2025/10/27 22:44 8m retest repro upstream report log
2025/09/19 15:23 20m pedrodemargomes@gmail.com patch upstream OK log
2025/09/18 21:11 14m pedrodemargomes@gmail.com patch upstream report log
2025/08/18 22:25 15m retest repro upstream report log
2025/06/09 21:58 17m retest repro upstream report log
2025/04/18 03:25 21m richard120310@gmail.com patch git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git e3a854b577cb report log
2025/03/28 21:57 16m retest repro upstream report log
2025/03/19 02:26 16m leo.fthirata@gmail.com patch upstream report log

Sample crash report:
loop0: detected capacity change from 0 to 32768
------------[ cut here ]------------
UBSAN: array-index-out-of-bounds in fs/jfs/jfs_dtree.c:2132:32
index 240 is out of range for type 'struct dtslot[128]'
CPU: 0 UID: 0 PID: 5303 Comm: syz-executor483 Not tainted 6.14.0-rc6-syzkaller-00115-ge3a854b577cb #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
 ubsan_epilogue lib/ubsan.c:231 [inline]
 __ubsan_handle_out_of_bounds+0x121/0x150 lib/ubsan.c:429
 dtDelete+0x2d67/0x2db0 fs/jfs/jfs_dtree.c:2132
 jfs_rename+0xf91/0x1bf0 fs/jfs/namei.c:1239
 vfs_rename+0xbdb/0xf00 fs/namei.c:5069
 do_renameat2+0xd94/0x13f0 fs/namei.c:5226
 __do_sys_rename fs/namei.c:5273 [inline]
 __se_sys_rename fs/namei.c:5271 [inline]
 __x64_sys_rename+0x82/0x90 fs/namei.c:5271
 do_syscall_x64 arch/x86/entry/common.c:52 [inline]
 do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fc873bc9bb9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 61 17 00 00 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fff24dc46e8 EFLAGS: 00000246 ORIG_RAX: 0000000000000052
RAX: ffffffffffffffda RBX: 0000400000000e00 RCX: 00007fc873bc9bb9
RDX: 00007fc873bc9bb9 RSI: 0000400000000f40 RDI: 0000400000000300
RBP: 00007fc873c42610 R08: 00007fff24dc48b8 R09: 00007fff24dc48b8
R10: 00007fff24dc48b8 R11: 0000000000000246 R12: 0000000000000001
R13: 00007fff24dc48a8 R14: 0000000000000001 R15: 0000000000000001
 </TASK>
---[ end trace ]---

Crashes (5):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2025/03/14 21:42 upstream e3a854b577cb e2826670 .config console log report syz / log C [disk image (non-bootable)] [vmlinux] [kernel image] [mounted in repro (corrupt fs)] ci-snapshot-upstream-root UBSAN: array-index-out-of-bounds in dtDelete
2025/11/20 21:16 upstream 8e621c9a3375 2cc4c24a .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root UBSAN: array-index-out-of-bounds in dtDelete
2025/05/26 21:41 upstream 0ff41df1cb26 06877188 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root UBSAN: array-index-out-of-bounds in dtDelete
2025/04/21 01:39 upstream 6fea5fabd332 2a20f901 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root UBSAN: array-index-out-of-bounds in dtDelete
2025/03/14 19:51 upstream e3a854b577cb e2826670 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root UBSAN: array-index-out-of-bounds in dtDelete
* Struck through repros no longer work on HEAD.