lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <202505150900.13CFA05B7@keescook>
Date: Thu, 15 May 2025 09:01:11 -0700
From: Kees Cook <kees@...nel.org>
To: Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc: Shung-Hsi Yu <shung-hsi.yu@...e.com>, bpf@...r.kernel.org,
	linux-mm@...ck.org, Andrii Nakryiko <andrii@...nel.org>,
	Ihor Solodrai <ihor.solodrai@...ux.dev>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Michal Hocko <mhocko@...e.com>, Vlastimil Babka <vbabka@...e.cz>,
	Uladzislau Rezki <urezki@...il.com>, linux-kernel@...r.kernel.org,
	linux-hardening@...r.kernel.org, regressions@...ts.linux.dev,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Alexei Starovoitov <ast@...nel.org>,
	Daniel Borkmann <daniel@...earbox.net>,
	Pawan Gupta <pawan.kumar.gupta@...ux.intel.com>,
	Eduard Zingerman <eddyz87@...il.com>
Subject: Re: [REGRESSION] bpf verifier slowdown due to vrealloc() change
 since 6.15-rc6

On Thu, May 15, 2025 at 08:55:47AM -0700, Andrii Nakryiko wrote:
> On Thu, May 15, 2025 at 8:53 AM Kees Cook <kees@...nel.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 <kees@...nel.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 <kees@...nel.org>
> > ---
> > Cc: Andrew Morton <akpm@...ux-foundation.org>
> > Cc: Uladzislau Rezki <urezki@...il.com>
> > Cc: <linux-mm@...ck.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.GAE@google.com/

Yes, this looks very much like the kasan oops that motivated the initial
patch:

https://lore.kernel.org/all/20250408192503.6149a816@outsider.home/

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