NetBSD/src BJshPFEsys/arch/amd64/amd64 cpufunc.S spl.S, sys/arch/amd64/conf GENERIC Makefile.amd64

   Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized
   memory used by the kernel at run time, and just like kASan and kCSan, it
   is an excellent feature. It has already detected 38 uninitialized variables
   in the kernel during my testing, which I have since discreetly fixed.

   We use two shadows:
    - "shad", to track uninitialized memory with a bit granularity (1:1).
      Each bit set to 1 in the shad corresponds to one uninitialized bit of
      real kernel memory.
    - "orig", to track the origin of the memory with a 4-byte granularity
      (1:1). Each uint32_t cell in the orig indicates the origin of the
      associated uint32_t of real kernel memory.

   The memory consumption of these shadows is consequent, so at least 4GB of
   RAM is recommended to run kMSan.

   The compiler inserts calls to specific __msan_* functions on each memory
   access, to manage both the shad and the orig and detect uninitialized
   memory accesses that change the execution flow (like an "if" on an
   uninitialized variable).

   We mark as uninit several types of memory buffers (stack, pools, kmem,
   malloc, uvm_km), and check each buffer passed to copyout, copyoutstr,
   bwrite, if_transmit_lock and DMA operations, to detect uninitialized memory
   that leaves the system. This allows us to detect kernel info leaks in a way
   that is more efficient and also more user-friendly than KLEAK.

   Contrary to kASan, kMSan requires comprehensive coverage, ie we cannot
   tolerate having one non-instrumented function, because this could cause
   false positives. kMSan cannot instrument ASM functions, so I converted
   most of them to __asm__ inlines, which kMSan is able to instrument. Those
   that remain receive special treatment.

   Contrary to kASan again, kMSan uses a TLS, so we must context-switch this
   TLS during interrupts. We use different contexts depending on the interrupt
   level.

   The orig tracks precisely the origin of a buffer. We use a special encoding
   for the orig values, and pack together in each uint32_t cell of the orig:
    - a code designating the type of memory (Stack, Pool, etc), and
    - a compressed pointer, which points either (1) to a string containing
      the name of the variable associated with the cell, or (2) to an area
      in the kernel .text section which we resolve to a symbol name + offset.

   This encoding allows us not to consume extra memory for associating
   information with each cell, and produces a precise output, that can tell
   for example the name of an uninitialized variable on the stack, the
   function in which it was pushed on the stack, and the function where we
   accessed this uninitialized variable.

   kMSan is available with LLVM, but not with GCC.

   The code is organized in a way that is similar to kASan and kCSan, so it
   means that other architectures than amd64 can be supported.
VersionDeltaFile
1.1+1,356-0sys/kern/subr_msan.c
1.1+241-0sys/arch/amd64/include/msan.h
1.17+85-1sys/sys/atomic.h
1.1+85-0sys/sys/msan.h
1.46+66-3sys/arch/amd64/include/frameasm.h
1.262+50-5sys/kern/subr_pool.c
1.11+54-1sys/sys/bus_proto.h
1.47+19-1sys/arch/amd64/amd64/cpufunc.S
1.65+19-1sys/arch/amd64/include/cpu.h
1.289+18-2sys/sys/systm.h
1.134+18-1sys/lib/libkern/libkern.h
1.42+16-1sys/arch/amd64/amd64/spl.S
1.158+13-4sys/kern/kern_malloc.c
1.546+13-2sys/arch/amd64/conf/GENERIC
1.64+12-2sys/arch/amd64/include/pmap.h
1.339+10-3sys/arch/x86/x86/pmap.c
1.339+11-2sys/arch/amd64/amd64/machdep.c
1.190+10-1sys/arch/amd64/amd64/locore.S
1.147+8-3sys/uvm/uvm_km.c
1.81+8-2sys/arch/x86/x86/bus_dma.c
1.77+8-2sys/kern/subr_kmem.c
1.80+9-1sys/arch/amd64/conf/Makefile.amd64
1.12+9-1sys/arch/amd64/amd64/busfunc.S
1.188+8-1sys/sys/lwp.h
1.33+7-2sys/arch/amd64/include/param.h
1.149+7-1sys/sys/cdefs.h
1.465+5-2sys/net/if.c
1.105+4-3sys/arch/x86/include/pmap.h
1.208+5-2sys/kern/kern_lwp.c
1.50+5-1sys/arch/amd64/amd64/amd64_trap.S
1.64+3-2sys/arch/amd64/include/types.h
1.5+3-2sys/arch/x86/include/bus_defs.h
1.28+3-2sys/arch/amd64/amd64/mptramp.S
1.1244+3-1sys/conf/files
1.4+3-1sys/arch/amd64/amd64/cpu_in_cksum.S
1.33+2-1sys/arch/amd64/amd64/lock_stubs.S
1.37+2-1sys/kern/files.kern
+2,198-6137 files

UnifiedSplitRaw