[PATCH] kunit/usercopy: Disable testing on !CONFIG_MMU

0 views
Skip to first unread message

Kees Cook

unread,
Jun 17, 2024, 1:41:22 PMJun 17
to Brendan Higgins, Kees Cook, kernel test robot, David Gow, Rae Moar, Gustavo A. R. Silva, Andrew Morton, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-h...@vger.kernel.org, linu...@kvack.org, linux-...@vger.kernel.org
Since arch_pick_mmap_layout() is an inline for non-MMU systems, disable
this test there.

Reported-by: kernel test robot <l...@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202406160505...@intel.com/
Signed-off-by: Kees Cook <ke...@kernel.org>
---
Cc: Brendan Higgins <brendan...@linux.dev>
Cc: David Gow <davi...@google.com>
Cc: Rae Moar <rm...@google.com>
Cc: "Gustavo A. R. Silva" <gusta...@kernel.org>
Cc: Andrew Morton <ak...@linux-foundation.org>
Cc: linux-k...@vger.kernel.org
Cc: kuni...@googlegroups.com
Cc: linux-h...@vger.kernel.org
Cc: linu...@kvack.org
---
lib/kunit/user_alloc.c | 4 ++++
lib/usercopy_kunit.c | 5 +++++
mm/util.c | 2 ++
3 files changed, 11 insertions(+)

diff --git a/lib/kunit/user_alloc.c b/lib/kunit/user_alloc.c
index 76d3d1345ed7..ae935df09a5e 100644
--- a/lib/kunit/user_alloc.c
+++ b/lib/kunit/user_alloc.c
@@ -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;
diff --git a/lib/usercopy_kunit.c b/lib/usercopy_kunit.c
index 45f1e558c464..e819561a540d 100644
--- a/lib/usercopy_kunit.c
+++ b/lib/usercopy_kunit.c
@@ -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;
diff --git a/mm/util.c b/mm/util.c
index df37c47d9374..e70e8e439258 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -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
--
2.34.1

Kees Cook

unread,
Jun 19, 2024, 4:25:22 PM (13 days ago) Jun 19
to Shuah Khan, Kees Cook, kernel test robot, Brendan Higgins, David Gow, Rae Moar, Gustavo A. R. Silva, Andrew Morton, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-h...@vger.kernel.org, linu...@kvack.org, linux-...@vger.kernel.org
Since arch_pick_mmap_layout() is an inline for non-MMU systems, disable
this test there.

Reported-by: kernel test robot <l...@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202406160505...@intel.com/
Signed-off-by: Kees Cook <ke...@kernel.org>
---
Resending as v2 with Shuah in To:
---
Cc: Shuah Khan <sk...@linuxfoundation.org>

Rae Moar

unread,
Jun 20, 2024, 5:13:50 PM (12 days ago) Jun 20
to Kees Cook, Shuah Khan, kernel test robot, Brendan Higgins, David Gow, Gustavo A. R. Silva, Andrew Morton, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-h...@vger.kernel.org, linu...@kvack.org, linux-...@vger.kernel.org
On Wed, Jun 19, 2024 at 4:25 PM Kees Cook <ke...@kernel.org> wrote:
>
> Since arch_pick_mmap_layout() is an inline for non-MMU systems, disable
> this test there.
>
> Reported-by: kernel test robot <l...@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202406160505...@intel.com/
> Signed-off-by: Kees Cook <ke...@kernel.org>

Hello!

This looks good to me. And seems to fix the problem. Thanks for the fix!

Reviewed-by: Rae Moar <rm...@google.com>

-Rae

Kees Cook

unread,
Jun 27, 2024, 1:07:24 PM (5 days ago) Jun 27
to Shuah Khan, Rae Moar, kernel test robot, Brendan Higgins, David Gow, Gustavo A. R. Silva, Andrew Morton, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-h...@vger.kernel.org, linu...@kvack.org, linux-...@vger.kernel.org
Hi Shuah,

Can you please add this to your -next tree since it fixes test failures
on non-MMU systems, after commit cf6219ee889f ("usercopy: Convert
test_user_copy to KUnit test").

Thanks!

-Kees
--
Kees Cook

David Gow

unread,
12:05 AM (23 hours ago) 12:05 AM
to Kees Cook, Shuah Khan, kernel test robot, Brendan Higgins, Rae Moar, Gustavo A. R. Silva, Andrew Morton, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-h...@vger.kernel.org, linu...@kvack.org, linux-...@vger.kernel.org
On Thu, 20 Jun 2024 at 04:25, Kees Cook <ke...@kernel.org> wrote:
>
> Since arch_pick_mmap_layout() is an inline for non-MMU systems, disable
> this test there.
>
> Reported-by: kernel test robot <l...@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202406160505...@intel.com/
> Signed-off-by: Kees Cook <ke...@kernel.org>
> ---
> Resending as v2 with Shuah in To:
> ---
> Cc: Shuah Khan <sk...@linuxfoundation.org>
> Cc: Brendan Higgins <brendan...@linux.dev>
> Cc: David Gow <davi...@google.com>
> Cc: Rae Moar <rm...@google.com>
> Cc: "Gustavo A. R. Silva" <gusta...@kernel.org>
> Cc: Andrew Morton <ak...@linux-foundation.org>
> Cc: linux-k...@vger.kernel.org
> Cc: kuni...@googlegroups.com
> Cc: linux-h...@vger.kernel.org
> Cc: linu...@kvack.org
> ---

Reviewed-by: David Gow <davi...@google.com>

Cheers,
-- David

Shuah Khan

unread,
12:15 PM (11 hours ago) 12:15 PM
to David Gow, Kees Cook, kernel test robot, Brendan Higgins, Rae Moar, Gustavo A. R. Silva, Andrew Morton, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-h...@vger.kernel.org, linu...@kvack.org, linux-...@vger.kernel.org, Shuah Khan
Thank you both. Applied to linux-kselftest kunit branch for next.

thanks,
-- Shuah

Shuah Khan

unread,
12:18 PM (11 hours ago) 12:18 PM
to Kees Cook, Rae Moar, kernel test robot, Brendan Higgins, David Gow, Gustavo A. R. Silva, Andrew Morton, linux-k...@vger.kernel.org, kuni...@googlegroups.com, linux-h...@vger.kernel.org, linu...@kvack.org, linux-...@vger.kernel.org, Shuah Khan
On 6/27/24 11:07, Kees Cook wrote:
> Hi Shuah,
>
> Can you please add this to your -next tree since it fixes test failures
> on non-MMU systems, after commit cf6219ee889f ("usercopy: Convert
> test_user_copy to KUnit test").
>

Reply all
Reply to author
Forward
0 new messages