linux-stable/arch
Dmitry Vyukov e41e614f6a x86: add missing include to sparsemem.h
Patch series "Add KernelMemorySanitizer infrastructure", v7.

KernelMemorySanitizer (KMSAN) is a detector of errors related to uses of
uninitialized memory.  It relies on compile-time Clang instrumentation
(similar to MSan in the userspace [1]) and tracks the state of every bit
of kernel memory, being able to report an error if uninitialized value is
used in a condition, dereferenced, or escapes to userspace, USB or DMA.

KMSAN has reported more than 300 bugs in the past few years (recently
fixed bugs: [2]), most of them with the help of syzkaller.  Such bugs keep
getting introduced into the kernel despite new compiler warnings and other
analyses (the 6.0 cycle already resulted in several KMSAN-reported bugs,
e.g.  [3]).  Mitigations like total stack and heap initialization are
unfortunately very far from being deployable.

The proposed patchset contains KMSAN runtime implementation together with
small changes to other subsystems needed to make KMSAN work.

The latter changes fall into several categories:

1. Changes and refactorings of existing code required to add KMSAN:
 - [01/43] x86: add missing include to sparsemem.h
 - [02/43] stackdepot: reserve 5 extra bits in depot_stack_handle_t
 - [03/43] instrumented.h: allow instrumenting both sides of copy_from_user()
 - [04/43] x86: asm: instrument usercopy in get_user() and __put_user_size()
 - [05/43] asm-generic: instrument usercopy in cacheflush.h
 - [10/43] libnvdimm/pfn_dev: increase MAX_STRUCT_PAGE_SIZE

2. KMSAN-related declarations in generic code, KMSAN runtime library,
   docs and configs:
 - [06/43] kmsan: add ReST documentation
 - [07/43] kmsan: introduce __no_sanitize_memory and __no_kmsan_checks
 - [09/43] x86: kmsan: pgtable: reduce vmalloc space
 - [11/43] kmsan: add KMSAN runtime core
 - [13/43] MAINTAINERS: add entry for KMSAN
 - [24/43] kmsan: add tests for KMSAN
 - [31/43] objtool: kmsan: list KMSAN API functions as uaccess-safe
 - [35/43] x86: kmsan: use __msan_ string functions where possible
 - [43/43] x86: kmsan: enable KMSAN builds for x86

3. Adding hooks from different subsystems to notify KMSAN about memory
   state changes:
 - [14/43] mm: kmsan: maintain KMSAN metadata for page
 - [15/43] mm: kmsan: call KMSAN hooks from SLUB code
 - [16/43] kmsan: handle task creation and exiting
 - [17/43] init: kmsan: call KMSAN initialization routines
 - [18/43] instrumented.h: add KMSAN support
 - [19/43] kmsan: add iomap support
 - [20/43] Input: libps2: mark data received in __ps2_command() as initialized
 - [21/43] dma: kmsan: unpoison DMA mappings
 - [34/43] x86: kmsan: handle open-coded assembly in lib/iomem.c
 - [36/43] x86: kmsan: sync metadata pages on page fault

4. Changes that prevent false reports by explicitly initializing memory,
   disabling optimized code that may trick KMSAN, selectively skipping
   instrumentation:
 - [08/43] kmsan: mark noinstr as __no_sanitize_memory
 - [12/43] kmsan: disable instrumentation of unsupported common kernel code
 - [22/43] virtio: kmsan: check/unpoison scatterlist in vring_map_one_sg()
 - [23/43] kmsan: handle memory sent to/from USB
 - [25/43] kmsan: disable strscpy() optimization under KMSAN
 - [26/43] crypto: kmsan: disable accelerated configs under KMSAN
 - [27/43] kmsan: disable physical page merging in biovec
 - [28/43] block: kmsan: skip bio block merging logic for KMSAN
 - [29/43] kcov: kmsan: unpoison area->list in kcov_remote_area_put()
 - [30/43] security: kmsan: fix interoperability with auto-initialization
 - [32/43] x86: kmsan: disable instrumentation of unsupported code
 - [33/43] x86: kmsan: skip shadow checks in __switch_to()
 - [37/43] x86: kasan: kmsan: support CONFIG_GENERIC_CSUM on x86, enable it for KASAN/KMSAN
 - [38/43] x86: fs: kmsan: disable CONFIG_DCACHE_WORD_ACCESS
 - [39/43] x86: kmsan: don't instrument stack walking functions
 - [40/43] entry: kmsan: introduce kmsan_unpoison_entry_regs()

