Skip to contentSkip to conversation

mm-vmalloc-only-zero-init-on-vrealloc-shrink.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message May 25, 2025 Stable branch

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: mm: vmalloc: only zero-init on vrealloc shrink
has been removed from the -mm tree. Its filename was
mm-vmalloc-only-zero-init-on-vrealloc-shrink.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Kees Cook <[email protected]>
Subject: mm: vmalloc: only zero-init on vrealloc shrink
Date: Thu, 15 May 2025 14:42:16 -0700

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")
Cc Danilo Krummrich <[email protected]>
Cc Eduard Zingerman <[email protected]>
Cc "Erhard F." <[email protected]>
Cc Shung-Hsi Yu <[email protected]>
Cc "Uladzislau Rezki (Sony)" <[email protected]>

---

 mm/vmalloc.c |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-only-zero-init-on-vrealloc-shrink +7 -5
@@ -4093,8 +4093,8 @@ void *vrealloc_noprof(const void *p, siz
 	 * 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, siz
 	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;
 	}

_

Patches currently in -mm which might be from [email protected] are