xref: /netbsd-src/share/man/man7/kernel_sanitizers.7 (revision 1fde49c064576f408cd09dfd32d84ffd49192653)
1*1fde49c0Sskrll.\"	$NetBSD: kernel_sanitizers.7,v 1.6 2020/07/12 13:40:44 skrll Exp $
261584588Smaxv.\"
361584588Smaxv.\" Copyright (c) 2020 The NetBSD Foundation, Inc.
461584588Smaxv.\" All rights reserved.
561584588Smaxv.\"
661584588Smaxv.\" This code is derived from software contributed to The NetBSD Foundation
761584588Smaxv.\" by Maxime Villard.
861584588Smaxv.\"
961584588Smaxv.\" Redistribution and use in source and binary forms, with or without
1061584588Smaxv.\" modification, are permitted provided that the following conditions
1161584588Smaxv.\" are met:
1261584588Smaxv.\" 1. Redistributions of source code must retain the above copyright
1361584588Smaxv.\"    notice, this list of conditions and the following disclaimer.
1461584588Smaxv.\" 2. Redistributions in binary form must reproduce the above copyright
1561584588Smaxv.\"    notice, this list of conditions and the following disclaimer in the
1661584588Smaxv.\"    documentation and/or other materials provided with the distribution.
1761584588Smaxv.\"
1861584588Smaxv.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1961584588Smaxv.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2061584588Smaxv.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2161584588Smaxv.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2261584588Smaxv.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2361584588Smaxv.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2461584588Smaxv.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2561584588Smaxv.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2661584588Smaxv.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2761584588Smaxv.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2861584588Smaxv.\" POSSIBILITY OF SUCH DAMAGE.
2961584588Smaxv.\"
300d658a2dSmaxv.Dd July 12, 2020
31bc3f8a62Swiz.Dt KERNEL_SANITIZERS 7
3261584588Smaxv.Os
3361584588Smaxv.Sh NAME
3461584588Smaxv.Nm kernel_sanitizers
35bc3f8a62Swiz.Nd NetBSD Kernel Sanitizers
3661584588Smaxv.Sh DESCRIPTION
3761584588SmaxvKernel Sanitizers are powerful kernel bug detection features that can
3861584588Smaxvautomatically discover several classes of bugs at run time while the kernel
3961584588Smaxvexecutes.
4061584588Smaxv.Pp
4161584588Smaxv.Nx
4261584588Smaxvsupports four kernel sanitizers.
4361584588SmaxvThey are not mutually compatible, and only one can be enabled at a time, via
4461584588Smaxvcompilation options.
4561584588Smaxv.Sh KUBSAN
4661584588SmaxvKernel Undefined Behavior Sanitizer, specializes in finding several types of
4761584588Smaxvundefined behaviors, such a misaligned accesses and integer overflows.
4861584588Smaxv.Ss Runtime cost
4961584588SmaxvHeavy runtime checks.
5061584588Smaxv.Ss Used components
5161584588SmaxvCompiler instrumentation and an entirely MI runtime.
5261584588Smaxv.Ss Supported architectures
53*1fde49c0Sskrllaarch64 (gcc), amd64 (gcc), arm (gcc).
5461584588Smaxv[Theoretically supported on all other architectures with no MD change required]
5561584588Smaxv.Ss Files
5661584588Smaxv.Bl -tag -width XXXX -compact
5764f849a4Smaxv.It Pa src/common/lib/libc/misc/ubsan.c
58bc3f8a62SwizCore KUBSAN code.
59bc3f8a62SwizMI.
6061584588Smaxv.El
6161584588Smaxv.Sh KASAN
6261584588SmaxvKernel Address Sanitizer, specializes in finding memory corruptions such as
6361584588Smaxvbuffer overflows and use-after-frees.
6461584588Smaxv.Ss Runtime cost
6561584588SmaxvHeavy runtime checks, and ~12.5% increase in memory consumption.
6661584588Smaxv.Ss Used components
6761584588SmaxvShadow memory, compiler instrumentation, special kernel wrappers, and
6861584588Smaxvlight MD infrastructure.
6961584588Smaxv.Ss Supported architectures
70d329adb0Sskrllaarch64 (gcc), amd64 (gcc, llvm), arm (gcc).
7161584588Smaxv.Pp
7261584588SmaxvKASAN is made of six sub-features that perform memory validation:
7361584588Smaxv.Bd -literal
7461584588Smaxv          +-----------------------------------------------------+
7561584588Smaxv          |                SUPPORTED SUB-FEATURE                |
7661584588Smaxv+---------+------+-------+---------+-----------+---------+------+
7761584588Smaxv|  PORT   | HEAP | STACK | ATOMICS | BUS_SPACE | BUS_DMA | VLAs |
7861584588Smaxv+---------+------+-------+---------+-----------+---------+------+
7961584588Smaxv| amd64   | Yes  | Yes   | Yes     | Yes       | Yes     | Yes  |
8061584588Smaxv+---------+------+-------+---------+-----------+---------+------+
8161584588Smaxv| aarch64 | Yes  | Yes   | Yes     | No        | Yes     | Yes  |
8261584588Smaxv+---------+------+-------+---------+-----------+---------+------+
83d329adb0Sskrll| arm     | Yes  | Yes   | Yes     | No        | Yes     | Yes  |
84d329adb0Sskrll+---------+------+-------+---------+-----------+---------+------+
8561584588Smaxv.Ed
8661584588Smaxv.Pp
8761584588SmaxvAn architecture is allowed to have only partial support.
8861584588Smaxv.Ss Files
8961584588Smaxv.Bl -tag -width XXXX -compact
9061584588Smaxv.It Pa src/sys/kern/subr_asan.c
91bc3f8a62SwizCore KASAN code.
92bc3f8a62SwizMI.
9361584588Smaxv.It Pa src/sys/sys/asan.h
94bc3f8a62SwizMain KASAN header.
95bc3f8a62SwizMI.
9661584588Smaxv.It Pa src/sys/arch/{port}/include/asan.h
97bc3f8a62SwizPort-specific KASAN code.
98bc3f8a62SwizMD.
9961584588Smaxv.El
10061584588Smaxv.Pp
10161584588SmaxvEach new port of KASAN should respect the existing naming conventions, and
10261584588Smaxvshould introduce only one MD header file.
10361584588Smaxv.Sh KCSAN
10461584588SmaxvKernel Concurrency Sanitizer, specializes in finding memory races.
10561584588Smaxv.Ss Runtime cost
10661584588SmaxvMedium runtime checks.
10761584588Smaxv.Ss Used components
10861584588SmaxvCompiler instrumentation, special kernel wrappers, and light MD infrastructure.
10961584588Smaxv.Ss Supported architectures
11061584588Smaxvamd64 (gcc).
11161584588Smaxv.Ss Files
11261584588Smaxv.Bl -tag -width XXXX -compact
11361584588Smaxv.It Pa src/sys/kern/subr_csan.c
114bc3f8a62SwizCore KCSAN code.
115bc3f8a62SwizMI.
11661584588Smaxv.It Pa src/sys/sys/csan.h
117bc3f8a62SwizMain KCSAN header.
118bc3f8a62SwizMI.
11961584588Smaxv.It Pa src/sys/arch/{port}/include/csan.h
120bc3f8a62SwizPort-specific KCSAN code.
121bc3f8a62SwizMD.
12261584588Smaxv.El
12361584588Smaxv.Pp
12461584588SmaxvEach new port of KCSAN should respect the existing naming conventions, and
12561584588Smaxvshould introduce only one MD header file.
12661584588Smaxv.Sh KMSAN
12761584588SmaxvKernel Memory Sanitizer, specializes in finding uninitialized memory.
12861584588Smaxv.Ss Runtime cost
1290d658a2dSmaxvHeavy runtime checks, and ~200% increase in memory consumption.
13061584588Smaxv.Ss Used components
1310d658a2dSmaxvDouble shadow memory, compiler instrumentation, special kernel wrappers, and
1320d658a2dSmaxvheavy MD infrastructure.
13361584588Smaxv.Ss Supported architectures
13461584588Smaxvamd64 (llvm).
13561584588Smaxv.Ss Files
13661584588Smaxv.Bl -tag -width XXXX -compact
13761584588Smaxv.It Pa src/sys/kern/subr_msan.c
138bc3f8a62SwizCore KMSAN code.
139bc3f8a62SwizMI.
14061584588Smaxv.It Pa src/sys/sys/msan.h
141bc3f8a62SwizMain KMSAN header.
142bc3f8a62SwizMI.
14361584588Smaxv.It Pa src/sys/arch/{port}/include/msan.h
144bc3f8a62SwizPort-specific KMSAN code.
145bc3f8a62SwizMD.
14661584588Smaxv.El
14761584588Smaxv.Pp
14861584588SmaxvEach new port of KMSAN should respect the existing naming conventions, and
14961584588Smaxvshould introduce only one MD header file.
15061584588Smaxv.Sh AUTHORS
151bc3f8a62Swiz.An -nosplit
15261584588SmaxvSupport for KUBSAN was developed by
15361584588Smaxv.An Kamil Rytarowski .
15461584588SmaxvSupport for KASAN, KCSAN and KMSAN was developed by
15561584588Smaxv.An Maxime Villard .
156d329adb0SskrllSupport for KASAN on ARM was developed by
157d329adb0Sskrll.An Nick Hudson .
158