KASAN: use-after-free Read in ocfs2_search_dirblock

Status: upstream: reported C repro on 2024/08/16 09:49
Subsystems: ocfs2
Labels: prio:high
[Documentation on labels]
Reported-by: syzbot+b9704899e166798d57c9@syzkaller.appspotmail.com
Fix commit: ocfs2: fix directory entry check in ocfs2_search_dirblock()
Patched on: [ci-upstream-linux-next-kasan-gce-root], missing on: [ci-qemu-gce-upstream-auto ci-qemu-native-arm64-kvm ci-qemu-upstream ci-qemu-upstream-386 ci-qemu2-arm32 ci-qemu2-arm64 ci-qemu2-arm64-compat ci-qemu2-arm64-mte ci-qemu2-riscv64 ci-snapshot-upstream-root ci-upstream-bpf-kasan-gce ci-upstream-bpf-next-kasan-gce ci-upstream-gce-arm64 ci-upstream-gce-leak ci-upstream-kasan-badwrites-root ci-upstream-kasan-gce ci-upstream-kasan-gce-386 ci-upstream-kasan-gce-root ci-upstream-kasan-gce-selinux-root ci-upstream-kasan-gce-smack-root ci-upstream-kmsan-gce-386-root ci-upstream-kmsan-gce-root ci-upstream-net-kasan-gce ci-upstream-net-this-kasan-gce ci-upstream-rust-kasan-gce ci2-upstream-fs ci2-upstream-kcsan-gce ci2-upstream-usb]
First crash: 823d, last: 676d
Cause bisection: the issue happens on the oldest tested release (bisect log)
Crash: KASAN: slab-out-of-bounds Read in ocfs2_find_entry (log)
Repro: C syz .config
  
✨ AI-generated root cause summary:

When mounting a corrupted OCFS2 filesystem image, a directory inode with the OCFS2_INLINE_DATA_FL dynamic feature can have an on-disk size (fe->i_size) larger than the maximum inline data capacity of the dinode block. Neither ocfs2_validate_inode_block()/ocfs2_populate_inode() nor ocfs2_find_entry_id() validates that i_size does not exceed the inline data limit. During directory lookup (ocfs2_lookup() -> ocfs2_find_entry_id()), ocfs2_search_dirblock() receives i_size_read(dir) as the search byte limit, causing dlimit to extend far beyond the buffer_head boundary (di_bh->b_data). As the search loop iterates using de->rec_len, it accesses memory beyond the buffer into an adjacent or freed page, triggering an out-of-bounds read reported by KASAN as use-after-free in ocfs2_match().

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

Root Cause Analysis

Involved Functions, Structs, and Files

  • Files: fs/ocfs2/dir.c, fs/ocfs2/inode.c, fs/ocfs2/ocfs2_fs.h
  • Functions: ocfs2_find_entry_id(), ocfs2_search_dirblock(), ocfs2_match(), ocfs2_populate_inode()
  • Structs & Fields:
    • struct ocfs2_dinode: fe->i_size, di->i_dyn_features, di->id2.i_data.id_data, di->id2.i_data.id_count
    • struct ocfs2_dir_entry: de->rec_len, de->name_len, de->inode, de->name
    • struct inode: dir->i_size (i_size_read(dir))

Mechanism of the Failure

  1. Inode Population and Missing Validation: In OCFS2, files or directories can have inline data embedded directly within their inode block buffer (di_bh->b_data) at di->id2.i_data.id_data when the dynamic feature flag OCFS2_INLINE_DATA_FL is set. The maximum possible inline data size is bounded by the block size minus the dinode structure header offset: $$\text{max_inline_data} = \text{sb->s_blocksize} - \text{offsetof}(\text{struct ocfs2_dinode}, \text{id2.i_data.id_data}) - \text{xattrsize}$$ (as computed by ocfs2_max_inline_data_with_xattr()).

    While regular file read paths (such as ocfs2_read_inline_data() in fs/ocfs2/aops.c) check whether i_size > ocfs2_max_inline_data_with_xattr(...), neither ocfs2_validate_inode_block() nor ocfs2_populate_inode() in fs/ocfs2/inode.c validates that fe->i_size of a directory inode with OCFS2_INLINE_DATA_FL fits within this limit.

  2. Triggering Directory Search (ocfs2_find_entry_id()): When looking up a path entry inside an inline directory (ocfs2_lookup() $\to$ ocfs2_find_entry() $\to$ ocfs2_find_entry_id()), the kernel reads the inode block di_bh and passes the start of inline data and the inode size to ocfs2_search_dirblock():

    di = (struct ocfs2_dinode *)di_bh->b_data;
    data = &di->id2.i_data;
    
    found = ocfs2_search_dirblock(di_bh, dir, name, namelen, 0,
                                  data->id_data, i_size_read(dir), res_dir);
    
  3. Out-of-Bounds Traversal in ocfs2_search_dirblock(): In ocfs2_search_dirblock(), the search limit is calculated as:

    de_buf = first_de;
    dlimit = de_buf + bytes;  /* bytes == i_size_read(dir) */
    

    Because bytes is taken directly from the unvalidated i_size, dlimit extends far beyond the bounds of the di_bh->b_data block (typically a single buffer/page).

    As the loop iterates:

    while (de_buf < dlimit - OCFS2_DIR_MEMBER_LEN) {
        de = (struct ocfs2_dir_entry *) de_buf;
        if (de->name + namelen <= dlimit &&
            ocfs2_match(namelen, name, de)) {
            ...
        }
        de_len = le16_to_cpu(de->rec_len);
        if (de_len <= 0) ...
        de_buf += de_len;
    }
    

    For non-matching entries, ocfs2_check_dir_entry() is intentionally skipped for performance ("minimal checking by hand"). When de_buf advances past the allocated di_bh buffer, it walks off the end of the page and enters adjacent physical memory in the kernel direct mapping.

  4. Crash Manifestation: When the out-of-bounds pointer de_buf enters an adjacent physical page that is marked as freed in the page allocator, accessing de->name_len inside inline ocfs2_match():

    if (len != de->name_len)
        return 0;
    

    triggers a KASAN use-after-free report (or an unhandled kernel paging request if an unmapped page boundary is crossed).

▶ ▼ ✨ AI Jobs (10)
ID Workflow Result Correct Bug Created Started Finished Revision
3a372562 assessment-security DenialOfService: ✅ Exploitable: ❌ FilesystemTrigger: ✅ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KASAN: use-after-free Read in ocfs2_search_dirblock 2026/11/09 04:45 2026/11/09 04:45 2026/11/09 05:12 5cecaf1f
9a3f0f59 assessment-security 💥 KASAN: use-after-free Read in ocfs2_search_dirblock 2026/10/09 03:38 2026/10/09 03:38 2026/10/09 04:04 723be09b
ecc59882 assessment-security 💥 KASAN: use-after-free Read in ocfs2_search_dirblock 2026/09/09 03:19 2026/09/09 03:19 2026/09/09 03:40 243b72f1
e3a10749 assessment-security 💥 KASAN: use-after-free Read in ocfs2_search_dirblock 2026/08/09 20:57 2026/08/09 20:57 2026/08/09 21:11 5d63f80b
d6ff2f0d assessment-security 💥 KASAN: use-after-free Read in ocfs2_search_dirblock 2026/07/09 00:55 2026/07/09 00:55 2026/07/09 01:23 93f57954
9cd3c925 assessment-security 💥 KASAN: use-after-free Read in ocfs2_search_dirblock 2026/06/22 02:26 2026/06/22 02:26 2026/06/22 02:56 43bfcdb0
e9cec2b1 assessment-security 💥 KASAN: use-after-free Read in ocfs2_search_dirblock 2026/06/14 02:07 2026/06/14 02:07 2026/06/14 02:28 4f06757f
ab495be6 assessment-security 💥 KASAN: use-after-free Read in ocfs2_search_dirblock 2026/06/09 17:41 2026/06/09 17:41 2026/06/09 18:06 c36c07f6
2f27b215 assessment-security 💥 KASAN: use-after-free Read in ocfs2_search_dirblock 2026/06/02 14:39 2026/06/02 14:39 2026/06/02 15:08 62fe1528
130e2621 assessment-security 💥 KASAN: use-after-free Read in ocfs2_search_dirblock 2026/05/25 08:58 2026/05/25 08:58 2026/05/25 09:28 c69befb3
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [ocfs2?] KASAN: use-after-free Read in ocfs2_search_dirblock 0 (2) 2024/11/19 16:28
▶ ▼ Similar bugs (2)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-5.15 KASAN: use-after-free Read in ocfs2_search_dirblock 19 syz, C done 8 620d 650d 3/3 fixed on 2025/04/11 04:43
linux-6.1 KASAN: use-after-free Read in ocfs2_search_dirblock origin:lts-only 19 syz, C inconclusive 2 664d 664d 0/3 upstream: reported C repro on 2025/01/21 15:12
▶ ▼ Last patch testing requests (7)
Created Duration User Patch Repo Result
2024/11/19 16:28 19m dmantipov@yandex.ru patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 158f238aa69d91ad74e535c73f552bd4b025109c OK log
2024/11/08 07:51 13m retest repro upstream report log
2024/11/08 07:51 13m retest repro upstream report log
2024/11/08 07:51 13m retest repro upstream report log
2024/08/30 05:29 18m retest repro upstream report log
2024/08/30 05:29 18m retest repro upstream report log
2024/08/30 05:29 18m retest repro upstream report log

