Skip to contentSkip to conversation

kasan-emit-different-calls-for-instrumentable-memintrinsics.patch removed from -mm tree

merged mm-hotfixes-stable Andrew Morton 1 participant 1 message Mar 3, 2023

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: kasan: emit different calls for instrumentable memintrinsics
has been removed from the -mm tree. Its filename was
kasan-emit-different-calls-for-instrumentable-memintrinsics.patch

This patch was dropped because it was merged into the mm-hotfixes-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Marco Elver <[email protected]>
Subject: kasan: emit different calls for instrumentable memintrinsics
Date: Fri, 24 Feb 2023 09:59:39 +0100

Clang 15 provides an option to prefix memcpy/memset/memmove calls with __asan_/__hwasan_ in instrumented functions:
https://reviews.llvm.org/D122724

GCC will add support in future:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108777

Use it to regain KASAN instrumentation of memcpy/memset/memmove on architectures that require noinstr to be really free from instrumented mem*() functions (all GENERIC_ENTRY architectures).

Fixes 69d4c0d32186 ("entry, kasan, x86: Disallow overriding mem*() functions")
Cc Alexander Potapenko <[email protected]>
Cc Andrey Ryabinin <[email protected]>
Cc Borislav Petkov (AMD) <[email protected]>
Cc Dave Hansen <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jakub Jelinek <[email protected]>
Cc Kees Cook <[email protected]>
Cc Linux Kernel Functional Testing <[email protected]>
Cc Nathan Chancellor <[email protected]> # build only
Cc Nick Desaulniers <[email protected]>
Cc Nicolas Schier <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Vincenzo Frascino <[email protected]>

---

mm/kasan/kasan.h renamed from mm/kasan/kasan.h~kasan-emit-different-calls-for-instrumentable-memintrinsics +4 -0
@@ -666,4 +666,8 @@ void __hwasan_storeN_noabort(unsigned lo
 
 void __hwasan_tag_memory(unsigned long addr, u8 tag, unsigned long size);
 
+void *__hwasan_memset(void *addr, int c, size_t len);
+void *__hwasan_memmove(void *dest, const void *src, size_t len);
+void *__hwasan_memcpy(void *dest, const void *src, size_t len);
+
 #endif /* __MM_KASAN_KASAN_H */
mm/kasan/shadow.c renamed from mm/kasan/shadow.c~kasan-emit-different-calls-for-instrumentable-memintrinsics +11 -0
@@ -107,6 +107,17 @@ void *__asan_memcpy(void *dest, const vo
 }
 EXPORT_SYMBOL(__asan_memcpy);
 
+#ifdef CONFIG_KASAN_SW_TAGS
+void *__hwasan_memset(void *addr, int c, size_t len) __alias(__asan_memset);
+EXPORT_SYMBOL(__hwasan_memset);
+#ifdef __HAVE_ARCH_MEMMOVE
+void *__hwasan_memmove(void *dest, const void *src, size_t len) __alias(__asan_memmove);
+EXPORT_SYMBOL(__hwasan_memmove);
+#endif
+void *__hwasan_memcpy(void *dest, const void *src, size_t len) __alias(__asan_memcpy);
+EXPORT_SYMBOL(__hwasan_memcpy);
+#endif
+
 void kasan_poison(const void *addr, size_t size, u8 value, bool init)
 {
 	void *shadow_start, *shadow_end;
scripts/Makefile.kasan renamed from scripts/Makefile.kasan~kasan-emit-different-calls-for-instrumentable-memintrinsics +8 -0
@@ -38,6 +38,11 @@ endif
 
 CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable))
 
+# Instrument memcpy/memset/memmove calls by using instrumented __asan_mem*()
+# instead. With compilers that don't support this option, compiler-inserted
+# memintrinsics won't be checked by KASAN on GENERIC_ENTRY architectures.
+CFLAGS_KASAN += $(call cc-param,asan-kernel-mem-intrinsic-prefix=1)
+
 endif # CONFIG_KASAN_GENERIC
 
 ifdef CONFIG_KASAN_SW_TAGS
@@ -54,6 +59,9 @@ CFLAGS_KASAN := -fsanitize=kernel-hwaddr
 		$(call cc-param,hwasan-inline-all-checks=0) \
 		$(instrumentation_flags)
 
+# Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*().
+CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1)
+
 endif # CONFIG_KASAN_SW_TAGS
 
 export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE

_

Patches currently in -mm which might be from [email protected] are