The patch titled Subject: mm, kasan: proper instrument _kernel_nofault has been added to the -mm mm-unstable branch. Its filename is mm-instrument-copy_from-to_kernel_nofault-fix.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-instrument-copy_from-to_kernel_nofault-fix.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Sabyrzhan Tasbolatov <snovitoll@xxxxxxxxx> Subject: mm, kasan: proper instrument _kernel_nofault Date: Mon, 30 Sep 2024 15:24:05 +0500 In commit 88ad9dc30bbf("mm, kasan: instrument copy_from/to_kernel_nofault"), both src and dst were checked which might lead to the false-positive reports. Regular instrument_read() for copy_from and instrument_write() for copy_to triggers KASAN reports in mm/kasan_test_c.c copy_from_to_kernel_nofault_oob() kunit test. Tested on x86_64, arm64 with CONFIG_KASAN_SW_TAGS using the latest linux-next tree, where this commit has been merged today. Link: https://lkml.kernel.org/r/20240930102405.2227124-1-snovitoll@xxxxxxxxx Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@xxxxxxxxx> Reported-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=210505 Cc: Andrey Konovalov <andreyknvl@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/maccess.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) --- a/mm/maccess.c~mm-instrument-copy_from-to_kernel_nofault-fix +++ a/mm/maccess.c @@ -32,7 +32,7 @@ long copy_from_kernel_nofault(void *dst, return -ERANGE; pagefault_disable(); - instrument_memcpy_before(dst, src, size); + instrument_read(src, size); if (!(align & 7)) copy_from_kernel_nofault_loop(dst, src, size, u64, Efault); if (!(align & 3)) @@ -40,7 +40,6 @@ long copy_from_kernel_nofault(void *dst, if (!(align & 1)) copy_from_kernel_nofault_loop(dst, src, size, u16, Efault); copy_from_kernel_nofault_loop(dst, src, size, u8, Efault); - instrument_memcpy_after(dst, src, size, 0); pagefault_enable(); return 0; Efault: @@ -65,7 +64,7 @@ long copy_to_kernel_nofault(void *dst, c align = (unsigned long)dst | (unsigned long)src; pagefault_disable(); - instrument_memcpy_before(dst, src, size); + instrument_write(dst, size); if (!(align & 7)) copy_to_kernel_nofault_loop(dst, src, size, u64, Efault); if (!(align & 3)) @@ -73,7 +72,6 @@ long copy_to_kernel_nofault(void *dst, c if (!(align & 1)) copy_to_kernel_nofault_loop(dst, src, size, u16, Efault); copy_to_kernel_nofault_loop(dst, src, size, u8, Efault); - instrument_memcpy_after(dst, src, size, 0); pagefault_enable(); return 0; Efault: _ Patches currently in -mm which might be from snovitoll@xxxxxxxxx are mm-instrument-copy_from-to_kernel_nofault.patch mm-instrument-copy_from-to_kernel_nofault-fix.patch