All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Potapenko <glider@google.com>
To: glider@google.com
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andrey Konovalov <andreyknvl@google.com>,
	Andy Lutomirski <luto@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
	Borislav Petkov <bp@alien8.de>, Christoph Hellwig <hch@lst.de>,
	Christoph Lameter <cl@linux.com>,
	David Rientjes <rientjes@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Eric Dumazet <edumazet@google.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Ilya Leoshkevich <iii@linux.ibm.com>,
	Ingo Molnar <mingo@redhat.com>, Jens Axboe <axboe@kernel.dk>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Kees Cook <keescook@chromium.org>, Marco Elver <elver@google.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Matthew Wilcox <willy@infradead.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Pekka Enberg <penberg@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Petr Mladek <pmladek@suse.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Vegard Nossum <vegard.nossum@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	kasan-dev@googlegroups.com, linux-mm@kvack.org,
	linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v6 33/44] x86: kmsan: disable instrumentation of unsupported code
Date: Mon,  5 Sep 2022 14:24:41 +0200	[thread overview]
Message-ID: <20220905122452.2258262-34-glider@google.com> (raw)
In-Reply-To: <20220905122452.2258262-1-glider@google.com>

Instrumenting some files with KMSAN will result in kernel being unable
to link, boot or crashing at runtime for various reasons (e.g. infinite
recursion caused by instrumentation hooks calling instrumented code again).

Completely omit KMSAN instrumentation in the following places:
 - arch/x86/boot and arch/x86/realmode/rm, as KMSAN doesn't work for i386;
 - arch/x86/entry/vdso, which isn't linked with KMSAN runtime;
 - three files in arch/x86/kernel - boot problems;
 - arch/x86/mm/cpu_entry_area.c - recursion.

Signed-off-by: Alexander Potapenko <glider@google.com>
---
v2:
 -- moved the patch earlier in the series so that KMSAN can compile
 -- split off the non-x86 part into a separate patch

v3:
 -- added a comment to lib/Makefile

v5:
 -- removed a comment belonging to another patch

Link: https://linux-review.googlesource.com/id/Id5e5c4a9f9d53c24a35ebb633b814c414628d81b
---
 arch/x86/boot/Makefile            | 1 +
 arch/x86/boot/compressed/Makefile | 1 +
 arch/x86/entry/vdso/Makefile      | 3 +++
 arch/x86/kernel/Makefile          | 2 ++
 arch/x86/kernel/cpu/Makefile      | 1 +
 arch/x86/mm/Makefile              | 2 ++
 arch/x86/realmode/rm/Makefile     | 1 +
 7 files changed, 11 insertions(+)

diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
index ffec8bb01ba8c..9860ca5979f8a 100644
--- a/arch/x86/boot/Makefile
+++ b/arch/x86/boot/Makefile
@@ -12,6 +12,7 @@
 # Sanitizer runtimes are unavailable and cannot be linked for early boot code.
 KASAN_SANITIZE			:= n
 KCSAN_SANITIZE			:= n
+KMSAN_SANITIZE			:= n
 OBJECT_FILES_NON_STANDARD	:= y
 
 # Kernel does not boot with kcov instrumentation here.
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 35ce1a64068b7..3a261abb6d158 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -20,6 +20,7 @@
 # Sanitizer runtimes are unavailable and cannot be linked for early boot code.
 KASAN_SANITIZE			:= n
 KCSAN_SANITIZE			:= n
+KMSAN_SANITIZE			:= n
 OBJECT_FILES_NON_STANDARD	:= y
 
 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
index 12f6c4d714cd6..ce4eb7e44e5b8 100644
--- a/arch/x86/entry/vdso/Makefile
+++ b/arch/x86/entry/vdso/Makefile
@@ -11,6 +11,9 @@ include $(srctree)/lib/vdso/Makefile
 
 # Sanitizer runtimes are unavailable and cannot be linked here.
 KASAN_SANITIZE			:= n
+KMSAN_SANITIZE_vclock_gettime.o := n
+KMSAN_SANITIZE_vgetcpu.o	:= n
+
 UBSAN_SANITIZE			:= n
 KCSAN_SANITIZE			:= n
 OBJECT_FILES_NON_STANDARD	:= y
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index a20a5ebfacd73..ac564c5d7b1f0 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -33,6 +33,8 @@ KASAN_SANITIZE_sev.o					:= n
 # With some compiler versions the generated code results in boot hangs, caused
 # by several compilation units. To be safe, disable all instrumentation.
 KCSAN_SANITIZE := n
+KMSAN_SANITIZE_head$(BITS).o				:= n
+KMSAN_SANITIZE_nmi.o					:= n
 
 # If instrumentation of this dir is enabled, boot hangs during first second.
 # Probably could be more selective here, but note that files related to irqs,
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
index 9661e3e802be5..f10a921ee7565 100644
--- a/arch/x86/kernel/cpu/Makefile
+++ b/arch/x86/kernel/cpu/Makefile
@@ -12,6 +12,7 @@ endif
 # If these files are instrumented, boot hangs during the first second.
 KCOV_INSTRUMENT_common.o := n
 KCOV_INSTRUMENT_perf_event.o := n
+KMSAN_SANITIZE_common.o := n
 
 # As above, instrumenting secondary CPU boot code causes boot hangs.
 KCSAN_SANITIZE_common.o := n
diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
index f8220fd2c169a..39c0700c9955c 100644
--- a/arch/x86/mm/Makefile
+++ b/arch/x86/mm/Makefile
@@ -12,6 +12,8 @@ KASAN_SANITIZE_mem_encrypt_identity.o	:= n
 # Disable KCSAN entirely, because otherwise we get warnings that some functions
 # reference __initdata sections.
 KCSAN_SANITIZE := n
+# Avoid recursion by not calling KMSAN hooks for CEA code.
+KMSAN_SANITIZE_cpu_entry_area.o := n
 
 ifdef CONFIG_FUNCTION_TRACER
 CFLAGS_REMOVE_mem_encrypt.o		= -pg
diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
index 83f1b6a56449f..f614009d3e4e2 100644
--- a/arch/x86/realmode/rm/Makefile
+++ b/arch/x86/realmode/rm/Makefile
@@ -10,6 +10,7 @@
 # Sanitizer runtimes are unavailable and cannot be linked here.
 KASAN_SANITIZE			:= n
 KCSAN_SANITIZE			:= n
+KMSAN_SANITIZE			:= n
 OBJECT_FILES_NON_STANDARD	:= y
 
 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in.
-- 
2.37.2.789.g6183377224-goog


  parent reply	other threads:[~2022-09-05 12:32 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05 12:24 [PATCH v6 00/44] Add KernelMemorySanitizer infrastructure Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 01/44] x86: add missing include to sparsemem.h Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 02/44] stackdepot: reserve 5 extra bits in depot_stack_handle_t Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 03/44] instrumented.h: allow instrumenting both sides of copy_from_user() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 04/44] x86: asm: instrument usercopy in get_user() and put_user() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 05/44] asm-generic: instrument usercopy in cacheflush.h Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 06/44] kmsan: add ReST documentation Alexander Potapenko
2022-09-06  3:10   ` [PATCH v6 6/44] " Bagas Sanjaya
2022-11-07 14:24     ` Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 07/44] kmsan: introduce __no_sanitize_memory and __no_kmsan_checks Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 08/44] kmsan: mark noinstr as __no_sanitize_memory Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 09/44] x86: kmsan: pgtable: reduce vmalloc space Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 10/44] libnvdimm/pfn_dev: increase MAX_STRUCT_PAGE_SIZE Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 11/44] kmsan: add KMSAN runtime core Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 12/44] kmsan: disable instrumentation of unsupported common kernel code Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 13/44] MAINTAINERS: add entry for KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 14/44] mm: kmsan: maintain KMSAN metadata for page operations Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 15/44] mm: kmsan: call KMSAN hooks from SLUB code Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 16/44] kmsan: handle task creation and exiting Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 17/44] init: kmsan: call KMSAN initialization routines Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 18/44] instrumented.h: add KMSAN support Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 19/44] kmsan: unpoison @tlb in arch_tlb_gather_mmu() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 20/44] kmsan: add iomap support Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 21/44] Input: libps2: mark data received in __ps2_command() as initialized Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 22/44] dma: kmsan: unpoison DMA mappings Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 23/44] virtio: kmsan: check/unpoison scatterlist in vring_map_one_sg() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 24/44] kmsan: handle memory sent to/from USB Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 25/44] kmsan: add tests for KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 26/44] kmsan: disable strscpy() optimization under KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 27/44] crypto: kmsan: disable accelerated configs " Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 28/44] kmsan: disable physical page merging in biovec Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 29/44] block: kmsan: skip bio block merging logic for KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 30/44] kcov: kmsan: unpoison area->list in kcov_remote_area_put() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 31/44] security: kmsan: fix interoperability with auto-initialization Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 32/44] objtool: kmsan: list KMSAN API functions as uaccess-safe Alexander Potapenko
2022-09-05 12:24 ` Alexander Potapenko [this message]
2022-09-05 12:24 ` [PATCH v6 34/44] x86: kmsan: skip shadow checks in __switch_to() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 35/44] x86: kmsan: handle open-coded assembly in lib/iomem.c Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 36/44] x86: kmsan: use __msan_ string functions where possible Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 37/44] x86: kmsan: sync metadata pages on page fault Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 38/44] x86: kasan: kmsan: support CONFIG_GENERIC_CSUM on x86, enable it for KASAN/KMSAN Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 39/44] x86: fs: kmsan: disable CONFIG_DCACHE_WORD_ACCESS Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 40/44] x86: kmsan: don't instrument stack walking functions Alexander Potapenko
2022-09-09  8:57   ` Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 41/44] entry: kmsan: introduce kmsan_unpoison_entry_regs() Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 42/44] bpf: kmsan: initialize BPF registers with zeroes Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 43/44] mm: fs: initialize fsdata passed to write_begin/write_end interface Alexander Potapenko
2022-09-05 12:24 ` [PATCH v6 44/44] x86: kmsan: enable KMSAN builds for x86 Alexander Potapenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220905122452.2258262-34-glider@google.com \
    --to=glider@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@google.com \
    --cc=arnd@arndb.de \
    --cc=ast@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bp@alien8.de \
    --cc=cl@linux.com \
    --cc=dvyukov@google.com \
    --cc=edumazet@google.com \
    --cc=elver@google.com \
    --cc=gor@linux.ibm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=iii@linux.ibm.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=keescook@chromium.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=mst@redhat.com \
    --cc=penberg@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rientjes@google.com \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=vbabka@suse.cz \
    --cc=vegard.nossum@oracle.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.