Sample crash report:
ocfs2: Mounting device (7,0) on (node local, slot 0) with ordered data mode.
==================================================================
BUG: KASAN: use-after-free in ocfs2_match fs/ocfs2/dir.c:334 [inline]
BUG: KASAN: use-after-free in ocfs2_search_dirblock+0x26b/0x820 fs/ocfs2/dir.c:367
Read of size 1 at addr ffff8880710858cb by task syz-executor292/5841

CPU: 0 UID: 0 PID: 5841 Comm: syz-executor292 Not tainted 6.12.0-syzkaller-10740-g509f806f7f70 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:378 [inline]
 print_report+0x169/0x550 mm/kasan/report.c:489
 kasan_report+0x143/0x180 mm/kasan/report.c:602
 ocfs2_match fs/ocfs2/dir.c:334 [inline]
 ocfs2_search_dirblock+0x26b/0x820 fs/ocfs2/dir.c:367
 ocfs2_find_entry_id fs/ocfs2/dir.c:414 [inline]
 ocfs2_find_entry+0x1169/0x2730 fs/ocfs2/dir.c:1078
 ocfs2_find_files_on_disk+0xff/0x360 fs/ocfs2/dir.c:1981
 ocfs2_lookup_ino_from_name+0xb1/0x1e0 fs/ocfs2/dir.c:2003
 ocfs2_lookup+0x292/0xa30 fs/ocfs2/namei.c:122
 lookup_open fs/namei.c:3627 [inline]
 open_last_lookups fs/namei.c:3748 [inline]
 path_openat+0x11a7/0x3590 fs/namei.c:3984
 do_filp_open+0x27f/0x4e0 fs/namei.c:4014
 do_sys_openat2+0x13e/0x1d0 fs/open.c:1402
 do_sys_open fs/open.c:1417 [inline]
 __do_sys_open fs/open.c:1425 [inline]
 __se_sys_open fs/open.c:1421 [inline]
 __x64_sys_open+0x225/0x270 fs/open.c:1421
 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:0x7f45aff47a59
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 b1 18 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f45afefe218 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 00007f45affd36a8 RCX: 00007f45aff47a59
RDX: 0000000000000000 RSI: 0000000400141042 RDI: 0000000020000080
RBP: 00007f45affd36a0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f45aff9c0c0
R13: 0000000400141042 R14: 00007f45aff9c200 R15: 0031656c69662f2e
 </TASK>

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x71085
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000000 ffffea0001c42188 ffffea0001c42108 0000000000000000
raw: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as freed
page last allocated via order 0, migratetype Movable, gfp_mask 0x8(__GFP_MOVABLE), pid 1, tgid 1 (swapper/0), ts 16694661071, free_ts 17832813418
 set_page_owner include/linux/page_owner.h:32 [inline]
 post_alloc_hook+0x1f3/0x230 mm/page_alloc.c:1556
 split_free_pages mm/page_alloc.c:6360 [inline]
 alloc_contig_range_noprof+0x821/0xe00 mm/page_alloc.c:6487
 __alloc_contig_pages mm/page_alloc.c:6516 [inline]
 alloc_contig_pages_noprof+0x4b3/0x5c0 mm/page_alloc.c:6596
 debug_vm_pgtable_alloc_huge_page+0xaf/0x100 mm/debug_vm_pgtable.c:1084
 init_args+0x83b/0xb20 mm/debug_vm_pgtable.c:1266
 debug_vm_pgtable+0xe0/0x550 mm/debug_vm_pgtable.c:1304
 do_one_initcall+0x248/0x870 init/main.c:1266
 do_initcall_level+0x157/0x210 init/main.c:1328
 do_initcalls+0x3f/0x80 init/main.c:1344
 kernel_init_freeable+0x435/0x5d0 init/main.c:1577
 kernel_init+0x1d/0x2b0 init/main.c:1466
 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
