Skip to contentSkip to conversation

usercopy: Convert test_user_copy to KUnit test

PATCH In review Kees Cook 5 participants 12 messages Jun 12, 2024 – Jun 27, 2024

Subsystems (7)
lore
Share & tools
lore

Kees Cook

author maintainer
#0 lore raw

v3 cover usercopy: Convert test_user_copy to KUnit test

Hi,

This builds on the proposal[1] from Mark and lets me convert the existing usercopy selftest to KUnit. Besides adding this basic test to the KUnit collection, it also opens the door for execve testing (which depends on having a functional current->mm), and should provide the basic infrastructure for adding Mark's much more complete usercopy tests.

v3:
- use MEMEQ KUnit helper (David)
- exclude pathological address confusion test for systems with separate address spaces, noticed by David
- add KUnit-conditional exports for alloc_mm() and arch_pick_mmap_layout() noticed by 0day
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

-Kees

[1] https://lore.kernel.org/lkml/[email protected]/

Kees Cook (2):
kunit: test: Add vm_mmap() allocation resource manager
usercopy: Convert test_user_copy to KUnit test

 MAINTAINERS                                |   1 +
 include/kunit/test.h                       |  17 ++
 kernel/fork.c                              |   3 +
 lib/Kconfig.debug                          |  21 +-
 lib/Makefile                               |   2 +-
 lib/kunit/Makefile                         |   1 +
 lib/kunit/user_alloc.c                     | 113 +++++++++
 lib/{test_user_copy.c => usercopy_kunit.c} | 282 ++++++++++-----------
 mm/util.c                                  |   3 +
 9 files changed, 288 insertions(+), 155 deletions(-)
 create mode 100644 lib/kunit/user_alloc.c
 rename lib/{test_user_copy.c => usercopy_kunit.c} (46%)
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v3 1/2 kunit: test: Add vm_mmap() allocation resource manager

For tests that need to allocate using vm_mmap() (e.g. usercopy and execve), provide the interface to have the allocation tracked by KUnit itself. This requires bringing up a placeholder userspace mm.

This combines my earlier attempt at this with Mark Rutland's version[1].

Normally alloc_mm() and arch_pick_mmap_layout() aren't exported for modules, so export these only for KUnit testing.

---
 include/kunit/test.h   |  17 +++++++
 kernel/fork.c          |   3 ++
 lib/kunit/Makefile     |   1 +
 lib/kunit/user_alloc.c | 113 +++++++++++++++++++++++++++++++++++++++++
 mm/util.c              |   3 ++
 5 files changed, 137 insertions(+)
 create mode 100644 lib/kunit/user_alloc.c
include/kunit/test.h +17 -0
index e32b4cb7afa2..ec61cad6b71d 100644
@@ -480,6 +480,23 @@ static inline void *kunit_kcalloc(struct kunit *test, size_t n, size_t size, gfp
 	return kunit_kmalloc_array(test, n, size, gfp | __GFP_ZERO);
 }
 
+/**
+ * kunit_vm_mmap() - Allocate KUnit-tracked vm_mmap() area
+ * @test: The test context object.
+ * @file: struct file pointer to map from, if any
+ * @addr: desired address, if any
+ * @len: how many bytes to allocate
+ * @prot: mmap PROT_* bits
+ * @flag: mmap flags
+ * @offset: offset into @file to start mapping from.
+ *
+ * See vm_mmap() for more information.
+ */
+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);
+
 void kunit_cleanup(struct kunit *test);
 
 void __printf(2, 3) kunit_log_append(struct string_stream *log, const char *fmt, ...);
kernel/fork.c +3 -0
index 99076dbe27d8..cea203197136 100644
@@ -115,6 +115,8 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/task.h>
 
+#include <kunit/visibility.h>
+
 /*
  * Minimum number of threads to boot the kernel
  */
@@ -1334,6 +1336,7 @@ struct mm_struct *mm_alloc(void)
 	memset(mm, 0, sizeof(*mm));
 	return mm_init(mm, current, current_user_ns());
 }
