mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-01-11 09:00:12 +00:00
mm: unexport globally copy_to_kernel_nofault
copy_to_kernel_nofault() is an internal helper which should not be visible to loadable modules – exporting it would give exploit code a cheap oracle to probe kernel addresses. Instead, keep the helper un-exported and compile the kunit case that exercises it only when mm/kasan/kasan_test.o is linked into vmlinux. [snovitoll@gmail.com: add a brief comment to `#ifndef MODULE`] Link: https://lkml.kernel.org/r/20250622141142.79332-1-snovitoll@gmail.com Link: https://lkml.kernel.org/r/20250622051906.67374-1-snovitoll@gmail.com Fixes: ca79a00bb9a8 ("kasan: migrate copy_user_test to kunit") Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com> Suggested-by: Christoph Hellwig <hch@infradead.org> Suggested-by: Marco Elver <elver@google.com> Acked-by: David Hildenbrand <david@redhat.com> Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com> Cc: Alexander Potapenko <glider@google.com> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
d8e77a0b63
commit
d2ef92cd2a
@ -1977,6 +1977,11 @@ static void rust_uaf(struct kunit *test)
|
||||
KUNIT_EXPECT_KASAN_FAIL(test, kasan_test_rust_uaf());
|
||||
}
|
||||
|
||||
/*
|
||||
* copy_to_kernel_nofault() is an internal helper available when
|
||||
* kasan_test is built-in, so it must not be visible to loadable modules.
|
||||
*/
|
||||
#ifndef MODULE
|
||||
static void copy_to_kernel_nofault_oob(struct kunit *test)
|
||||
{
|
||||
char *ptr;
|
||||
@ -2011,6 +2016,7 @@ static void copy_to_kernel_nofault_oob(struct kunit *test)
|
||||
|
||||
kfree(ptr);
|
||||
}
|
||||
#endif /* !MODULE */
|
||||
|
||||
static void copy_user_test_oob(struct kunit *test)
|
||||
{
|
||||
@ -2131,7 +2137,9 @@ static struct kunit_case kasan_kunit_test_cases[] = {
|
||||
KUNIT_CASE(match_all_not_assigned),
|
||||
KUNIT_CASE(match_all_ptr_tag),
|
||||
KUNIT_CASE(match_all_mem_tag),
|
||||
#ifndef MODULE
|
||||
KUNIT_CASE(copy_to_kernel_nofault_oob),
|
||||
#endif
|
||||
KUNIT_CASE(rust_uaf),
|
||||
KUNIT_CASE(copy_user_test_oob),
|
||||
{}
|
||||
|
||||
@ -82,7 +82,6 @@ Efault:
|
||||
pagefault_enable();
|
||||
return -EFAULT;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(copy_to_kernel_nofault);
|
||||
|
||||
long strncpy_from_kernel_nofault(char *dst, const void *unsafe_addr, long count)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user