From: Kees Cook <kees@kernel.org>
To: Shung-Hsi Yu <shung-hsi.yu@suse.com>
Cc: bpf@vger.kernel.org, linux-mm@kvack.org,
Andrii Nakryiko <andrii@kernel.org>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@suse.com>, Vlastimil Babka <vbabka@suse.cz>,
Uladzislau Rezki <urezki@gmail.com>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
regressions@lists.linux.dev,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Pawan Gupta <pawan.kumar.gupta@linux.intel.com>,
Eduard Zingerman <eddyz87@gmail.com>
Subject: Re: [REGRESSION] bpf verifier slowdown due to vrealloc() change since 6.15-rc6
Date: Thu, 15 May 2025 08:53:15 -0700 [thread overview]
Message-ID: <202505150850.6F3E261D67@keescook> (raw)
In-Reply-To: <202505150845.0F9E154@keescook>
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@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 <kees@kernel.org>
---
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Uladzislau Rezki <urezki@gmail.com>
Cc: <linux-mm@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;
return (void *)p;
}
--
2.34.1
--
Kees Cook
next prev parent reply other threads:[~2025-05-15 15:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 13:12 Shung-Hsi Yu
2025-05-15 14:51 ` Kees Cook
2025-05-15 16:51 ` Kees Cook
2025-05-15 17:18 ` Pawan Gupta
2025-05-15 17:41 ` Kees Cook
2025-05-15 17:52 ` Pawan Gupta
2025-05-15 20:26 ` Pawan Gupta
2025-05-15 17:53 ` Andrii Nakryiko
2025-05-15 18:24 ` Kees Cook
2025-05-15 18:50 ` Eduard Zingerman
2025-05-15 15:47 ` Kees Cook
2025-05-15 15:53 ` Kees Cook [this message]
2025-05-15 15:55 ` Andrii Nakryiko
2025-05-15 16:01 ` Kees Cook
2025-05-15 18:31 ` Eduard Zingerman
2025-05-15 21:36 ` Kees Cook
2025-05-15 21:39 ` Eduard Zingerman
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=202505150850.6F3E261D67@keescook \
--to=kees@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=ihor.solodrai@linux.dev \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=regressions@lists.linux.dev \
--cc=shung-hsi.yu@suse.com \
--cc=urezki@gmail.com \
--cc=vbabka@suse.cz \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox