public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/ext4: Initialize new folios before use
@ 2025-12-23 21:58 Bartlomiej Kubik
  2025-12-24  1:39 ` Baokun Li
  0 siblings, 1 reply; 4+ messages in thread
From: Bartlomiej Kubik @ 2025-12-23 21:58 UTC (permalink / raw)
  To: tytso
  Cc: adilger.kernel, linux-ext4, linux-kernel, david.hunter.linux,
	skhan, khalid, linux-kernel-mentees, Bartlomiej Kubik,
	syzbot+703d8a2cd20971854b06

KMSAN reports an uninitialized value in adiantum_crypt, created at
write_begin_get_folio(). New folios are allocated with the FGP_CREAT
flag and may be returned uninitialized. These uninitialized folios are
then used without proper initialization.

Fixes: b799474b9aeb ("mm/pagemap: add write_begin_get_folio() helper function")
Tested-by: syzbot+703d8a2cd20971854b06@syzkaller.appspotmail.com
Reported-by: syzbot+703d8a2cd20971854b06@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=703d8a2cd20971854b06

Signed-off-by: Bartlomiej Kubik <kubik.bartlomiej@gmail.com>
---
 include/linux/pagemap.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 31a848485ad9..31bbc8299e08 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -787,7 +787,8 @@ static inline struct folio *write_begin_get_folio(const struct kiocb *iocb,
                 fgp_flags |= FGP_DONTCACHE;

         return __filemap_get_folio(mapping, index, fgp_flags,
-                                   mapping_gfp_mask(mapping));
+				mapping_gfp_mask(mapping)|
+				__GFP_ZERO);
 }

 /**
--
2.39.5

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

* Re: [PATCH] fs/ext4: Initialize new folios before use
  2025-12-23 21:58 [PATCH] fs/ext4: Initialize new folios before use Bartlomiej Kubik
@ 2025-12-24  1:39 ` Baokun Li
  2025-12-28 13:00   ` Bartłomiej Kubik
  0 siblings, 1 reply; 4+ messages in thread
From: Baokun Li @ 2025-12-24  1:39 UTC (permalink / raw)
  To: Bartlomiej Kubik
  Cc: tytso, adilger.kernel, linux-ext4, linux-kernel,
	david.hunter.linux, skhan, khalid, linux-kernel-mentees,
	syzbot+703d8a2cd20971854b06

Hi Bartlomiej,

On 2025-12-24 05:58, Bartlomiej Kubik wrote:
> KMSAN reports an uninitialized value in adiantum_crypt, created at
> write_begin_get_folio(). New folios are allocated with the FGP_CREAT
> flag and may be returned uninitialized. These uninitialized folios are
> then used without proper initialization.
>
> Fixes: b799474b9aeb ("mm/pagemap: add write_begin_get_folio() helper function")
> Tested-by: syzbot+703d8a2cd20971854b06@syzkaller.appspotmail.com
> Reported-by: syzbot+703d8a2cd20971854b06@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=703d8a2cd20971854b06
>
> Signed-off-by: Bartlomiej Kubik <kubik.bartlomiej@gmail.com>
> ---
>  include/linux/pagemap.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> index 31a848485ad9..31bbc8299e08 100644
> --- a/include/linux/pagemap.h
> +++ b/include/linux/pagemap.h
> @@ -787,7 +787,8 @@ static inline struct folio *write_begin_get_folio(const struct kiocb *iocb,
>                  fgp_flags |= FGP_DONTCACHE;
>
>          return __filemap_get_folio(mapping, index, fgp_flags,
> -                                   mapping_gfp_mask(mapping));
> +				mapping_gfp_mask(mapping)|
> +				__GFP_ZERO);
We do need to perform some initialization, but doing it in this common
path is clearly unreasonable. It would introduce unnecessary zeroing
overhead even for non-crypto scenarios.

Therefore, I suspect something was missed in certain crypto-related
initialization paths where the zeroing should have been handled instead.


Cheers,
Baokun


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

* Re: [PATCH] fs/ext4: Initialize new folios before use
  2025-12-24  1:39 ` Baokun Li
@ 2025-12-28 13:00   ` Bartłomiej Kubik
  2025-12-28 20:09     ` Eric Biggers
  0 siblings, 1 reply; 4+ messages in thread
From: Bartłomiej Kubik @ 2025-12-28 13:00 UTC (permalink / raw)
  To: Baokun Li
  Cc: tytso, adilger.kernel, linux-ext4, linux-kernel,
	david.hunter.linux, skhan, khalid, linux-kernel-mentees,
	syzbot+703d8a2cd20971854b06

Hi,

Thank you for your suggestions.

