kunit/usercopy: Disable testing on !CONFIG_MMU

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

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202406160505.uBge6TMY-lkp@intel.com/
Signed-off-by: Kees Cook <kees@kernel.org>
Reviewed-by: Rae Moar <rmoar@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
Kees Cook 2024-06-19 13:25:17 -07:00 committed by Shuah Khan
parent cf6219ee88
commit 4d6cf24832
3 changed files with 11 additions and 0 deletions

View File

@ -30,6 +30,10 @@ static int kunit_attach_mm(void)
if (current->mm) if (current->mm)
return 0; return 0;
/* arch_pick_mmap_layout() is only sane with MMU systems. */
if (!IS_ENABLED(CONFIG_MMU))
return -EINVAL;
mm = mm_alloc(); mm = mm_alloc();
if (!mm) if (!mm)
return -ENOMEM; return -ENOMEM;

View File

@ -290,6 +290,11 @@ static int usercopy_test_init(struct kunit *test)
struct usercopy_test_priv *priv; struct usercopy_test_priv *priv;
unsigned long user_addr; 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); priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, priv);
test->priv = priv; test->priv = priv;

View File

@ -484,7 +484,9 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack)
clear_bit(MMF_TOPDOWN, &mm->flags); clear_bit(MMF_TOPDOWN, &mm->flags);
} }
#endif #endif
#ifdef CONFIG_MMU
EXPORT_SYMBOL_IF_KUNIT(arch_pick_mmap_layout); EXPORT_SYMBOL_IF_KUNIT(arch_pick_mmap_layout);
#endif
/** /**
* __account_locked_vm - account locked pages to an mm's locked_vm * __account_locked_vm - account locked pages to an mm's locked_vm