NetBSD/sys/conf
maxv 10c5b02320 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.
2019-11-14 16:23:52 +00:00
..
assym.mk Fix dependency of *.d -> assym.h in `-S' mode. 2015-09-10 13:11:39 +00:00
compat_netbsd09.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd10.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd11.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd12.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd13.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd14.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd15.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd16.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd20.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd30.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd40.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd50.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd60.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd70.config note that COMPAT_X implies all COMPAT_X+N. 2018-01-15 07:20:10 +00:00
compat_netbsd80.config Merge the [pgoyette-compat] branch 2019-01-27 02:08:33 +00:00
compat_netbsd90.config Add a new member to struct vfsstat and grow the unused members 2019-09-22 22:59:37 +00:00
compat_netbsd.config clean up COMPAT_* options for native netbsd code: 2017-09-14 07:58:38 +00:00
copts.mk convert HAVE_GCC == 7 to HAVE_GCC >= 7. 2019-09-30 00:06:02 +00:00
copyright Welcome to 2019! 2019-01-01 01:52:40 +00:00
cscope.mk Move less important part out of Makefile.kern.inc. 2015-08-29 16:27:07 +00:00
debugsyms.c Expose struct kauth_cred for the benefit of the debugger. I can't convince gcc 2015-10-06 22:13:39 +00:00
dts.mk change -h to -n because it is more "portable" 2019-04-24 20:53:10 +00:00
files Add support for Kernel Memory Sanitizer (kMSan). It detects uninitialized 2019-11-14 16:23:52 +00:00
filesystems.config comment out CHFS to fix build issues 2019-06-17 17:06:39 +00:00
gdbinit.mk Move less important part out of Makefile.kern.inc. 2015-08-29 16:27:07 +00:00
genassym.cf Have MI genassym.cf. 2015-08-26 03:00:52 +00:00
ldscript.mk More build ordering. 2015-09-06 15:20:59 +00:00
linkset
lint.mk Move less important part out of Makefile.kern.inc. 2015-08-29 16:27:07 +00:00
majors Implement a front-end driver of virtio-9p called vio9p 2019-10-28 02:56:40 +00:00
majors.std Update device dependency information - the sysmon major device now depends on the sysmon module itself, not on the individual components. 2015-04-23 23:22:51 +00:00
majors.storage
majors.tty
majors.usb
majors.ws
Makefile.kern.inc pass -Wno-error=implicit-fallthrough for zlib.c. 2019-02-05 08:33:25 +00:00
mdroot.mk Put back MEMORY_DISK_IMAGE logic, but use generated opt_memory_root_image.h 2015-08-30 05:24:03 +00:00
mkldscript.sh
newvers_stand.mk Fix typo 2017-04-09 14:52:14 +00:00
newvers_stand.sh Add makefile snippet for vers.c building. 2017-04-08 19:53:54 +00:00
newvers.mk - modernize: use getopts/usage/true/false variables 2017-04-08 18:24:09 +00:00
newvers.sh - modernize: use getopts/usage/true/false variables 2017-04-08 18:24:09 +00:00
osrelease.sh
param.c defparam all of the config variables associated with SYSV IPC stuff. 2019-04-09 22:05:27 +00:00
ssp.mk Add KCOV - kernel code coverage tracing device 2019-02-23 03:10:05 +00:00
std Merge the [pgoyette-compat] branch 2019-01-27 02:08:33 +00:00