Skip to contentSkip to conversation

lib-test_hmm-fix-memory-leak-in-dmirror_migrate_to_system.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Jun 9

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: lib/test_hmm: fix memory leak in dmirror_migrate_to_system()
has been removed from the -mm tree. Its filename was
lib-test_hmm-fix-memory-leak-in-dmirror_migrate_to_system.patch

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

------------------------------------------------------
From: Hao Ge <[email protected]>
Subject: lib/test_hmm: fix memory leak in dmirror_migrate_to_system()
Date: Thu, 28 May 2026 09:13:36 +0800

Move the kvcalloc() calls after the early return checks to avoid leaking src_pfns and dst_pfns when end < start or mmget_not_zero() fails.

Fixes 775465fd26a3 ("lib/test_hmm: add zone device private THP test infrastructure")
Cc Jason Gunthorpe <[email protected]>
Cc Leon Romanovsky <[email protected]>

---

 lib/test_hmm.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/test_hmm.c renamed from lib/test_hmm.c~lib-test_hmm-fix-memory-leak-in-dmirror_migrate_to_system +3 -3
@@ -1111,9 +1111,6 @@ static int dmirror_migrate_to_system(str
 	unsigned long *src_pfns;
 	unsigned long *dst_pfns;
 
-	src_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*src_pfns), GFP_KERNEL | __GFP_NOFAIL);
-	dst_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*dst_pfns), GFP_KERNEL | __GFP_NOFAIL);
-
 	start = cmd->addr;
 	end = start + size;
 	if (end < start)
@@ -1123,6 +1120,9 @@ static int dmirror_migrate_to_system(str
 	if (!mmget_not_zero(mm))
 		return -EINVAL;
 
+	src_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*src_pfns), GFP_KERNEL | __GFP_NOFAIL);
+	dst_pfns = kvcalloc(PTRS_PER_PTE, sizeof(*dst_pfns), GFP_KERNEL | __GFP_NOFAIL);
+
 	cmd->cpages = 0;
 	mmap_read_lock(mm);
 	for (addr = start; addr < end; addr = next) {

_

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

mm-alloc_tag-replace-fixed-size-early-pfn-array-with-dynamic-linked-list.patch alloc_tag-fix-use-after-free-in-proc-allocinfo-after-module-unload.patch maintainers-add-hao-ge-as-reviewer-for-codetag-and-alloc_tag.patch