5. Fixes for bugs detected with CONFIG_KMSAN_CHECK_PARAM_RETVAL:
 - [41/43] bpf: kmsan: initialize BPF registers with zeroes
 - [42/43] mm: fs: initialize fsdata passed to write_begin/write_end interface

This patchset allows one to boot and run a defconfig+KMSAN kernel on a
QEMU without known false positives.  It however doesn't guarantee there
are no false positives in drivers of certain devices or less tested
subsystems, although KMSAN is actively tested on syzbot with a large
config.

By default, KMSAN enforces conservative checks of most kernel function
parameters passed by value (via CONFIG_KMSAN_CHECK_PARAM_RETVAL, which
maps to the -fsanitize-memory-param-retval compiler flag).  As discussed
in [4] and [5], passing uninitialized values as function parameters is
considered undefined behavior, therefore KMSAN now reports such cases as
errors.  Several newly added patches fix known manifestations of these
errors.


This patch (of 43):

Including sparsemem.h from other files (e.g.  transitively via
asm/pgtable_64_types.h) results in compilation errors due to unknown
types:

sparsemem.h:34:32: error: unknown type name 'phys_addr_t'
extern int phys_to_target_node(phys_addr_t start);
                               ^
sparsemem.h:36:39: error: unknown type name 'u64'
extern int memory_add_physaddr_to_nid(u64 start);
                                      ^

Fix these errors by including linux/types.h from sparsemem.h This is
required for the upcoming KMSAN patches.

Link: https://lkml.kernel.org/r/20220915150417.722975-1-glider@google.com
Link: https://lkml.kernel.org/r/20220915150417.722975-2-glider@google.com
Signed-off-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Alexander Potapenko <glider@google.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Eric Biggers <ebiggers@kernel.org>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Marco Elver <elver@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vegard Nossum <vegard.nossum@oracle.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Eric Biggers <ebiggers@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-10-03 14:03:17 -07:00
..
alpha mm/madvise: introduce MADV_COLLAPSE sync hugepage collapse 2022-09-11 20:25:46 -07:00
arc arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
arm arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
arm64 arm64: Change elfcore for_each_mte_vma() to use VMA iterator 2022-09-26 19:46:19 -07:00
csky arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
hexagon provide arch_test_bit_acquire for architectures that define test_bit 2022-08-27 09:49:54 -07:00
ia64 arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
loongarch arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
m68k arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
microblaze - The usual batches of cleanups from Baoquan He, Muchun Song, Miaohe 2022-08-05 16:32:45 -07:00
mips arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
nios2 arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
openrisc Updates to various subsystems which I help look after. lib, ocfs2, 2022-08-07 10:03:24 -07:00
parisc parisc: remove mmap linked list from cache handling 2022-09-26 19:46:19 -07:00
powerpc powerpc: remove mmap linked list walks 2022-09-26 19:46:19 -07:00
riscv riscv: use vma iterator for vdso 2022-09-26 19:46:26 -07:00
s390 s390: remove vma linked list walks 2022-09-26 19:46:19 -07:00
sh arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
sparc arch: mm: rename FORCE_MAX_ZONEORDER to ARCH_FORCE_MAX_ORDER 2022-09-11 20:25:56 -07:00
um um: remove vma linked list walk 2022-09-26 19:46:20 -07:00
x86 x86: add missing include to sparsemem.h 2022-10-03 14:03:17 -07:00
xtensa xtensa: remove vma linked list walks 2022-09-26 19:46:20 -07:00
.gitignore
Kconfig mm: x86: add CONFIG_ARCH_HAS_NONLEAF_PMD_YOUNG 2022-09-26 19:46:08 -07:00