Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit()
@ 2026-09-02  1:33 Joseph Qi
  2026-09-02  1:38 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Joseph Qi @ 2026-09-02  1:33 UTC (permalink / raw)
  To: Christian Brauner
  Cc: linux-fsdevel, linux-ext4, ocfs2-devel, linux-kernel, Joseph Qi,
	Srikanth Aithal, Luca Weiss, Jan Kara

Commit a2c924c240e7 ("buffer: set BIO_COMPLETE_IN_TASK for dropbehind
writeback") added an unconditional folio_test_dropbehind(bh->b_folio) in
__bh_submit().  But jbd2 shadow buffers have a NULL b_folio since commit
5febcba29792 ("jbd2: point the shadow buffer at the frozen data
directly") made them point b_data at the kmalloced frozen data rather
than a folio.  Submitting such a buffer during journal commit oopses:

  BUG: kernel NULL pointer dereference, address: 0000000000000000
  RIP: 0010:__bh_submit.constprop.0+0x87/0x120
  Call Trace:
   jbd2_journal_commit_transaction+0x932/0x1b10
   kjournald2+0xb2/0x250

Hit by the ocfs2-testsuite fill_verify_holes test running with
data=writeback.

Dropbehind only applies to buffers backed by a folio, so skip the check
when b_folio is NULL.

Fixes: 5febcba29792 ("jbd2: point the shadow buffer at the frozen data directly")
Tested-by: Srikanth Aithal <Srikanth.Aithal@amd.com>
Tested-by: Luca Weiss <luca.weiss@fairphone.com> # sm7225-fairphone-fp4
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
---
 fs/buffer.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 427d8a817cd5..f46fa6413032 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1106,7 +1106,8 @@ static void __bh_submit(struct buffer_head *bh, blk_opf_t opf,
 
 	bio = bio_alloc(bh->b_bdev, 1, opf, GFP_NOIO);
 
-	if (folio_test_dropbehind(bh->b_folio) && op_is_write(opf))
+	if (bh->b_folio && folio_test_dropbehind(bh->b_folio) &&
+	    op_is_write(opf))
 		bio_set_flag(bio, BIO_COMPLETE_IN_TASK);
 
 	if (IS_ENABLED(CONFIG_FS_ENCRYPTION))
-- 
2.39.3


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

* Re: [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit()
  2026-09-02  1:33 [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit() Joseph Qi
@ 2026-09-02  1:38 ` sashiko-bot
  2026-09-02 20:52 ` Yalagada Pavan Kumar
  2026-09-04  5:28 ` Greg Ociepka
  2 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-09-02  1:38 UTC (permalink / raw)
  To: Joseph Qi; +Cc: Mark Fasheh, tytso, Joel Becker, Joseph Qi, linux-ext4

> Commit a2c924c240e7 ("buffer: set BIO_COMPLETE_IN_TASK for dropbehind
> writeback") added an unconditional folio_test_dropbehind(bh->b_folio) in
> __bh_submit().  But jbd2 shadow buffers have a NULL b_folio since commit
> 5febcba29792 ("jbd2: point the shadow buffer at the frozen data
> directly") made them point b_data at the kmalloced frozen data rather
> than a folio.  Submitting such a buffer during journal commit oopses:
> 
>   BUG: kernel NULL pointer dereference, address: 0000000000000000
>   RIP: 0010:__bh_submit.constprop.0+0x87/0x120
>   Call Trace:
>    jbd2_journal_commit_transaction+0x932/0x1b10
>    kjournald2+0xb2/0x250
> 
> Hit by the ocfs2-testsuite fill_verify_holes test running with
> data=writeback.
> 
> Dropbehind only applies to buffers backed by a folio, so skip the check
> when b_folio is NULL.
> 
> Fixes: 5febcba29792 ("jbd2: point the shadow buffer at the frozen data directly")
> Tested-by: Srikanth Aithal <Srikanth.Aithal@amd.com>
> Tested-by: Luca Weiss <luca.weiss@fairphone.com> # sm7225-fairphone-fp4
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>

Sashiko has reviewed this patch and found no issues. It looks great!

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260902013357.2815214-1-joseph.qi@linux.alibaba.com?part=1


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

* Re: [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit()
  2026-09-02  1:33 [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit() Joseph Qi
  2026-09-02  1:38 ` sashiko-bot
@ 2026-09-02 20:52 ` Yalagada Pavan Kumar
  2026-09-03  1:42   ` Joseph Qi
  2026-09-04  5:28 ` Greg Ociepka
  2 siblings, 1 reply; 6+ messages in thread
From: Yalagada Pavan Kumar @ 2026-09-02 20:52 UTC (permalink / raw)
  To: Joseph Qi
  Cc: Christian Brauner, linux-fsdevel, linux-ext4, ocfs2-devel,
	linux-kernel, Srikanth Aithal, Luca Weiss, Jan Kara

On Wed, Sep 02, 2026 at 09:33:57AM +0800, Joseph Qi wrote:
> Commit a2c924c240e7 ("buffer: set BIO_COMPLETE_IN_TASK for dropbehind
> writeback") added an unconditional folio_test_dropbehind(bh->b_folio) in
> __bh_submit().  But jbd2 shadow buffers have a NULL b_folio since commit
> 5febcba29792 ("jbd2: point the shadow buffer at the frozen data
> directly") made them point b_data at the kmalloced frozen data rather
> than a folio.  Submitting such a buffer during journal commit oopses:
> 
>   BUG: kernel NULL pointer dereference, address: 0000000000000000
>   RIP: 0010:__bh_submit.constprop.0+0x87/0x120
>   Call Trace:
>    jbd2_journal_commit_transaction+0x932/0x1b10
>    kjournald2+0xb2/0x250
> 
> Hit by the ocfs2-testsuite fill_verify_holes test running with
> data=writeback.
> 
> Dropbehind only applies to buffers backed by a folio, so skip the check
> when b_folio is NULL.
>
Hi,

I was working on a fix for this syzbot report [1] and didn't realize that you were
already working on it. I noticed your patch on the mailing list, so i won't
send a duplicate patch.
 
> Fixes: 5febcba29792 ("jbd2: point the shadow buffer at the frozen data directly")

Could you please add the Reported-by: and Closes: tags from the syzbot report
to your patch? This will help syzbot associate the patch with the reported
issue and track the fix.

[1]: https://syzkaller.appspot.com/bug?extid=41453ea05ab61c075f1f

Thank you,
Pavan

> Tested-by: Srikanth Aithal <Srikanth.Aithal@amd.com>
> Tested-by: Luca Weiss <luca.weiss@fairphone.com> # sm7225-fairphone-fp4
> Reviewed-by: Jan Kara <jack@suse.cz>
> Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
> ---
>  fs/buffer.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/buffer.c b/fs/buffer.c
> index 427d8a817cd5..f46fa6413032 100644
> --- a/fs/buffer.c
> +++ b/fs/buffer.c
> @@ -1106,7 +1106,8 @@ static void __bh_submit(struct buffer_head *bh, blk_opf_t opf,
>  
>  	bio = bio_alloc(bh->b_bdev, 1, opf, GFP_NOIO);
>  
> -	if (folio_test_dropbehind(bh->b_folio) && op_is_write(opf))
> +	if (bh->b_folio && folio_test_dropbehind(bh->b_folio) &&
> +	    op_is_write(opf))
>  		bio_set_flag(bio, BIO_COMPLETE_IN_TASK);
>  
>  	if (IS_ENABLED(CONFIG_FS_ENCRYPTION))
> -- 
> 2.39.3
> 

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

* Re: [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit()
  2026-09-02 20:52 ` Yalagada Pavan Kumar
@ 2026-09-03  1:42   ` Joseph Qi
  2026-09-04 10:35     ` Christian Brauner
  0 siblings, 1 reply; 6+ messages in thread
From: Joseph Qi @ 2026-09-03  1:42 UTC (permalink / raw)
  To: Yalagada Pavan Kumar, Christian Brauner
  Cc: linux-fsdevel, linux-ext4, ocfs2-devel, linux-kernel,
	Srikanth Aithal, Luca Weiss, Jan Kara



On 9/3/26 4:52 AM, Yalagada Pavan Kumar wrote:
> On Wed, Sep 02, 2026 at 09:33:57AM +0800, Joseph Qi wrote:
>> Commit a2c924c240e7 ("buffer: set BIO_COMPLETE_IN_TASK for dropbehind
>> writeback") added an unconditional folio_test_dropbehind(bh->b_folio) in
>> __bh_submit().  But jbd2 shadow buffers have a NULL b_folio since commit
>> 5febcba29792 ("jbd2: point the shadow buffer at the frozen data
>> directly") made them point b_data at the kmalloced frozen data rather
>> than a folio.  Submitting such a buffer during journal commit oopses:
>>
>>   BUG: kernel NULL pointer dereference, address: 0000000000000000
>>   RIP: 0010:__bh_submit.constprop.0+0x87/0x120
>>   Call Trace:
>>    jbd2_journal_commit_transaction+0x932/0x1b10
>>    kjournald2+0xb2/0x250
>>
>> Hit by the ocfs2-testsuite fill_verify_holes test running with
>> data=writeback.
>>
>> Dropbehind only applies to buffers backed by a folio, so skip the check
>> when b_folio is NULL.
>>
> Hi,
> 
> I was working on a fix for this syzbot report [1] and didn't realize that you were
> already working on it. I noticed your patch on the mailing list, so i won't
> send a duplicate patch.
>  
>> Fixes: 5febcba29792 ("jbd2: point the shadow buffer at the frozen data directly")
> 
> Could you please add the Reported-by: and Closes: tags from the syzbot report
> to your patch? This will help syzbot associate the patch with the reported
> issue and track the fix.
> 
> [1]: https://syzkaller.appspot.com/bug?extid=41453ea05ab61c075f1f
> 
Hi Christian,
Could you please address the above when apply the patch? Or should I
resend the patch with them?

Thanks,
Joseph 

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

* Re: [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit()
  2026-09-02  1:33 [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit() Joseph Qi
  2026-09-02  1:38 ` sashiko-bot
  2026-09-02 20:52 ` Yalagada Pavan Kumar
@ 2026-09-04  5:28 ` Greg Ociepka
  2 siblings, 0 replies; 6+ messages in thread
From: Greg Ociepka @ 2026-09-04  5:28 UTC (permalink / raw)
  To: Joseph Qi
  Cc: Christian Brauner, Yalagada Pavan Kumar, Matthew Wilcox,
	linux-fsdevel, linux-ext4, linux-kernel

On Wed, 2 Sep 2026 09:33:57 +0800, Joseph Qi wrote:
> Since commit 8deae2284976 ("buffer: allow a buffer_head to point at
> memory outside the page cache"), bh->b_folio may be NULL.

We hit the same NULL dereference independently on real hardware, and
it is nastier than a fuzzer-only finding: on an ext4 root filesystem
every boot of next-20260831 (and every later tag up to next-20260903)
dies about two minutes in. jbd2's shadow buffers have no b_folio by
design, so the first journal commit after mount oopses in
__bh_submit(), kjournald2 is killed by make_task_dead() and every
subsequent metadata write blocks forever - journald, the flush workers
and eventually all of userspace wedge in uninterruptible sleep with no
block-layer errors reported. After an unclean shutdown the crash moves
into early boot (journal recovery commits immediately), which makes
the machine effectively unbootable until a different kernel is chosen.

  Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
  CPU: 0 UID: 0 PID: 357 Comm: jbd2/nvme0n1p18 Tainted: G        W  7.3.0-rc1-next-20260831
  pc : __bh_submit+0xa8/0x210
  Call trace:
   __bh_submit+0xa8/0x210 (P)
   bh_submit+0x24/0x38
   jbd2_journal_commit_transaction+0xb80/0x1ce8
   kjournald2+0xb8/0x238

With this exact change applied on top of next-20260831 the same
machine (ASUS Zenbook A16 UX3607OA, Snapdragon X2 Elite, arm64) boots
reliably and has been running normally for 11+ hours.

Tested-by: Greg Ociepka <greg@ferrisoft.com>


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

* Re: [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit()
  2026-09-03  1:42   ` Joseph Qi
@ 2026-09-04 10:35     ` Christian Brauner
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2026-09-04 10:35 UTC (permalink / raw)
  To: Joseph Qi
  Cc: Yalagada Pavan Kumar, linux-fsdevel, linux-ext4, ocfs2-devel,
	linux-kernel, Srikanth Aithal, Luca Weiss, Jan Kara

On Thu, Sep 03, 2026 at 09:42:27AM +0800, Joseph Qi wrote:
> 
> 
> On 9/3/26 4:52 AM, Yalagada Pavan Kumar wrote:
> > On Wed, Sep 02, 2026 at 09:33:57AM +0800, Joseph Qi wrote:
> >> Commit a2c924c240e7 ("buffer: set BIO_COMPLETE_IN_TASK for dropbehind
> >> writeback") added an unconditional folio_test_dropbehind(bh->b_folio) in
> >> __bh_submit().  But jbd2 shadow buffers have a NULL b_folio since commit
> >> 5febcba29792 ("jbd2: point the shadow buffer at the frozen data
> >> directly") made them point b_data at the kmalloced frozen data rather
> >> than a folio.  Submitting such a buffer during journal commit oopses:
> >>
> >>   BUG: kernel NULL pointer dereference, address: 0000000000000000
> >>   RIP: 0010:__bh_submit.constprop.0+0x87/0x120
> >>   Call Trace:
> >>    jbd2_journal_commit_transaction+0x932/0x1b10
> >>    kjournald2+0xb2/0x250
> >>
> >> Hit by the ocfs2-testsuite fill_verify_holes test running with
> >> data=writeback.
> >>
> >> Dropbehind only applies to buffers backed by a folio, so skip the check
> >> when b_folio is NULL.
> >>
> > Hi,
> > 
> > I was working on a fix for this syzbot report [1] and didn't realize that you were
> > already working on it. I noticed your patch on the mailing list, so i won't
> > send a duplicate patch.
> >  
> >> Fixes: 5febcba29792 ("jbd2: point the shadow buffer at the frozen data directly")
> > 
> > Could you please add the Reported-by: and Closes: tags from the syzbot report
> > to your patch? This will help syzbot associate the patch with the reported
> > issue and track the fix.
> > 
> > [1]: https://syzkaller.appspot.com/bug?extid=41453ea05ab61c075f1f
> > 
> Hi Christian,
> Could you please address the above when apply the patch? Or should I
> resend the patch with them?

I'll do it. Thanks!

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

end of thread, other threads:[~2026-09-04 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02  1:33 [PATCH] buffer: fix NULL dereference of bh->b_folio in __bh_submit() Joseph Qi
2026-09-02  1:38 ` sashiko-bot
2026-09-02 20:52 ` Yalagada Pavan Kumar
2026-09-03  1:42   ` Joseph Qi
2026-09-04 10:35     ` Christian Brauner
2026-09-04  5:28 ` Greg Ociepka

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