Skip to contentSkip to conversation

kunit/usercopy: Disable testing on !CONFIG_MMU

PATCH Superseded Kees Cook 1 participant 1 message Jun 17, 2024

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 kunit/usercopy: Disable testing on !CONFIG_MMU

Since arch_pick_mmap_layout() is an inline for non-MMU systems, disable this test there.

---
Cc: Brendan Higgins <[email protected]>
Cc: David Gow <[email protected]>
Cc: Rae Moar <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 lib/kunit/user_alloc.c | 4 ++++
 lib/usercopy_kunit.c   | 5 +++++
 mm/util.c              | 2 ++
 3 files changed, 11 insertions(+)
lib/kunit/user_alloc.c +4 -0
index 76d3d1345ed7..ae935df09a5e 100644
@@ -30,6 +30,10 @@ static int kunit_attach_mm(void)
 	if (current->mm)
 		return 0;
 
+	/* arch_pick_mmap_layout() is only sane with MMU systems. */
+	if (!IS_ENABLED(CONFIG_MMU))
+		return -EINVAL;
+
 	mm = mm_alloc();
 	if (!mm)
 		return -ENOMEM;
lib/usercopy_kunit.c +5 -0
index 45f1e558c464..e819561a540d 100644
@@ -290,6 +290,11 @@ static int usercopy_test_init(struct kunit *test)
 	struct usercopy_test_priv *priv;
 	unsigned long user_addr;
 
+	if (!IS_ENABLED(CONFIG_MMU)) {
+		kunit_skip(test, "Userspace allocation testing not available on non-MMU systems");
+		return 0;
+	}
+
 	priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);
 	test->priv = priv;
mm/util.c +2 -0
index df37c47d9374..e70e8e439258 100644
@@ -484,7 +484,9 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack)
 	clear_bit(MMF_TOPDOWN, &mm->flags);
 }
 #endif
+#ifdef CONFIG_MMU
 EXPORT_SYMBOL_IF_KUNIT(arch_pick_mmap_layout);
+#endif
 
 /**
  * __account_locked_vm - account locked pages to an mm's locked_vm
Signature · 1 line
2.34.1