+EXPORT_SYMBOL_IF_KUNIT(mm_alloc);
 
 static inline void __mmput(struct mm_struct *mm)
 {
lib/kunit/Makefile +1 -0
index 309659a32a78..56dd67dc6e57 100644
@@ -2,6 +2,7 @@ obj-$(CONFIG_KUNIT) +=			kunit.o
 
 kunit-objs +=				test.o \
 					resource.o \
+					user_alloc.o \
 					static_stub.o \
 					string-stream.o \
 					assert.o \
lib/kunit/user_alloc.c new file +113 -0

113 lines not on this page · raw message

mm/util.c +3 -0
index c9e519e6811f..df37c47d9374 100644
@@ -26,6 +26,8 @@
 
 #include <linux/uaccess.h>
 
+#include <kunit/visibility.h>
+
 #include "internal.h"
 #include "swap.h"
 
@@ -482,6 +484,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack)
 	clear_bit(MMF_TOPDOWN, &mm->flags);
 }
 #endif
+EXPORT_SYMBOL_IF_KUNIT(arch_pick_mmap_layout);
 
 /**
  * __account_locked_vm - account locked pages to an mm's locked_vm
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH v3 2/2 usercopy: Convert test_user_copy to KUnit test

In reply to Kees Cook

Convert the runtime tests of hardened usercopy to standard KUnit tests.

Additionally disable usercopy_test_invalid() for systems with separate address spaces (or no MMU) since it's not sensible to test for address confusion there (e.g. m68k).

---
 MAINTAINERS                                |   1 +
 lib/Kconfig.debug                          |  21 +-
 lib/Makefile                               |   2 +-
 lib/{test_user_copy.c => usercopy_kunit.c} | 282 ++++++++++-----------
 4 files changed, 151 insertions(+), 155 deletions(-)
 rename lib/{test_user_copy.c => usercopy_kunit.c} (46%)
MAINTAINERS +1 -0
index 8754ac2c259d..0cd171ec6010 100644
@@ -11962,6 +11962,7 @@ F:	arch/*/configs/hardening.config
 F:	include/linux/overflow.h
 F:	include/linux/randomize_kstack.h
 F:	kernel/configs/hardening.config
+F:	lib/usercopy_kunit.c
 F:	mm/usercopy.c
 K:	\b(add|choose)_random_kstack_offset\b
 K:	\b__check_(object_size|heap_object)\b
lib/Kconfig.debug +9 -12
index 59b6765d86b8..561e346f5cb0 100644
@@ -2505,18 +2505,6 @@ config TEST_VMALLOC
 
 	  If unsure, say N.
 
-config TEST_USER_COPY
-	tristate "Test user/kernel boundary protections"
-	depends on m
-	help
-	  This builds the "test_user_copy" module that runs sanity checks
-	  on the copy_to/from_user infrastructure, making sure basic
-	  user/kernel boundary testing is working. If it fails to load,
-	  a regression has been detected in the user/kernel memory boundary
-	  protections.
-
-	  If unsure, say N.
-
 config TEST_BPF
 	tristate "Test BPF filter functionality"
 	depends on m && NET
@@ -2814,6 +2802,15 @@ config SIPHASH_KUNIT_TEST
 	  This is intended to help people writing architecture-specific
 	  optimized versions.  If unsure, say N.
 
+config USERCOPY_KUNIT_TEST
+	tristate "KUnit Test for user/kernel boundary protections"
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the "usercopy_kunit" module that runs sanity checks
+	  on the copy_to/from_user infrastructure, making sure basic
+	  user/kernel boundary testing is working.
+
 config TEST_UDELAY
 	tristate "udelay test driver"
 	help
lib/Makefile +1 -1
index 3b1769045651..fae5cc67b95a 100644
@@ -78,7 +78,6 @@ obj-$(CONFIG_TEST_LKM) += test_module.o
 obj-$(CONFIG_TEST_VMALLOC) += test_vmalloc.o
 obj-$(CONFIG_TEST_RHASHTABLE) += test_rhashtable.o
 obj-$(CONFIG_TEST_SORT) += test_sort.o
-obj-$(CONFIG_TEST_USER_COPY) += test_user_copy.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_keys.o
 obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
 obj-$(CONFIG_TEST_DYNAMIC_DEBUG) += test_dynamic_debug.o
@@ -388,6 +387,7 @@ CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-truncation)
 CFLAGS_fortify_kunit.o += $(DISABLE_STRUCTLEAK_PLUGIN)
 obj-$(CONFIG_FORTIFY_KUNIT_TEST) += fortify_kunit.o
 obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o
+obj-$(CONFIG_USERCOPY_KUNIT_TEST) += usercopy_kunit.o
 
 obj-$(CONFIG_GENERIC_LIB_DEVMEM_IS_ALLOWED) += devmem_is_allowed.o
 
lib/usercopy_kunit.c renamed from lib/test_user_copy.c +140 -142