On Wed, 24 Dec 2025 at 02:39, Baokun Li <libaokun1@huawei.com> wrote:
>
> Hi Bartlomiej,
>
> On 2025-12-24 05:58, Bartlomiej Kubik wrote:
> > KMSAN reports an uninitialized value in adiantum_crypt, created at
> > write_begin_get_folio(). New folios are allocated with the FGP_CREAT
> > flag and may be returned uninitialized. These uninitialized folios are
> > then used without proper initialization.
> >
> > Fixes: b799474b9aeb ("mm/pagemap: add write_begin_get_folio() helper function")
> > Tested-by: syzbot+703d8a2cd20971854b06@syzkaller.appspotmail.com
> > Reported-by: syzbot+703d8a2cd20971854b06@syzkaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=703d8a2cd20971854b06
> >
> > Signed-off-by: Bartlomiej Kubik <kubik.bartlomiej@gmail.com>
> > ---
> >  include/linux/pagemap.h | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> > index 31a848485ad9..31bbc8299e08 100644
> > --- a/include/linux/pagemap.h
> > +++ b/include/linux/pagemap.h
> > @@ -787,7 +787,8 @@ static inline struct folio *write_begin_get_folio(const struct kiocb *iocb,
> >                  fgp_flags |= FGP_DONTCACHE;
> >
> >          return __filemap_get_folio(mapping, index, fgp_flags,
> > -                                   mapping_gfp_mask(mapping));
> > +                             mapping_gfp_mask(mapping)|
> > +                             __GFP_ZERO);
> We do need to perform some initialization, but doing it in this common
> path is clearly unreasonable. It would introduce unnecessary zeroing
> overhead even for non-crypto scenarios.

Yes. That could introduce unnecessary zeroing in other paths.

> Therefore, I suspect something was missed in certain crypto-related
> initialization paths where the zeroing should have been handled instead.

I will try to fix this in the crypto-path only and send [PATCH v2].

>
> Cheers,
> Baokun
>

Best regards
Bartłomiej Kubik

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

* Re: [PATCH] fs/ext4: Initialize new folios before use
  2025-12-28 13:00   ` Bartłomiej Kubik
@ 2025-12-28 20:09     ` Eric Biggers
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Biggers @ 2025-12-28 20:09 UTC (permalink / raw)
  To: Bartłomiej Kubik
  Cc: Baokun Li, tytso, adilger.kernel, linux-ext4, linux-kernel,
	david.hunter.linux, skhan, khalid, linux-kernel-mentees,
	syzbot+703d8a2cd20971854b06

On Sun, Dec 28, 2025 at 02:00:46PM +0100, Bartłomiej Kubik wrote:
> Hi,
> 
> Thank you for your suggestions.
> 
> On Wed, 24 Dec 2025 at 02:39, Baokun Li <libaokun1@huawei.com> wrote:
> >
> > Hi Bartlomiej,
> >
> > On 2025-12-24 05:58, Bartlomiej Kubik wrote:
> > > KMSAN reports an uninitialized value in adiantum_crypt, created at
> > > write_begin_get_folio(). New folios are allocated with the FGP_CREAT
> > > flag and may be returned uninitialized. These uninitialized folios are
> > > then used without proper initialization.
> > >
> > > Fixes: b799474b9aeb ("mm/pagemap: add write_begin_get_folio() helper function")
> > > Tested-by: syzbot+703d8a2cd20971854b06@syzkaller.appspotmail.com
> > > Reported-by: syzbot+703d8a2cd20971854b06@syzkaller.appspotmail.com
> > > Closes: https://syzkaller.appspot.com/bug?extid=703d8a2cd20971854b06
> > >
> > > Signed-off-by: Bartlomiej Kubik <kubik.bartlomiej@gmail.com>
> > > ---
> > >  include/linux/pagemap.h | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
> > > index 31a848485ad9..31bbc8299e08 100644
> > > --- a/include/linux/pagemap.h
> > > +++ b/include/linux/pagemap.h
> > > @@ -787,7 +787,8 @@ static inline struct folio *write_begin_get_folio(const struct kiocb *iocb,
> > >                  fgp_flags |= FGP_DONTCACHE;
> > >
> > >          return __filemap_get_folio(mapping, index, fgp_flags,
> > > -                                   mapping_gfp_mask(mapping));
> > > +                             mapping_gfp_mask(mapping)|
> > > +                             __GFP_ZERO);
> > We do need to perform some initialization, but doing it in this common
> > path is clearly unreasonable. It would introduce unnecessary zeroing
> > overhead even for non-crypto scenarios.
> 
> Yes. That could introduce unnecessary zeroing in other paths.
> 
> > Therefore, I suspect something was missed in certain crypto-related
> > initialization paths where the zeroing should have been handled instead.
> 
> I will try to fix this in the crypto-path only and send [PATCH v2].

Please see https://lore.kernel.org/linux-ext4/20251210022202.GB4128@sol/
for my earlier analysis of this issue.

- Eric

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

end of thread, other threads:[~2025-12-28 20:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-23 21:58 [PATCH] fs/ext4: Initialize new folios before use Bartlomiej Kubik
2025-12-24  1:39 ` Baokun Li
2025-12-28 13:00   ` Bartłomiej Kubik
2025-12-28 20:09     ` Eric Biggers

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