10c5b02320
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. |
||
---|---|---|
.. | ||
assym.mk | ||
compat_netbsd09.config | ||
compat_netbsd10.config | ||
compat_netbsd11.config | ||
compat_netbsd12.config | ||
compat_netbsd13.config | ||
compat_netbsd14.config | ||
compat_netbsd15.config | ||
compat_netbsd16.config | ||
compat_netbsd20.config | ||
compat_netbsd30.config | ||
compat_netbsd40.config | ||
compat_netbsd50.config | ||
compat_netbsd60.config | ||
compat_netbsd70.config | ||
compat_netbsd80.config | ||
compat_netbsd90.config | ||
compat_netbsd.config | ||
copts.mk | ||
copyright | ||
cscope.mk | ||
debugsyms.c | ||
dts.mk | ||
files | ||
filesystems.config | ||
gdbinit.mk | ||
genassym.cf | ||
ldscript.mk | ||
linkset | ||
lint.mk | ||
majors | ||
majors.std | ||
majors.storage | ||
majors.tty | ||
majors.usb | ||
majors.ws | ||
Makefile.kern.inc | ||
mdroot.mk | ||
mkldscript.sh | ||
newvers_stand.mk | ||
newvers_stand.sh | ||
newvers.mk | ||
newvers.sh | ||
osrelease.sh | ||
param.c | ||
ssp.mk | ||
std |