402 lines not on this page · raw message

Signature · 1 line
2.34.1
#10 lore raw
In reply to Kees Cook
Quoted 18 lines · Kees Cook

Hi,

This builds on the proposal[1] from Mark and lets me convert the existing usercopy selftest to KUnit. Besides adding this basic test to the KUnit collection, it also opens the door for execve testing (which depends on having a functional current->mm), and should provide the basic infrastructure for adding Mark's much more complete usercopy tests.

v3:
- use MEMEQ KUnit helper (David)
- exclude pathological address confusion test for systems with separate address spaces, noticed by David
- add KUnit-conditional exports for alloc_mm() and arch_pick_mmap_layout() noticed by 0day
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

Quoted 3 lines

-Kees

[1] https://lore.kernel.org/lkml/[email protected]/

Thanks! This looks good to me (and passes everything here). Unless there's a compelling reason not to, I think we can take this via the KUnit tree.

Cheers,
-- David

author maintainer
#11 lore raw
Quoted 19 lines · David Gow
Quoted 18 lines · Kees Cook

Hi,

This builds on the proposal[1] from Mark and lets me convert the existing usercopy selftest to KUnit. Besides adding this basic test to the KUnit collection, it also opens the door for execve testing (which depends on having a functional current->mm), and should provide the basic infrastructure for adding Mark's much more complete usercopy tests.

v3:
- use MEMEQ KUnit helper (David)
- exclude pathological address confusion test for systems with separate address spaces, noticed by David
- add KUnit-conditional exports for alloc_mm() and arch_pick_mmap_layout() noticed by 0day
v2: https://lore.kernel.org/lkml/[email protected]/
v1: https://lore.kernel.org/lkml/[email protected]/

Quoted 7 lines
Quoted 3 lines

-Kees

[1] https://lore.kernel.org/lkml/[email protected]/

Thanks! This looks good to me (and passes everything here). Unless there's a compelling reason not to, I think we can take this via the KUnit tree.

That would be lovely, thank you! :)

Signature · 1 line
Kees Cook
maintainer
#5 lore raw
In reply to Kees Cook
Quoted 58 lines · Kees Cook

Convert the runtime tests of hardened usercopy to standard KUnit tests.

Additionally disable usercopy_test_invalid() for systems with separate address spaces (or no MMU) since it's not sensible to test for address confusion there (e.g. m68k).

---
  MAINTAINERS                                |   1 +
  lib/Kconfig.debug                          |  21 +-
  lib/Makefile                               |   2 +-
  lib/{test_user_copy.c => usercopy_kunit.c} | 282 ++++++++++-----------
  4 files changed, 151 insertions(+), 155 deletions(-)

rename lib/{test_user_copy.c => usercopy_kunit.c} (46%)

MAINTAINERS +1 -0
index 8754ac2c259d..0cd171ec6010 100644
@@ -11962,6 +11962,7 @@ F:	arch/*/configs/hardening.config
  F:	include/linux/overflow.h
  F:	include/linux/randomize_kstack.h
  F:	kernel/configs/hardening.config
+F:	lib/usercopy_kunit.c
  F:	mm/usercopy.c
  K:	\b(add|choose)_random_kstack_offset\b
  K:	\b__check_(object_size|heap_object)\b
lib/Kconfig.debug +0 -12
index 59b6765d86b8..561e346f5cb0 100644
@@ -2505,18 +2505,6 @@ config TEST_VMALLOC
 
  	  If unsure, say N.
 
-config TEST_USER_COPY
-	tristate "Test user/kernel boundary protections"
-	depends on m
-	help
-	  This builds the "test_user_copy" module that runs sanity checks
-	  on the copy_to/from_user infrastructure, making sure basic
-	  user/kernel boundary testing is working. If it fails to load,
-	  a regression has been detected in the user/kernel memory boundary
-	  protections.
-
-	  If unsure, say N.
-
  config TEST_BPF
  	tristate "Test BPF filter functionality"
  	depends on m && NET
@@ -2814,6 +2802,15 @@ config SIPHASH_KUNIT_TEST
  	  This is intended to help people writing architecture-specific
  	  optimized versions.  If unsure, say N.

lib/Kconfig.debug config SIPHASH_KUNIT_TEST · line 2813

Quoted 10 lines
lib/Kconfig.debug +9 -0
 
+config USERCOPY_KUNIT_TEST
+	tristate "KUnit Test for user/kernel boundary protections"
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the "usercopy_kunit" module that runs sanity checks
+	  on the copy_to/from_user infrastructure, making sure basic
+	  user/kernel boundary testing is working.
+

Please carry the following line forward as well to be complete assuming it is relevant.

If unsure, say N.

thanks,
-- Shuah

author maintainer
#6 lore raw
Quoted 70 lines · Shuah Khan
Quoted 55 lines · Kees Cook

Convert the runtime tests of hardened usercopy to standard KUnit tests.

Additionally disable usercopy_test_invalid() for systems with separate address spaces (or no MMU) since it's not sensible to test for address confusion there (e.g. m68k).

---
  MAINTAINERS                                |   1 +
  lib/Kconfig.debug                          |  21 +-
  lib/Makefile                               |   2 +-
  lib/{test_user_copy.c => usercopy_kunit.c} | 282 ++++++++++-----------
  4 files changed, 151 insertions(+), 155 deletions(-)

rename lib/{test_user_copy.c => usercopy_kunit.c} (46%)

MAINTAINERS +1 -0
index 8754ac2c259d..0cd171ec6010 100644
@@ -11962,6 +11962,7 @@ F:	arch/*/configs/hardening.config
  F:	include/linux/overflow.h
  F:	include/linux/randomize_kstack.h
  F:	kernel/configs/hardening.config
