All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ivan Tiukov" <ivan@tiukov.com>, linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [BUG] ext4: NULL deref in ext4_mb_load_buddy_gfp() on 6.1.y
Date: Mon, 16 Nov 2026 09:36:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-216623@kernel.org> (raw)
In-Reply-To: <ef745013-2ea2-4e2d-86be-ac3e4a9d0cba@app.fastmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ext4: missing Signed-off-by trailer in commit message
- [Low] ext4: missing Fixes trailers in commit message
--

commit e1b11c11cdaa0a618daf0cfc52aa27557238d3df
Author: Ivan Tiukov <ivan@tiukov.com>

> ext4: NULL deref in ext4_mb_load_buddy_gfp() on 6.1.y
>
> Hello,
>
> Linux 6.1.y panics in ext4 under heavy unlink/truncate load. I believe this
> is a stable-only regression from the mballoc folio conversion in 6.1.191:
> the converted code assumes __filemap_get_folio() returns an ERR_PTR when it
> cannot hand out a folio, but 6.1.y still returns a plain NULL, so the NULL
> check that IS_ERR() is supposed to provide is not there.
>
> The crash reproduced three times on one host within eight hours; the trace
> below is from the third one, captured over netconsole because the machine
> went down before journald could persist anything.
>
> = Crash
> --------
>
> Kernel: 6.1.192-1 (Debian 6.1.0-55-amd64), x86_64, 4 vCPU KVM guest, 8 GB.
> Process: rpmsign, doing unlink() of large RPM files on ext4 root.
>
>   BUG: kernel NULL pointer dereference, address: 0000000000000000
>   #PF: supervisor read access in kernel mode
>   #PF: error_code(0x0000) - not-present page
>   PGD 0 P4D 0
>   Oops: 0000 [#1] PREEMPT SMP NOPTI
>   CPU: 3 PID: 12736 Comm: rpmsign Not tainted 6.1.0-55-amd64 #1 Debian 6.1.192-1
>   Hardware name: Red Hat KVM, BIOS 1.16.0-4.module_el8.9.0+3659+9c8643f3 04/01/2014
>   RIP: 0010:ext4_mb_load_buddy_gfp+0xbc/0x380 [ext4]
>   Code: 89 44 24 08 f7 3c 24 48 63 d8 89 54 24 0c ba 01 00 00 00 48 89 de
>         e8 d3 6e ff f2 49 89 c7 48 3d 00 f0 ff ff 0f 87 28 01 00 00 <48>
>         8b 00 a8 04 0f 84 12 01 00 00 49 8b 07 a8 01 0f 85 07 01 00 00
>   RSP: 0018:ffffd065089bfae8 EFLAGS: 00010207
>   RAX: 0000000000000000 RBX: 000000000000004c RCX: 0000000000000003
>   RDX: 000000000000000c RSI: ffff8ecec175f908 RDI: ffff8ecdd505e000
>   RBP: ffff8ecee0983000 R08: ffff8ecec1582f70 R09: 0000000000000000
>   R10: 0000000000000000 R11: ffff8ece2a13eff0 R12: ffffd065089bfb80
>   R13: 0000000000008c40 R14: ffff8ecec0420a78 R15: 0000000000000000
>   CR2: 0000000000000000 CR3: 00000000150b2000 CR4: 0000000000750ee0
>   Call Trace:
>    <TASK>
>    ext4_free_blocks+0x410/0xbb0 [ext4]
>    ext4_ext_remove_space+0x7ff/0x15d0 [ext4]
>    ext4_ext_truncate+0xb4/0xd0 [ext4]
>    ext4_truncate+0x314/0x490 [ext4]
>    ? __ext4_journal_start_sb+0x105/0x120 [ext4]
>    ext4_evict_inode+0x2f8/0x710 [ext4]
>    evict+0x112/0x2c0
>    do_unlinkat+0x173/0x320
>    __x64_sys_unlink+0x3e/0x70
>    do_syscall_64+0x5d/0xb0
>    entry_SYSCALL_64_after_hwframe+0x6e/0xd8
>    </TASK>
>   Kernel panic - not syncing: Fatal exception
>
> = Analysis
> ----------
>
> The faulting instruction is in the fast path of ext4_mb_load_buddy_gfp():
>
>   folio = __filemap_get_folio(inode->i_mapping, pnum, FGP_ACCESSED, 0);
>   if (IS_ERR(folio) || !folio_test_uptodate(folio) || folio_test_locked(folio)) {
>
> No FGP_CREAT is passed, so when the folio is not in the page cache
> __filemap_get_folio() reaches no_page: and, on 6.1.y, simply does
> "return folio;" with folio == NULL.
>
>   IS_ERR(NULL) is false, so the guard falls through to
>   folio_test_locked(folio), which dereferences NULL.
>
> RAX == 0 at the fault and CR2 == 0 confirm the returned value was NULL. I
> also disassembled the shipped ext4.ko to make sure this is the code being
> executed:
>
>   315c8: call  __filemap_get_folio
>   315cd: mov   %rax,%r15
>   315d0: cmp   $0xfffffffffffff000,%rax    # IS_ERR() only
>   315d6: ja    <slow path>
>   315dc: mov   (%rax),%rax                 # +0xbc, faults with RAX == NULL
>
> There is no NULL test anywhere between the call and the dereference.
>
> Commit a8d83471c560 ("ext4: fix error pointer dereference in
> ext4_mb_load_buddy_gfp()") added the IS_ERR() checks. That is correct for
> mainline, where __filemap_get_folio() returns ERR_PTR(-ENOENT), but it does
> not cover 6.1.y, where the function returns NULL for the same situation.
>
> = Why this is 6.1.y only
> -------------------------
>
> __filemap_get_folio() changed its no-folio convention in v6.4:
>
>   66dabbb65d67  mm: return an ERR_PTR from __filemap_get_folio
>   38a55db9877c  filemap: Handle error return from __filemap_get_folio()
>
> That change is a semantics change for every caller, so it was never a
> stable candidate and 6.1.y does not have it. What 6.1.y did get, in
> 6.1.191, is the ext4 side of the folio conversion (862483175d3d, d34e4fd4e73f
> and the a8d83471c560 follow-up), which was written against the post-6.4
> semantics.
>
> I checked the tree heads:
>
>   branch         ext4 guard               __filemap_get_folio   result
>   linux-6.6.y    IS_ERR(folio) || ...     ERR_PTR(-ENOENT)      ok
>   linux-6.12.y   IS_ERR(folio) || ...     ERR_PTR(-ENOENT)      ok
>   linux-6.1.y    IS_ERR(folio) || ...     NULL                  NULL deref
>
> So 6.1.y is the only affected stable branch, and it stays broken in 6.1.192
> and in linux-6.1.y HEAD. 5.15.y still uses find_get_page_flags() here and is
> not affected.
>
> = Minor: a second latent site in the same file
> -----------------------------------------------
>
> ext4_mb_get_buddy_page_lock() has the same assumption:
>
>   folio = __filemap_get_folio(inode->i_mapping, pnum,
>                   FGP_LOCK | FGP_ACCESSED | FGP_CREAT, gfp);
>   if (IS_ERR(folio))
>           return PTR_ERR(folio);
>   BUG_ON(folio->mapping != inode->i_mapping);
>
> Here NULL does come back from FGP_CREAT when the allocation fails, and
> PTR_ERR(NULL) is 0, so the function reports success and then dereferences
> NULL in BUG_ON(). Same root cause, different symptom. I folded it into the
> patch below.
>
> No other file under fs/ext4/ calls __filemap_get_folio() in 6.1.192, so
> mballoc.c is the whole surface.
>
> = Proposed fix (against 6.1.192)
> ---------------------------------
>
> Use IS_ERR_OR_NULL() and translate NULL into -ENOMEM. This keeps working
> unchanged if 6.1.y ever picks up the ERR_PTR() semantics, and it is a no-op
> for mainline.

[Severity: High]
The commit message is missing a Signed-off-by trailer, which is required
under the Developer's Certificate of Origin before the patch can be
applied.

[Severity: Low]
Since this fixes regressions introduced by the folio conversion commits on
6.1.y, should the commit message also include Fixes tags?

  Fixes: d34e4fd4e73f ("ext4: convert bd_bitmap_page to bd_bitmap_folio")
  Fixes: 862483175d3d ("ext4: convert bd_buddy_page to bd_buddy_folio")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/ef745013-2ea2-4e2d-86be-ac3e4a9d0cba@app.fastmail.com?part=1

      reply	other threads:[~2026-11-16  9:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  9:30 [BUG] ext4: NULL deref in ext4_mb_load_buddy_gfp() on 6.1.y Ivan Tiukov
2026-11-16  9:36 ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-216623@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ivan@tiukov.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.