Linux EXT4 FS development
 help / color / mirror / Atom feed
* [Bug 222294] New: [REGRESSION] 6.1.191+: NULL deref in ext4_mb_load_buddy_gfp() after a3a7d360252c ("ext4: fix e4b bitmap inconsistency reports")
@ 2026-11-19  9:51 bugzilla-daemon
  2026-11-19  9:53 ` [Bug 222294] " bugzilla-daemon
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bugzilla-daemon @ 2026-11-19  9:51 UTC (permalink / raw)
  To: linux-ext4

https://bugzilla.kernel.org/show_bug.cgi?id=222294

            Bug ID: 222294
           Summary: [REGRESSION] 6.1.191+: NULL deref in
                    ext4_mb_load_buddy_gfp() after a3a7d360252c ("ext4:
                    fix e4b bitmap inconsistency reports")
           Product: File System
           Version: 2.5
          Hardware: Intel
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P3
         Component: ext4
          Assignee: fs_ext4@kernel-bugs.osdl.org
          Reporter: internet.jejkowice@gmail.com
        Regression: No

Created attachment 311518
  --> https://bugzilla.kernel.org/attachment.cgi?id=311518&action=edit
patch

Regression in the 6.1.y stable series, introduced in 6.1.191 and still
present in 6.1.192. 6.1.190 is fine.

REPRODUCER (100% on 6.1.191/6.1.192, 0% on 6.1.190):

    sync; echo 1 > /proc/sys/vm/drop_caches

The machine oopses immediately (kernel.panic_on_oops=1, so it reboots).
Without manual action it also hit during a nightly cron job (rsync doing
unlink()/rename() on an ext4 volume) at 04:45, after the page cache had
been churned by earlier I/O.

SYSTEM
Dell PowerEdge R820, BIOS 2.7.0, x86_64, 40 CPUs, CONFIG_PREEMPT,
ext4 on megaraid_sas. Self-built kernel from kernel.org tarballs.
Tainted (O): out-of-tree vboxdrv/vboxnetflt/vboxnetadp and xt_IPMARK,
none of which appear in the traces.
<.config attached / available on request>

FIRST OOPS (rsync, unlink path)

  Oops: 0000 [#1] PREEMPT SMP
  CPU: 15 PID: 73107 Comm: rsync Tainted: G O 6.1.192 #1
  RIP: 0010:ext4_mb_load_buddy_gfp+0xbc/0x390 [ext4]
  Code: ... 49 89 c7 48 3d 00 f0 ff ff 0f 87 3a 01 00 00 <48> 8b 00 a8 04
        0f 84 24 01 00 00 ...
  RAX: 0000000000000000 RBX: 00000000000003e4 ...
  CR2: 0000000000000000
  Call Trace:
   ext4_free_blocks+0x3a7/0xb30 [ext4]
   ext4_ext_remove_space+0x80f/0x1570 [ext4]
   ext4_ext_truncate+0xb4/0xc0 [ext4]
   ext4_truncate+0x310/0x480 [ext4]
   ext4_evict_inode+0x308/0x720 [ext4]
   evict+0x103/0x2b0
   do_unlinkat+0x143/0x2f0
   __x64_sys_unlink+0x3e/0x60
   do_syscall_64+0x35/0x90

A second rsync hit the same RIP via the allocation path
(ext4_mb_regular_allocator <- ext4_mb_new_blocks <- ext4_ext_map_blocks <-
ext4_writepages <- ext4_rename), for a different group (0x3fa vs 0x3e4).
Everything after that was fallout: BSD process accounting writes from
do_exit() into the already-broken ext4 led to further oopses, a dead
mutex waiter on a freed stack, and finally soft lockups on the
acct mutex's wait_lock until the box was reset.

CAUSE
Diffing 6.1.190 -> 6.1.191, the regression comes from
  a3a7d360252c ("ext4: fix e4b bitmap inconsistency reports")
  [upstream bdc56a9c46b2]
preceded in the same release by the preparatory commits
  e394adafb089, e6b6cbe9f2fb, 1c0f0e2b9b69
which are not themselves the cause.

The patch converts ext4_mb_load_buddy_gfp() and
ext4_mb_get_buddy_page_lock() to __filemap_get_folio() and checks the
result with IS_ERR() only. In 6.1.y, __filemap_get_folio() never returns
ERR_PTR() (mm/filemap.c, no ERR_PTR anywhere in the function). It returns
NULL when:
 - the lookup misses and FGP_CREAT is not set (falls through no_page to
   the final "return folio;" with folio == NULL),
 - FGP_NOWAIT and folio_trylock() fails,
 - filemap_alloc_folio() fails,
 - filemap_add_folio() fails (folio = NULL).

So in the fast path
    folio = __filemap_get_folio(mapping, pnum, FGP_ACCESSED, 0);
    if (IS_ERR(folio) || !folio_test_uptodate(folio) || ...)
a cache miss reaches folio_test_uptodate(NULL) and dereferences address 0.
This matches the oops: "cmp $0xfffff000,%rax; ja" is IS_ERR(), followed
by "mov (%rax),%rax; test $4,%al" (folio->flags, PG_uptodate) with
RAX = 0, CR2 = 0. The FGP_CREAT slow path has the same flaw
(PTR_ERR(NULL) == 0, so ret = 0 and the NULL folio is used), as does
ext4_mb_get_buddy_page_lock() (folio->mapping on NULL).

Upstream (>= v6.3) returns ERR_PTR from __filemap_get_folio(), so only
stable branches that received this backport without adapting it are
affected. 5.15.y and 5.10.y may be affected too if they got the same
backport; I have not checked.

WORKAROUND / FIX
Wrapper that maps NULL to ERR_PTR(-ENOMEM), used for all six
__filemap_get_folio() calls in fs/ext4/mballoc.c:

    static struct folio *ext4_mb_get_folio(struct address_space *mapping,
                    pgoff_t index, int fgp, gfp_t gfp)
    {
            struct folio *folio = __filemap_get_folio(mapping, index, fgp,
gfp);

            return folio ? folio : ERR_PTR(-ENOMEM);
    }

With this applied on 6.1.192, 4x "echo 1" and 7x "echo 3" to drop_caches
no longer crash (previously a single "echo 1" did).
<Result of cron.daily rsync after drop_caches with the patch: ...>
Patch attached; also sent to stable@vger.kernel.org and
linux-ext4@vger.kernel.org: <lore.kernel.org link>

Reverting a3a7d360252c is the other option.

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

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

* [Bug 222294] [REGRESSION] 6.1.191+: NULL deref in ext4_mb_load_buddy_gfp() after a3a7d360252c ("ext4: fix e4b bitmap inconsistency reports")
  2026-11-19  9:51 [Bug 222294] New: [REGRESSION] 6.1.191+: NULL deref in ext4_mb_load_buddy_gfp() after a3a7d360252c ("ext4: fix e4b bitmap inconsistency reports") bugzilla-daemon
@ 2026-11-19  9:53 ` bugzilla-daemon
  2026-11-19 10:06 ` bugzilla-daemon
  2026-11-19 10:13 ` bugzilla-daemon
  2 siblings, 0 replies; 4+ messages in thread