page last free pid 1 tgid 1 stack trace:
 reset_page_owner include/linux/page_owner.h:25 [inline]
 free_pages_prepare mm/page_alloc.c:1127 [inline]
 free_unref_page+0xde3/0x1130 mm/page_alloc.c:2657
 free_contig_range+0x152/0x550 mm/page_alloc.c:6630
 destroy_args+0x92/0x910 mm/debug_vm_pgtable.c:1017
 debug_vm_pgtable+0x4be/0x550 mm/debug_vm_pgtable.c:1397
 do_one_initcall+0x248/0x870 init/main.c:1266
 do_initcall_level+0x157/0x210 init/main.c:1328
 do_initcalls+0x3f/0x80 init/main.c:1344
 kernel_init_freeable+0x435/0x5d0 init/main.c:1577
 kernel_init+0x1d/0x2b0 init/main.c:1466
 ret_from_fork+0x4b/0x80 arch/x86/kernel/process.c:147
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244

Memory state around the buggy address:
 ffff888071085780: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff888071085800: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
>ffff888071085880: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
                                              ^
 ffff888071085900: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
 ffff888071085980: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
==================================================================

Crashes (14):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2024/11/30 02:20 upstream 509f806f7f70 68914665 .config strace log report syz / log C [disk image] [vmlinux] [kernel image] [mounted in repro] ci2-upstream-fs KASAN: use-after-free Read in ocfs2_search_dirblock
2024/08/16 03:58 upstream d7a5aa4b3c00 e4bacdaf .config console log report syz / log C [disk image (non-bootable)] [vmlinux] [kernel image] [mounted in repro] ci-snapshot-upstream-root KASAN: use-after-free Read in ocfs2_search_dirblock
2024/11/28 15:16 linux-next f486c8aa16b8 5df23865 .config strace log report syz / log C [disk image] [vmlinux] [kernel image] [mounted in repro] ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in ocfs2_search_dirblock
2024/08/16 05:29 upstream d7a5aa4b3c00 e4bacdaf .config console log report syz / log C [disk image (non-bootable)] [vmlinux] [kernel image] [mounted in repro] ci-snapshot-upstream-root KASAN: slab-out-of-bounds Read in ocfs2_search_dirblock
2024/08/16 04:45 upstream d7a5aa4b3c00 e4bacdaf .config console log report syz / log C [disk image (non-bootable)] [vmlinux] [kernel image] [mounted in repro] ci-snapshot-upstream-root KASAN: slab-out-of-bounds Read in ocfs2_search_dirblock
2025/01/09 20:06 upstream eea6e4b4dfb8 9220929f .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: use-after-free Read in ocfs2_search_dirblock
2024/12/01 03:52 upstream d8b78066f4c9 68914665 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: use-after-free Read in ocfs2_search_dirblock
2024/10/04 12:33 upstream 3840cbe24cf0 d7906eff .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: use-after-free Read in ocfs2_search_dirblock
2024/08/16 03:04 upstream d7a5aa4b3c00 e4bacdaf .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: use-after-free Read in ocfs2_search_dirblock
2024/11/28 14:27 linux-next f486c8aa16b8 5df23865 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-linux-next-kasan-gce-root KASAN: use-after-free Read in ocfs2_search_dirblock
2025/01/03 01:49 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 573067a5a685 d3ccff63 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 KASAN: use-after-free Read in ocfs2_search_dirblock
2024/12/28 03:37 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 573067a5a685 d3ccff63 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 KASAN: use-after-free Read in ocfs2_search_dirblock
2024/12/22 05:10 upstream 48f506ad0b68 d7f584ee .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: slab-use-after-free Read in ocfs2_search_dirblock
2024/12/20 19:49 upstream 8faabc041a00 49cfeac8 .config console log report [disk image (non-bootable)] [vmlinux] [kernel image] ci-snapshot-upstream-root KASAN: slab-out-of-bounds Read in ocfs2_search_dirblock
* Struck through repros no longer work on HEAD.