Re: [PATCH v2] mm: unexport globally copy_to_kernel_nofault
From: Andrew Morton
Date: Sun Jun 22 2025 - 14:20:22 EST
On Sun, 22 Jun 2025 19:11:42 +0500 Sabyrzhan Tasbolatov <snovitoll@xxxxxxxxx> wrote:
> `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.
The recent 707f853d7fa3 ("module: Provide
EXPORT_SYMBOL_GPL_FOR_MODULES() helper") quietly added a thing which
might be useful here. As far as I understand it, this will permit us
to export copy_to_kernel_nofault to kasan_test_c.o and to nothing else.
"might". It depends on how "exploit code" might get hold of the
symbol. Perhaps you/we can discuss this further. Is the problem that
copy_to_kernel_nofault() is non-static? Or it the problem that
"exploit code" is itself a kernel module?
In other words, a fuller investigation of how this export presently benefits
exploiters would help us understand how much
EXPORT_SYMBOL_GPL_FOR_MODULES() will improve the situation.