From: bugzilla-daemon @ 2026-11-19  9:53 UTC (permalink / raw)
  To: linux-ext4

https://bugzilla.kernel.org/show_bug.cgi?id=222294

--- Comment #1 from Dawid Partyka (internet.jejkowice@gmail.com) ---
Created attachment 311519
  --> https://bugzilla.kernel.org/attachment.cgi?id=311519&action=edit
.config

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

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

* [Bug 222294] [REGRESSION] 6.1.191+: NULL deref in ext4_mb_load_buddy_gfp() after a3a7d360252c ("ext4: fix e4b bitmap inconsistency reports")
  2026-11-19  9:51 [Bug 222294] New: [REGRESSION] 6.1.191+: NULL deref in ext4_mb_load_buddy_gfp() after a3a7d360252c ("ext4: fix e4b bitmap inconsistency reports") bugzilla-daemon
  2026-11-19  9:53 ` [Bug 222294] " bugzilla-daemon
@ 2026-11-19 10:06 ` bugzilla-daemon
  2026-11-19 10:13 ` bugzilla-daemon
  2 siblings, 0 replies; 4+ messages in thread
From: bugzilla-daemon @ 2026-11-19 10:06 UTC (permalink / raw)
  To: linux-ext4

https://bugzilla.kernel.org/show_bug.cgi?id=222294

Dawid Partyka (internet.jejkowice@gmail.com) changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Regression|No                          |Yes
 Bisected commit-id|                            |a3a7d360252c0d84ae8bda067fb
                   |                            |296c9e82928d3
     Kernel Version|                            |6.1.192

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

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

* [Bug 222294] [REGRESSION] 6.1.191+: NULL deref in ext4_mb_load_buddy_gfp() after a3a7d360252c ("ext4: fix e4b bitmap inconsistency reports")
  2026-11-19  9:51 [Bug 222294] New: [REGRESSION] 6.1.191+: NULL deref in ext4_mb_load_buddy_gfp() after a3a7d360252c ("ext4: fix e4b bitmap inconsistency reports") bugzilla-daemon
  2026-11-19  9:53 ` [Bug 222294] " bugzilla-daemon
  2026-11-19 10:06 ` bugzilla-daemon
@ 2026-11-19 10:13 ` bugzilla-daemon
  2 siblings, 0 replies; 4+ messages in thread
From: bugzilla-daemon @ 2026-11-19 10:13 UTC (permalink / raw)
  To: linux-ext4

https://bugzilla.kernel.org/show_bug.cgi?id=222294

--- Comment #2 from Dawid Partyka (internet.jejkowice@gmail.com) ---
Created attachment 311520
  --> https://bugzilla.kernel.org/attachment.cgi?id=311520&action=edit
log

-- 
You are receiving this mail because:
You are watching the assignee of the bug.

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

end of thread, other threads:[~2026-11-19 10:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  9:51 [Bug 222294] New: [REGRESSION] 6.1.191+: NULL deref in ext4_mb_load_buddy_gfp() after a3a7d360252c ("ext4: fix e4b bitmap inconsistency reports") bugzilla-daemon
2026-11-19  9:53 ` [Bug 222294] " bugzilla-daemon
2026-11-19 10:06 ` bugzilla-daemon
2026-11-19 10:13 ` bugzilla-daemon

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