+F:	lib/usercopy_kunit.c
  F:	mm/usercopy.c
  K:	\b(add|choose)_random_kstack_offset\b
  K:	\b__check_(object_size|heap_object)\b
lib/Kconfig.debug +0 -12
index 59b6765d86b8..561e346f5cb0 100644
@@ -2505,18 +2505,6 @@ config TEST_VMALLOC
  	  If unsure, say N.
-config TEST_USER_COPY
-	tristate "Test user/kernel boundary protections"
-	depends on m
-	help
-	  This builds the "test_user_copy" module that runs sanity checks
-	  on the copy_to/from_user infrastructure, making sure basic
-	  user/kernel boundary testing is working. If it fails to load,
-	  a regression has been detected in the user/kernel memory boundary
-	  protections.
-
-	  If unsure, say N.
-
  config TEST_BPF
  	tristate "Test BPF filter functionality"
  	depends on m && NET
@@ -2814,6 +2802,15 @@ config SIPHASH_KUNIT_TEST
  	  This is intended to help people writing architecture-specific

lib/Kconfig.debug config SIPHASH_KUNIT_TEST · line 2812

Quoted 10 lines
lib/Kconfig.debug +9 -0
  	  optimized versions.  If unsure, say N.
+config USERCOPY_KUNIT_TEST
+	tristate "KUnit Test for user/kernel boundary protections"
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the "usercopy_kunit" module that runs sanity checks
+	  on the copy_to/from_user infrastructure, making sure basic
+	  user/kernel boundary testing is working.
+

Please carry the following line forward as well to be complete assuming it is relevant.

Quoted 1 line

If unsure, say N.

I've explicitly removed that because it would be repetitive if it were included for all KUnit tests.

Signature · 1 line
Kees Cook
maintainer
#7 lore raw
Quoted 71 lines · Kees Cook
Quoted 70 lines · Shuah Khan
Quoted 55 lines · Kees Cook

Convert the runtime tests of hardened usercopy to standard KUnit tests.

Additionally disable usercopy_test_invalid() for systems with separate address spaces (or no MMU) since it's not sensible to test for address confusion there (e.g. m68k).

---
   MAINTAINERS                                |   1 +
   lib/Kconfig.debug                          |  21 +-
   lib/Makefile                               |   2 +-
   lib/{test_user_copy.c => usercopy_kunit.c} | 282 ++++++++++-----------
   4 files changed, 151 insertions(+), 155 deletions(-)

rename lib/{test_user_copy.c => usercopy_kunit.c} (46%)

