mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [BUG] ext4: NULL pointer dereference in jbd2_journal_file_inode() during inline data conversion
@ 2026-11-15  0:43 Ahmed Khan
  2026-11-16 21:39 ` Theodore Tso
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmed Khan @ 2026-11-15  0:43 UTC (permalink / raw)
  To: tytso, adilger.kernel; +Cc: linux-ext4, linux-fsdevel, linux-kernel

Hi Theodore and Andreas,

My name is Ahmed Khan, I am a security researcher from Canada. I
believe I found a bug within the Linux Kernel, specifically, version
7.3.4 affecting all major distros. I will be candid and state that I
used AI heavily in fuzzing the kernel using "syzkaller". Below are its
findings, the proof of concept worked on my QEMU VM repeatedly.

I found and verified a deterministic NULL pointer dereference in
jbd2_journal_file_inode() triggered when expanding an inline_data ext4
file via path-based truncate() on a filesystem mounted in data=ordered
mode.

This corresponds to syzbot crash ID:
3eb9083d961b1b97587d103692546ba06797de4e

1. Root Cause Analysis
----------------------
In ext4, EXT4_I(inode)->jinode is lazily allocated via
ext4_inode_attach_jinode(). Normally this occurs during
ext4_file_open(), ext4_write_begin(), or late inside ext4_setattr().

When path-based truncate() is called on a file without opening a file
descriptor, the inode enters ext4_setattr() with EXT4_I(inode)->jinode
still NULL:

  /* fs/ext4/inode.c — ext4_setattr() */
  if (ext4_has_inline_data(inode) &&
      attr->ia_size > EXT4_I(inode)->i_inline_size) {
      error = ext4_convert_inline_data(inode); /* jinode is still NULL */
      if (error)
          goto err_out;
  }
  ...
  /* ext4_inode_attach_jinode() is only called later in ext4_setattr() */

During inline conversion, ext4_convert_inline_data_nolock() calls
ext4_map_blocks(..., EXT4_GET_BLOCKS_CREATE). When the inode also has
EXT4_INODE_EXTENTS set and the filesystem is mounted with data=ordered,
ext4_map_blocks() calls ext4_jbd2_inode_add_write(), passing
EXT4_I(inode)->jinode (NULL) directly to jbd2_journal_file_inode().

jbd2_journal_file_inode() then acquires journal->j_list_lock (with IRQs
disabled) and dereferences the NULL jinode pointer at offset 0x28/0x38,
causing a fatal Oops/GPF while holding the journal list lock.

2. Reproduction Steps
---------------------
1. Mount a crafted ext4 image in default data=ordered mode containing a
   regular file with both EXT4_INLINE_DATA_FL and EXT4_EXTENTS_FL set.
2. Without opening a file descriptor on the target file, invoke:
   truncate("./file3", 0x10001);

 * Proof of Concept: Linux Kernel ext4/jbd2 NULL Pointer Dereference
 *
 * Target Linux Kernel Versions:
 *   - Upstream Linux: 7.0 – 7.3.4+
 *   - Confirmed Distro Kernels (6/6 Tested Distros Crashed):
 *       * Ubuntu 26.04.1 LTS (Linux 7.0.0-38-generic #38-Ubuntu)
 *       * Ubuntu 26.10       (Linux 7.3.0-10-generic #10-Ubuntu)
 *       * Fedora Cloud 45    (Linux 7.2.11-300.fc45.x86_64)
 *       * Debian Sid / Forky (Linux 7.2.15+deb14-cloud-amd64)
 *       * Arch Linux         (Linux 7.2.11-arch1-1)
 *       * openSUSE Tumbleweed (Linux 7.3.3-1-default)
 *       * Upstream Base / CachyOS (Linux 7.3.4 SMP KASAN)
 *
 * Vulnerability Summary:
 *   Triggered via truncate("./file3", 0x10001) on a crafted ext4 filesystem
 *   where the target inode has both EXT4_INLINE_DATA_FL and
EXT4_EXTENTS_FL set.
 *   ext4_setattr() calls ext4_convert_inline_data() before attaching a jinode,
 *   causing ext4_jbd2_inode_add_write() to pass jinode == NULL into
 *   jbd2_journal_file_inode(), causing an immediate NULL pointer
dereference (GPF)
 *   while holding journal->j_list_lock with interrupts disabled.
 *
 * Crash Signature:
 *   Oops: general protection fault, address: 0x0000000000000028 (or 0x38)
 *   RIP: 0010:jbd2_journal_file_inode+0x14b/0x5b0
 *   note: poc1 exited with irqs disabled / preempt_count 1
 *
 * Compilation:
 *   gcc -O2 -o poc1 poc1_ext4_jbd2_nullderef.c
 *   Prerequisite: ensure /dev/loop0 exists (modprobe loop && losetup -f)
 *
 * Originally autogenerated by syzkaller (https://github.com/google/syzkaller)

3. Crash Log (KASAN)
--------------------
[   18.161021] Oops: general protection fault, probably for
non-canonical address
  0xdffffc0000000005: 0000 [#1] SMP KASAN NOPTI
[   18.162724] RIP: 0010:jbd2_journal_file_inode+0x14b/0x5b0
[   18.163481] Code: 48 c1 e8 03 42 80 3c 30 00 74 08 4c 89 e7 e8 4a
41 8c ff 49 8b 44 24 28 ...
[   18.170125] Call Trace:
[   18.170410]  <TASK>
[   18.170685]  ext4_jbd2_inode_add_write+0x138/0x1e0
[   18.171220]  ext4_map_blocks+0x1102/0x1b40
[   18.171691]  ext4_convert_inline_data_nolock+0x18e/0x450
[   18.172281]  ext4_convert_inline_data+0x17c/0x250
[   18.172780]  ext4_setattr+0xa2c/0x1ea0
[   18.173200]  notify_change+0x628/0xd60
[   18.173620]  do_truncate+0x144/0x230
[   18.174020]  do_sys_truncate+0x17e/0x200
[   18.174450]  ksys_truncate+0x2c/0x40
[   18.174820]  do_syscall_64+0x10e/0x5e0
[   18.176450]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[   18.178920] note: poc1[318] exited with irqs disabled / preempt_count

4. Suggested Fix Direction
--------------------------
Calling ext4_inode_attach_jinode(inode) inside ext4_convert_inline_data()
(or prior to calling ext4_convert_inline_data() in ext4_setattr())
ensures jinode is allocated before ext4_map_blocks() attempts to add
the inode to the journal's ordered data list.

Please let me know if you would like the standalone C reproducer or
the minimal ext4 disk image attached inline. I have this in a private
repo and would be happy to add you as a project contributor.

Best regards,
Ahmed Khan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16 21:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15  0:43 [BUG] ext4: NULL pointer dereference in jbd2_journal_file_inode() during inline data conversion Ahmed Khan
2026-11-16 21:39 ` Theodore Tso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®