From nobody Tue Apr 7 16:28:42 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6680AECAAA3 for ; Fri, 26 Aug 2022 15:14:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343622AbiHZPOl (ORCPT ); Fri, 26 Aug 2022 11:14:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343558AbiHZPNB (ORCPT ); Fri, 26 Aug 2022 11:13:01 -0400 Received: from mail-ed1-x549.google.com (mail-ed1-x549.google.com [IPv6:2a00:1450:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F19FD2F5 for ; Fri, 26 Aug 2022 08:09:45 -0700 (PDT) Received: by mail-ed1-x549.google.com with SMTP id q32-20020a05640224a000b004462f105fa9so1239895eda.4 for ; Fri, 26 Aug 2022 08:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc; bh=TL1IO7xzXsHa87B/8VTzh6zaFcPyOOUQBNZupLxKBzY=; b=HmM0VO6gyAfILflJdnMgQCrJGnTi5XVkH3YSfQa6Ep7rg4UjuRksDwsSKfdFWywrKQ X82KrgKGqPOH7W1Y085jaYB8hH48o1UO09SOdX25urL9IS+XrJIM0Ssl/7EKgVgUGuxb suAFkuoPLhsCY3yiCTAbiGImLbwkQ5FdkgDFrYP2s7UE16Wpzs+b87M7ywZwNSRcm9YT cGnqAcNCOOLNxnkJmTHzwJPrKl7dQaDEoIofp21fLLf8UCuU8TSnY933jziAvQ7zwjo3 /ax/hZi6c/lKBcQc7+qabk0byKdenq8IrwbzMmcRBwdyqFxWLtVcbbN3QqtnjPKNbk+n t0fA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc; bh=TL1IO7xzXsHa87B/8VTzh6zaFcPyOOUQBNZupLxKBzY=; b=AiRkh3+VKJOzjOCIVJ6lacTjGpiEJvFl2qqjKsLQ40W3bcXH1wz3wou+s7WHL/cvw0 QK8C4PAy8CNfCxDe/h5S6niweTgPwFxuzepwAXXY4fohgqUOuQ3H3OZXzzT0kI3qdMo4 z9bmIH1oas+psDbfaeFtoJFPcsfm65hnorkDmaPM6Dfg7oHZ+R5J0QtVKGL915BOyei7 jzy/KL0nCrwafHcen9am+/fsBW3+KaVJiXzgsK7X0mIeQOXrttgQJkkQFMbDfF4GJXfp h0uHhBVZgNZZemQqkEBR9aQydfHBjaPDmzBCqpS9+kW55lKyb4P9WRKXZT28T+HfOTXh TzYQ== X-Gm-Message-State: ACgBeo0b/2YODm2T/da/WfMWzgRKktAanICqQ3mmuhSJL94FH0rNzewa QTDPtKPmzZItBkdGmlqQY9UYp3FazeQ= X-Google-Smtp-Source: AA6agR76x5AzTzEwn7EdrRuhdUjJW6rIUhqvD9uYbbBW+SigP/bQyvCEvWgW5kLb9e6YBzYDFPgy1GTjMDc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:5207:ac36:fdd3:502d]) (user=glider job=sendgmr) by 2002:a50:fe91:0:b0:43d:c97d:1b93 with SMTP id d17-20020a50fe91000000b0043dc97d1b93mr7390732edt.67.1661526585272; Fri, 26 Aug 2022 08:09:45 -0700 (PDT) Date: Fri, 26 Aug 2022 17:07:56 +0200 In-Reply-To: <20220826150807.723137-1-glider@google.com> Mime-Version: 1.0 References: <20220826150807.723137-1-glider@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826150807.723137-34-glider@google.com> Subject: [PATCH v5 33/44] x86: kmsan: disable instrumentation of unsupported code From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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/Id5e5c4a9f9d53c24a35ebb633b8= 14c414628d81b --- 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 c= ode. KASAN_SANITIZE :=3D n KCSAN_SANITIZE :=3D n +KMSAN_SANITIZE :=3D n OBJECT_FILES_NON_STANDARD :=3D y =20 # Kernel does not boot with kcov instrumentation here. diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/M= akefile 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 c= ode. KASAN_SANITIZE :=3D n KCSAN_SANITIZE :=3D n +KMSAN_SANITIZE :=3D n OBJECT_FILES_NON_STANDARD :=3D y =20 # 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 =20 # Sanitizer runtimes are unavailable and cannot be linked here. KASAN_SANITIZE :=3D n +KMSAN_SANITIZE_vclock_gettime.o :=3D n +KMSAN_SANITIZE_vgetcpu.o :=3D n + UBSAN_SANITIZE :=3D n KCSAN_SANITIZE :=3D n OBJECT_FILES_NON_STANDARD :=3D 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 :=3D n # With some compiler versions the generated code results in boot hangs, ca= used # by several compilation units. To be safe, disable all instrumentation. KCSAN_SANITIZE :=3D n +KMSAN_SANITIZE_head$(BITS).o :=3D n +KMSAN_SANITIZE_nmi.o :=3D n =20 # If instrumentation of this dir is enabled, boot hangs during first secon= d. # Probably could be more selective here, but note that files related to ir= qs, 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 :=3D n KCOV_INSTRUMENT_perf_event.o :=3D n +KMSAN_SANITIZE_common.o :=3D n =20 # As above, instrumenting secondary CPU boot code causes boot hangs. KCSAN_SANITIZE_common.o :=3D 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 :=3D n # Disable KCSAN entirely, because otherwise we get warnings that some func= tions # reference __initdata sections. KCSAN_SANITIZE :=3D n +# Avoid recursion by not calling KMSAN hooks for CEA code. +KMSAN_SANITIZE_cpu_entry_area.o :=3D n =20 ifdef CONFIG_FUNCTION_TRACER CFLAGS_REMOVE_mem_encrypt.o =3D -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 :=3D n KCSAN_SANITIZE :=3D n +KMSAN_SANITIZE :=3D n OBJECT_FILES_NON_STANDARD :=3D y =20 # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. --=20 2.37.2.672.g94769d06f0-goog