MAINTAINERS +1 -0
index 8754ac2c259d..0cd171ec6010 100644
@@ -11962,6 +11962,7 @@ F:	arch/*/configs/hardening.config
   F:	include/linux/overflow.h
   F:	include/linux/randomize_kstack.h
   F:	kernel/configs/hardening.config
+F:	lib/usercopy_kunit.c
   F:	mm/usercopy.c
   K:	\b(add|choose)_random_kstack_offset\b
   K:	\b__check_(object_size|heap_object)\b
lib/Kconfig.debug +0 -12
index 59b6765d86b8..561e346f5cb0 100644
@@ -2505,18 +2505,6 @@ config TEST_VMALLOC
   	  If unsure, say N.
-config TEST_USER_COPY
-	tristate "Test user/kernel boundary protections"
-	depends on m
-	help
-	  This builds the "test_user_copy" module that runs sanity checks
-	  on the copy_to/from_user infrastructure, making sure basic
-	  user/kernel boundary testing is working. If it fails to load,
-	  a regression has been detected in the user/kernel memory boundary
-	  protections.
-
-	  If unsure, say N.
-
   config TEST_BPF
   	tristate "Test BPF filter functionality"
   	depends on m && NET
@@ -2814,6 +2802,15 @@ config SIPHASH_KUNIT_TEST
   	  This is intended to help people writing architecture-specific

lib/Kconfig.debug config SIPHASH_KUNIT_TEST · line 2812

Quoted 10 lines
lib/Kconfig.debug +9 -0
   	  optimized versions.  If unsure, say N.
+config USERCOPY_KUNIT_TEST
+	tristate "KUnit Test for user/kernel boundary protections"
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds the "usercopy_kunit" module that runs sanity checks
+	  on the copy_to/from_user infrastructure, making sure basic
+	  user/kernel boundary testing is working.
+

Please carry the following line forward as well to be complete assuming it is relevant.

Quoted 5 lines
Quoted 1 line

If unsure, say N.

I've explicitly removed that because it would be repetitive if it were included for all KUnit tests.

Thanks for the explanation.

thanks,
-- Shuah

#8 lore raw
In reply to Kees Cook
Quoted 13 lines · Kees Cook

Convert the runtime tests of hardened usercopy to standard KUnit tests.

Additionally disable usercopy_test_invalid() for systems with separate address spaces (or no MMU) since it's not sensible to test for address confusion there (e.g. m68k).

---

...

lib/usercopy_kunit.c static int __init test_user_copy_init(void) · line 329

Quoted 3 lines
lib/usercopy_kunit.c renamed from lib/test_user_copy.c +2 -0
+kunit_test_suites(&usercopy_test_suite);
+MODULE_AUTHOR("Kees Cook <[email protected]>");
  MODULE_LICENSE("GPL");

Can you add the missing MODULE_DESCRIPTION() to remove the W=1 warning?

The fix to the current file is part of:
https://lore.kernel.org/all/[email protected]/

author maintainer
#9 lore raw
Quoted 15 lines · Jeff Johnson
Quoted 13 lines · Kees Cook

Convert the runtime tests of hardened usercopy to standard KUnit tests.

Additionally disable usercopy_test_invalid() for systems with separate address spaces (or no MMU) since it's not sensible to test for address confusion there (e.g. m68k).

---

...

Quoted 8 lines

lib/usercopy_kunit.c static int __init test_user_copy_init(void) · line 329

Quoted 3 lines
lib/usercopy_kunit.c renamed from lib/test_user_copy.c +2 -0
+kunit_test_suites(&usercopy_test_suite);
+MODULE_AUTHOR("Kees Cook <[email protected]>");
  MODULE_LICENSE("GPL");

Can you add the missing MODULE_DESCRIPTION() to remove the W=1 warning?

The fix to the current file is part of:
https://lore.kernel.org/all/[email protected]/

Thanks for the reminder! I've split it out and sent a separate patch to Shuah.

Signature · 1 line
Kees Cook
#2 lore raw

Re: [PATCH v3 1/2] kunit: test: Add vm_mmap() allocation resource manager

In reply to Kees Cook

Hi,

Quoted 10 lines · Kees Cook

For tests that need to allocate using vm_mmap() (e.g. usercopy and execve), provide the interface to have the allocation tracked by KUnit itself. This requires bringing up a placeholder userspace mm.

This combines my earlier attempt at this with Mark Rutland's version[1].

Normally alloc_mm() and arch_pick_mmap_layout() aren't exported for modules, so export these only for KUnit testing.

FWIW, not sure I understand what the above link has to do with this patch.

Quoted 4 lines

This patch results in a build failure for nommu_kc705_defconfig if kunit tests are also enabled.

ERROR: modpost: vmlinux: local symbol 'arch_pick_mmap_layout' was exported

If CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT=n, CONFIG_MMU=n, and CONFIG_KUNIT=y, arch_pick_mmap_layout is exported. However, if CONFIG_MMU=n, it is declared as static inline function.

Guenter

---
bisect log:

# bad: [b992b79ca8bc336fa8e2c80990b5af80ed8f36fd] Add linux-next specific files for 20240620
# good: [6ba59ff4227927d3a8530fc2973b80e94b54d58f] Linux 6.10-rc4
git bisect start 'HEAD' 'v6.10-rc4'
# good: [c02e717c5a89654b244fec58bb5cda32770966b5] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git
git bisect good c02e717c5a89654b244fec58bb5cda32770966b5
# good: [29e7d78253b7ebf4b76fcf6d95e227d0b0c57dc0] Merge branch 'msm-next' of https://gitlab.freedesktop.org/drm/msm.git
git bisect good 29e7d78253b7ebf4b76fcf6d95e227d0b0c57dc0
# good: [bf8fd0d956bfcbf4fd6ff063366374c4bf87d806] Merge branch 'non-rcu/next' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git
git bisect good bf8fd0d956bfcbf4fd6ff063366374c4bf87d806
# good: [1110f16317b1e0742521eaef5613eb1eb17f55ca] Merge branch 'icc-next' of git://git.kernel.org/pub/scm/linux/kernel/git/djakov/icc.git
git bisect good 1110f16317b1e0742521eaef5613eb1eb17f55ca
# good: [63f3716198e5644713748d83e6a6df3b4a6a3b10] Merge branch 'gpio/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git
git bisect good 63f3716198e5644713748d83e6a6df3b4a6a3b10
# bad: [91b48d9adafddb242264ba19c0bae6e23f71b18a] Merge branch 'kunit' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git
git bisect bad 91b48d9adafddb242264ba19c0bae6e23f71b18a
# good: [9b401f4a7170125365160c9af267a41ff6b39001] pinctrl: ti: ti-iodelay: fix possible memory leak when pinctrl_enable() fails git bisect good 9b401f4a7170125365160c9af267a41ff6b39001
# good: [1963f932d368f18185466979cc0bc89414d798e7] Merge branch 'pwm/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git
git bisect good 1963f932d368f18185466979cc0bc89414d798e7
# good: [f91869accbe23a2bb08712b7262fa61eab716d42] selftests/resctrl: Simplify bandwidth report type handling
git bisect good f91869accbe23a2bb08712b7262fa61eab716d42
# good: [cbf284291604e818424f45dbdf6a8a705b5480ad] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git
git bisect good cbf284291604e818424f45dbdf6a8a705b5480ad
# good: [a5217468214c228b89da37291de604cd756914ab] kunit: add missing MODULE_DESCRIPTION() macros to core modules
git bisect good a5217468214c228b89da37291de604cd756914ab
# bad: [51104c19d8570eb23208e08eac0e9ae09ced1c15] kunit: test: Add vm_mmap() allocation resource manager
git bisect bad 51104c19d8570eb23208e08eac0e9ae09ced1c15
# good: [425ae3ab5a1fa744a00680f059cf1accaaaecb28] list: test: add the missing MODULE_DESCRIPTION() macro
git bisect good 425ae3ab5a1fa744a00680f059cf1accaaaecb28

# first bad commit: [51104c19d8570eb23208e08eac0e9ae09ced1c15] kunit: test: Add vm_mmap() allocation resource manager
author maintainer
#3 lore raw

Re: [PATCH v3 1/2] kunit: test: Add vm_mmap() allocation resource manager

Quoted 7 lines · Guenter Roeck

Hi,

Quoted 4 lines · Kees Cook

For tests that need to allocate using vm_mmap() (e.g. usercopy and execve), provide the interface to have the allocation tracked by KUnit itself. This requires bringing up a placeholder userspace mm.

Quoted 8 lines
Quoted 6 lines

This combines my earlier attempt at this with Mark Rutland's version[1].

Normally alloc_mm() and arch_pick_mmap_layout() aren't exported for modules, so export these only for KUnit testing.

FWIW, not sure I understand what the above link has to do with this patch.

Both the above Link and this patch were implementing KUnit usercopy tests (and the required infrastructure).

Quoted 6 lines
Quoted 5 lines
Quoted 8 lines

This patch results in a build failure for nommu_kc705_defconfig if kunit tests are also enabled.

ERROR: modpost: vmlinux: local symbol 'arch_pick_mmap_layout' was exported

If CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT=n, CONFIG_MMU=n, and CONFIG_KUNIT=y, arch_pick_mmap_layout is exported. However, if CONFIG_MMU=n, it is declared as static inline function.

I replied in the other thread too, but this has had a fix pending:
https://lore.kernel.org/lkml/202406271005.4E767DAE@keescook/

I pinged the patch again today.

-Kees

Signature · 1 line
Kees Cook