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: <20251223-b4-kunit-user-alloc-v1-1-fb910ae0e50c@google.com>
Date: Tue, 23 Dec 2025 16:18:10 +0000
From: Brendan Jackman <jackmanb@...gle.com>
To: Brendan Higgins <brendan.higgins@...ux.dev>, David Gow <davidgow@...gle.com>, 
	Rae Moar <raemoar63@...il.com>, Kees Cook <kees@...nel.org>, Ingo Molnar <mingo@...hat.com>, 
	Peter Zijlstra <peterz@...radead.org>, Juri Lelli <juri.lelli@...hat.com>, 
	Vincent Guittot <vincent.guittot@...aro.org>, Dietmar Eggemann <dietmar.eggemann@....com>, 
	Steven Rostedt <rostedt@...dmis.org>, Ben Segall <bsegall@...gle.com>, Mel Gorman <mgorman@...e.de>, 
	Valentin Schneider <vschneid@...hat.com>, Andrew Morton <akpm@...ux-foundation.org>, 
	David Hildenbrand <david@...nel.org>, Lorenzo Stoakes <lorenzo.stoakes@...cle.com>, 
	"Liam R. Howlett" <Liam.Howlett@...cle.com>, Vlastimil Babka <vbabka@...e.cz>, 
	Mike Rapoport <rppt@...nel.org>, Suren Baghdasaryan <surenb@...gle.com>, Michal Hocko <mhocko@...e.com>
Cc: linux-kselftest@...r.kernel.org, kunit-dev@...glegroups.com, 
	linux-kernel@...r.kernel.org, linux-mm@...ck.org, 
	Brendan Jackman <jackmanb@...gle.com>
Subject: [PATCH 1/3] kunit: test: Delete pointless resource API usage

This code uses the low-level resource API to track parameters of the
vm_mmap call, but it doesn't do anything with them, because the mm
teardown code takes care of tearing down the mmaps. Delete it.

Signed-off-by: Brendan Jackman <jackmanb@...gle.com>
---
 lib/kunit/user_alloc.c | 76 ++++----------------------------------------------
 1 file changed, 6 insertions(+), 70 deletions(-)

diff --git a/lib/kunit/user_alloc.c b/lib/kunit/user_alloc.c
index b8cac765e6204..564f5566641d5 100644
--- a/lib/kunit/user_alloc.c
+++ b/lib/kunit/user_alloc.c
@@ -7,21 +7,6 @@
 #include <linux/kthread.h>
 #include <linux/mm.h>
 
-struct kunit_vm_mmap_resource {
-	unsigned long addr;
-	size_t size;
-};
-
-/* vm_mmap() arguments */
-struct kunit_vm_mmap_params {
-	struct file *file;
-	unsigned long addr;
-	unsigned long len;
-	unsigned long prot;
-	unsigned long flag;
-	unsigned long offset;
-};
-
 int kunit_attach_mm(void)
 {
 	struct mm_struct *mm;
@@ -50,67 +35,18 @@ int kunit_attach_mm(void)
 }
 EXPORT_SYMBOL_GPL(kunit_attach_mm);
 
-static int kunit_vm_mmap_init(struct kunit_resource *res, void *context)
-{
-	struct kunit_vm_mmap_params *p = context;
-	struct kunit_vm_mmap_resource vres;
-	int ret;
-
-	ret = kunit_attach_mm();
-	if (ret)
-		return ret;
-
-	vres.size = p->len;
-	vres.addr = vm_mmap(p->file, p->addr, p->len, p->prot, p->flag, p->offset);
-	if (!vres.addr)
-		return -ENOMEM;
-	res->data = kmemdup(&vres, sizeof(vres), GFP_KERNEL);
-	if (!res->data) {
-		vm_munmap(vres.addr, vres.size);
-		return -ENOMEM;
-	}
-
-	return 0;
-}
-
-static void kunit_vm_mmap_free(struct kunit_resource *res)
-{
-	struct kunit_vm_mmap_resource *vres = res->data;
-
-	/*
-	 * Since this is executed from the test monitoring process,
-	 * the test's mm has already been torn down. We don't need
-	 * to run vm_munmap(vres->addr, vres->size), only clean up
-	 * the vres.
-	 */
-
-	kfree(vres);
-	res->data = NULL;
-}
-
 unsigned long kunit_vm_mmap(struct kunit *test, struct file *file,
 			    unsigned long addr, unsigned long len,
 			    unsigned long prot, unsigned long flag,
 			    unsigned long offset)
 {
-	struct kunit_vm_mmap_params params = {
-		.file = file,
-		.addr = addr,
-		.len = len,
-		.prot = prot,
-		.flag = flag,
-		.offset = offset,
-	};
-	struct kunit_vm_mmap_resource *vres;
+	int err;
 
-	vres = kunit_alloc_resource(test,
-				    kunit_vm_mmap_init,
-				    kunit_vm_mmap_free,
-				    GFP_KERNEL,
-				    &params);
-	if (vres)
-		return vres->addr;
-	return 0;
+	err = kunit_attach_mm();
+	if (err)
+		return err;
+
+	return vm_mmap(file, addr, len, prot, flag, offset);
 }
 EXPORT_SYMBOL_GPL(kunit_vm_mmap);
 

-- 
2.51.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