kcov: Integrate with KMSAN

- kern_kcov.c needs to be compiled with -fsanitize=kernel-memory when
  KMSAN is configured since it calls into various other subsystems.
- Disable address and memory sanitizers in kcov(4)'s coverage sanitizer
  callbacks, as they do not provide useful checking.  Moreover, with
  KMSAN we may otherwise get false positives since the caller (coverage
  sanitizer runtime) is not instrumented.
- Disable KASAN and KMSAN interceptors in subr_coverage.c, as they do
  not provide any benefit but do introduce overhead when fuzzing.

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Mark Johnston 2021-09-14 14:29:27 -04:00
parent 272c4a4dc5
commit cf4670fe0b
3 changed files with 6 additions and 5 deletions

View File

@ -3826,7 +3826,7 @@ kern/kern_idle.c standard
kern/kern_intr.c standard
kern/kern_jail.c standard
kern/kern_kcov.c optional kcov \
compile-with "${NORMAL_C:N-fsanitize*}"
compile-with "${NORMAL_C:N-fsanitize*} ${NORMAL_C:M-fsanitize=kernel-memory}"
kern/kern_khelp.c standard
kern/kern_kthread.c standard
kern/kern_ktr.c optional ktr

View File

@ -35,7 +35,8 @@
* $FreeBSD$
*/
#ifdef KCSAN
/* Interceptors are required for KMSAN. */
#if defined(KASAN) || defined(KCSAN)
#define SAN_RUNTIME
#endif
@ -191,7 +192,7 @@ get_kinfo(struct thread *td)
return (info);
}
static void
static void __nosanitizeaddress __nosanitizememory
trace_pc(uintptr_t ret)
{
struct thread *td;
@ -223,7 +224,7 @@ trace_pc(uintptr_t ret)
buf[0] = index + 1;
}
static bool
static bool __nosanitizeaddress __nosanitizememory
trace_cmp(uint64_t type, uint64_t arg1, uint64_t arg2, uint64_t ret)
{
struct thread *td;

View File

@ -35,7 +35,7 @@
* $FreeBSD$
*/
#ifdef KCSAN
#ifdef SAN_NEEDS_INTERCEPTORS
#define SAN_RUNTIME
#endif