Skip to contentSkip to conversation

kasan: Emit different calls for instrumentable memintrinsics

PATCH Superseded Marco Elver 2 participants 2 messages Feb 13, 2023 – Feb 14, 2023

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 kasan: Emit different calls for instrumentable memintrinsics

Clang 15 will provide an option to prefix calls to memcpy/memset/memmove with __asan_ 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")

---
v3:
* Resend with actual fix.

v2:
* Use asan-kernel-mem-intrinsic-prefix=1, so that once GCC supports the param, it also works there (it needs the =1).

The Fixes tag is just there to show the dependency, and that people shouldn't apply this patch without 69d4c0d32186.

---
 scripts/Makefile.kasan | 7 +++++++
 1 file changed, 7 insertions(+)
scripts/Makefile.kasan +7 -0
index b9e94c5e7097..3b35a88af60d 100644
@@ -38,6 +38,13 @@ endif
 
 CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable))
 
+ifdef CONFIG_GENERIC_ENTRY
+# 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.
+CFLAGS_KASAN += $(call cc-param,asan-kernel-mem-intrinsic-prefix=1)
+endif
+
 endif # CONFIG_KASAN_GENERIC
 
 ifdef CONFIG_KASAN_SW_TAGS
Signature · 1 line
2.39.1.581.gbfd45094c4-goog
Acked-by on v3 1/1
#1 lore raw
Quoted 6 lines · Marco Elver

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

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

Quoted 6 lines

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")

Thanks!

Quoted 35 lines

---
v3:
* Resend with actual fix.

v2:
* Use asan-kernel-mem-intrinsic-prefix=1, so that once GCC supports the param, it also works there (it needs the =1).

The Fixes tag is just there to show the dependency, and that people shouldn't apply this patch without 69d4c0d32186.

---
 scripts/Makefile.kasan | 7 +++++++
 1 file changed, 7 insertions(+)
scripts/Makefile.kasan +7 -0
index b9e94c5e7097..3b35a88af60d 100644
@@ -38,6 +38,13 @@ endif
 
 CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable))
 
+ifdef CONFIG_GENERIC_ENTRY
+# 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.
+CFLAGS_KASAN += $(call cc-param,asan-kernel-mem-intrinsic-prefix=1)
+endif
+
 endif # CONFIG_KASAN_GENERIC
 
 ifdef CONFIG_KASAN_SW_TAGS
Signature · 1 line
2.39.1.581.gbfd45094c4-goog