Skip to contentSkip to conversation

mm: export copy_to_kernel_nofault

PATCH In review Arnd Bergmann 7 participants 10 messages Oct 18, 2024 – Jun 22, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: export copy_to_kernel_nofault

From: Arnd Bergmann <[email protected]>

This symbol is now used on the kasan test module, so it needs to be exported.

ERROR: modpost: "copy_to_kernel_nofault" [mm/kasan/kasan_test.ko] undefined!

Fixes 44749130ffb4 ("kasan: migrate copy_user_test to kunit")
---
 mm/maccess.c | 1 +
 1 file changed, 1 insertion(+)
mm/maccess.c +1 -0
index 3ca55ec63a6a..8f0906180a94 100644
@@ -82,6 +82,7 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size)
 	pagefault_enable();
 	return -EFAULT;
 }
+EXPORT_SYMBOL_GPL(copy_to_kernel_nofault);
 
 long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
 {
Signature · 1 line
2.39.5
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

This symbol is now used on the kasan test module, so it needs to be exported.

ERROR: modpost: "copy_to_kernel_nofault" [mm/kasan/kasan_test.ko] undefined!

Fixes 44749130ffb4 ("kasan: migrate copy_user_test to kunit")
---
  mm/maccess.c | 1 +
  1 file changed, 1 insertion(+)
mm/maccess.c +0 -0
index 3ca55ec63a6a..8f0906180a94 100644

mm/maccess.c long copy_to_kernel_nofault(void *dst, const void *src, size_t size) · line 88

Quoted 7 lines
mm/maccess.c +1 -0
@@ -82,6 +82,7 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size)
  	pagefault_enable();
  	return -EFAULT;
  }
+EXPORT_SYMBOL_GPL(copy_to_kernel_nofault);
 
  long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
  {
Signature · 3 lines
Cheers,

David / dhildenb
Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 27 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

This symbol is now used on the kasan test module, so it needs to be exported.

ERROR: modpost: "copy_to_kernel_nofault" [mm/kasan/kasan_test.ko] undefined!

Fixes 44749130ffb4 ("kasan: migrate copy_user_test to kunit")
---
 mm/maccess.c | 1 +
 1 file changed, 1 insertion(+)
mm/maccess.c +1 -1
index 3ca55ec63a6a..8f0906180a94 100644
@@ -82,6 +82,7 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size)
        pagefault_enable();
        return -EFAULT;
 }
+EXPORT_SYMBOL_GPL(copy_to_kernel_nofault);
 
 long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
 {
--
Quoted 2 lines

2.39.5

Thank you!

#3 lore raw
In reply to Arnd Bergmann
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

This symbol is now used on the kasan test module, so it needs to be exported.

ERROR: modpost: "copy_to_kernel_nofault" [mm/kasan/kasan_test.ko] undefined!

Meh, it would be great not to export internal helpers just because someone wants to test them. Please just mark that test built-in only instead.

#4 lore raw
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

Quoted 8 lines
Quoted 4 lines

This symbol is now used on the kasan test module, so it needs to be exported.

ERROR: modpost: "copy_to_kernel_nofault" [mm/kasan/kasan_test.ko] undefined!

Meh, it would be great not to export internal helpers just because someone wants to test them. Please just mark that test built-in only instead.

We have EXPORT_SYMBOL_IF_KUNIT. See include/kunit/visibility.h - that's more appropriate, and also adjust kasan_test.c to do MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING).

#5 lore raw
Quoted 10 lines · Marco Elver
Quoted 9 lines · Christoph Hellwig
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

This symbol is now used on the kasan test module, so it needs to be exported.

ERROR: modpost: "copy_to_kernel_nofault" [mm/kasan/kasan_test.ko] undefined!

Quoted 7 lines
Quoted 3 lines

Meh, it would be great not to export internal helpers just because someone wants to test them. Please just mark that test built-in only instead.

We have EXPORT_SYMBOL_IF_KUNIT. See include/kunit/visibility.h - that's more appropriate, and also adjust kasan_test.c to do MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING).

Thats a little better, but at least in this case I still think it is a very bad idea. copy_to_kernel_nofault is a perfect vector for exploit code to probe writing to kernel address without causing faults so it really should never ever be exported.

#6 lore raw
Quoted 16 lines · Christoph Hellwig
Quoted 14 lines · Marco Elver
Quoted 12 lines · Christoph Hellwig
Quoted 6 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

This symbol is now used on the kasan test module, so it needs to be exported.

ERROR: modpost: "copy_to_kernel_nofault" [mm/kasan/kasan_test.ko] undefined!

Meh, it would be great not to export internal helpers just because someone wants to test them. Please just mark that test built-in only instead.

Quoted 8 lines
Quoted 3 lines

We have EXPORT_SYMBOL_IF_KUNIT. See include/kunit/visibility.h - that's more appropriate, and also adjust kasan_test.c to do MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING).

Thats a little better, but at least in this case I still think it is a very bad idea. copy_to_kernel_nofault is a perfect vector for exploit code to probe writing to kernel address without causing faults so it really should never ever be exported.

Another alternative is to just #ifndef MODULE the offending test case, so it's only available if built-in. No need to just make the whole test built-in only. I know there are users of this particular test that rely on it being a module.

#7 lore raw
Quoted 4 lines · Marco Elver

Another alternative is to just #ifndef MODULE the offending test case, so it's only available if built-in. No need to just make the whole test built-in only. I know there are users of this particular test that rely on it being a module.

That sounds good to me.

maintainer
#8 lore raw
Quoted 7 lines · On Wed, 23 Oct 2024 00:05:36 -0700 Christoph Hellwig <[email protected]> wrote:
Quoted 4 lines · Marco Elver

Another alternative is to just #ifndef MODULE the offending test case, so it's only available if built-in. No need to just make the whole test built-in only. I know there are users of this particular test that rely on it being a module.

That sounds good to me.

We still don't have patch which does this, so this series is stalled.

Sabyrzhan, could you please consider this?

#9 lore raw
Quoted 9 lines · Andrew Morton
Quoted 6 lines · On Wed, 23 Oct 2024 00:05:36 -0700 Christoph Hellwig <[email protected]> wrote:
Quoted 4 lines · Marco Elver

Another alternative is to just #ifndef MODULE the offending test case, so it's only available if built-in. No need to just make the whole test built-in only. I know there are users of this particular test that rely on it being a module.

Quoted 5 lines
Quoted 1 line

That sounds good to me.

We still don't have patch which does this, so this series is stalled.

Sabyrzhan, could you please consider this?

I've just posted a follow-up that removes the exported symbol. See Message-Id: <[email protected]> Sorry for taking so long.