On Thu, May 15, 2025 at 8:53 AM Kees Cook <k...@kernel.org> wrote: > > On Thu, May 15, 2025 at 08:47:47AM -0700, Kees Cook wrote: > > On Thu, May 15, 2025 at 09:12:25PM +0800, Shung-Hsi Yu wrote: > > > Bisect was done by Pawan and got to commit a0309faf1cb0 "mm: vmalloc: > > > support more granular vrealloc() sizing"[2]. To further zoom in the > > > > Can you try this patch? It's a clear bug fix, but if it doesn't improve > > things, I have another idea to rearrange the memset. > > Here's the patch (on top of the prior one) that relocates the memset: > > > From 0bc71b78603500705aca77f82de8ed1fc595c4c3 Mon Sep 17 00:00:00 2001 > From: Kees Cook <k...@kernel.org> > Date: Thu, 15 May 2025 08:48:24 -0700 > Subject: [PATCH] mm: vmalloc: Only zero-init on vrealloc shrink > > The common case is to grow reallocations, and since init_on_alloc will > have already zeroed the whole allocation, we only need to zero when > shrinking the allocation. > > Fixes: a0309faf1cb0 ("mm: vmalloc: support more granular vrealloc() sizing") > Signed-off-by: Kees Cook <k...@kernel.org> > --- > Cc: Andrew Morton <a...@linux-foundation.org> > Cc: Uladzislau Rezki <ure...@gmail.com> > Cc: <linux...@kvack.org> > --- > mm/vmalloc.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 74bd00fd734d..83bedb1559ac 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -4093,8 +4093,8 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t > flags) > * would be a good heuristic for when to shrink the vm_area? > */ > if (size <= old_size) { > - /* Zero out "freed" memory. */ > - if (want_init_on_free()) > + /* Zero out "freed" memory, potentially for future realloc. */ > + if (want_init_on_free() || want_init_on_alloc(flags)) > memset((void *)p + size, 0, old_size - size); > vm->requested_size = size; > kasan_poison_vmalloc(p + size, old_size - size); > @@ -4107,9 +4107,11 @@ void *vrealloc_noprof(const void *p, size_t size, > gfp_t flags) > if (size <= alloced_size) { > kasan_unpoison_vmalloc(p + old_size, size - old_size, > KASAN_VMALLOC_PROT_NORMAL); > - /* Zero out "alloced" memory. */ > - if (want_init_on_alloc(flags)) > - memset((void *)p + old_size, 0, size - old_size); > + /* > + * No need to zero memory here, as unused memory will have > + * already been zeroed at initial allocation time or during > + * realloc shrink time. > + */ > vm->requested_size = size;
This vm->requested_size change you are adding should also fix the kasan issue reported by syzbot ([0]). [0] https://lore.kernel.org/bpf/68213ddf.050a0220.f2294.0045....@google.com/ > return (void *)p; > } > -- > 2.34.1 > > > > -- > Kees Cook