All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: kernel test robot <lkp@intel.com>
Cc: kbuild-all@lists.01.org, clang-built-linux@googlegroups.com,
	linux-kernel@vger.kernel.org, Marco Elver <elver@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	kasan-dev@googlegroups.com
Subject: Re: [PATCH v3 4/9] x86/build: Warn on orphan section placement
Date: Sat, 27 Jun 2020 08:44:08 -0700	[thread overview]
Message-ID: <202006270840.E0BC752A72@keescook> (raw)
In-Reply-To: <202006250240.J1VuMKoC%lkp@intel.com>

On Thu, Jun 25, 2020 at 02:36:27AM +0800, kernel test robot wrote:
> I love your patch! Perhaps something to improve:
> [...]
> config: x86_64-randconfig-a012-20200624 (attached as .config)

CONFIG_KCSAN=y

> compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 1d4c87335d5236ea1f35937e1014980ba961ae34)
> [...]
> All warnings (new ones prefixed by >>):
> 
>    ld.lld: warning: drivers/built-in.a(mfd/mt6397-irq.o):(.init_array.0) is being placed in '.init_array.0'

As far as I can tell, this is a Clang bug. But I don't know the
internals here, so I've opened:
https://bugs.llvm.org/show_bug.cgi?id=46478

and created a work-around patch for the kernel:


commit 915f2c343e59a14f00c68f4d7afcfdc621de0674
Author: Kees Cook <keescook@chromium.org>
Date:   Sat Jun 27 08:07:54 2020 -0700

    vmlinux.lds.h: Avoid KCSAN's unwanted sections
    
    KCSAN (-fsanitize=thread) produces unwanted[1] .eh_frame and .init_array.*
    sections. Add them to DISCARDS, except with CONFIG_CONSTRUCTORS, which
    wants to keep .init_array.* sections.
    
    [1] https://bugs.llvm.org/show_bug.cgi?id=46478
    
    Signed-off-by: Kees Cook <keescook@chromium.org>

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index f8a5b2333729..41c8c73de6c4 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -195,7 +195,9 @@ endif
 # Workaround for a gcc prelease that unfortunately was shipped in a suse release
 KBUILD_CFLAGS += -Wno-sign-compare
 #
-KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
+KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
+KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
+KBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
 
 # Avoid indirect branches in kernel to deal with Spectre
 ifdef CONFIG_RETPOLINE
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index b1dca0762fc5..a44ee16abc78 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -934,10 +934,28 @@
 	EXIT_DATA
 #endif
 
+/*
+ * Clang's -fsanitize=thread produces unwanted sections (.eh_frame
+ * and .init_array.*), but CONFIG_CONSTRUCTORS wants to keep any
+ * .init_array.* sections.
+ * https://bugs.llvm.org/show_bug.cgi?id=46478
+ */
+#if defined(CONFIG_KCSAN) && !defined(CONFIG_CONSTRUCTORS)
+#define KCSAN_DISCARDS	 						\
+	*(.init_array) *(.init_array.*)					\
+	*(.eh_frame)
+#elif defined(CONFIG_KCSAN) && defined(CONFIG_CONSTRUCTORS)
+#define KCSAN_DISCARDS	 						\
+	*(.eh_frame)
+#else
+#define KCSAN_DISCARDS
+#endif
+
 #define DISCARDS							\
 	/DISCARD/ : {							\
 	EXIT_DISCARDS							\
 	EXIT_CALL							\
+	KCSAN_DISCARDS							\
 	*(.discard)							\
 	*(.discard.*)							\
 	*(.modinfo)							\

-- 
Kees Cook

WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: kbuild-all@lists.01.org
Subject: Re: [PATCH v3 4/9] x86/build: Warn on orphan section placement
Date: Sat, 27 Jun 2020 08:44:08 -0700	[thread overview]
Message-ID: <202006270840.E0BC752A72@keescook> (raw)
In-Reply-To: <202006250240.J1VuMKoC%lkp@intel.com>

[-- Attachment #1: Type: text/plain, Size: 2847 bytes --]

On Thu, Jun 25, 2020 at 02:36:27AM +0800, kernel test robot wrote:
> I love your patch! Perhaps something to improve:
> [...]
> config: x86_64-randconfig-a012-20200624 (attached as .config)

CONFIG_KCSAN=y

> compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 1d4c87335d5236ea1f35937e1014980ba961ae34)
> [...]
> All warnings (new ones prefixed by >>):
> 
>    ld.lld: warning: drivers/built-in.a(mfd/mt6397-irq.o):(.init_array.0) is being placed in '.init_array.0'

As far as I can tell, this is a Clang bug. But I don't know the
internals here, so I've opened:
https://bugs.llvm.org/show_bug.cgi?id=46478

and created a work-around patch for the kernel:


commit 915f2c343e59a14f00c68f4d7afcfdc621de0674
Author: Kees Cook <keescook@chromium.org>
Date:   Sat Jun 27 08:07:54 2020 -0700

    vmlinux.lds.h: Avoid KCSAN's unwanted sections
    
    KCSAN (-fsanitize=thread) produces unwanted[1] .eh_frame and .init_array.*
    sections. Add them to DISCARDS, except with CONFIG_CONSTRUCTORS, which
    wants to keep .init_array.* sections.
    
    [1] https://bugs.llvm.org/show_bug.cgi?id=46478
    
    Signed-off-by: Kees Cook <keescook@chromium.org>

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index f8a5b2333729..41c8c73de6c4 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -195,7 +195,9 @@ endif
 # Workaround for a gcc prelease that unfortunately was shipped in a suse release
 KBUILD_CFLAGS += -Wno-sign-compare
 #
-KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
+KBUILD_AFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
+KBUILD_CFLAGS += -fno-asynchronous-unwind-tables -fno-unwind-tables
+KBUILD_LDFLAGS += $(call ld-option,--no-ld-generated-unwind-info)
 
 # Avoid indirect branches in kernel to deal with Spectre
 ifdef CONFIG_RETPOLINE
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index b1dca0762fc5..a44ee16abc78 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -934,10 +934,28 @@
 	EXIT_DATA
 #endif
 
+/*
+ * Clang's -fsanitize=thread produces unwanted sections (.eh_frame
+ * and .init_array.*), but CONFIG_CONSTRUCTORS wants to keep any
+ * .init_array.* sections.
+ * https://bugs.llvm.org/show_bug.cgi?id=46478
+ */
+#if defined(CONFIG_KCSAN) && !defined(CONFIG_CONSTRUCTORS)
+#define KCSAN_DISCARDS	 						\
+	*(.init_array) *(.init_array.*)					\
+	*(.eh_frame)
+#elif defined(CONFIG_KCSAN) && defined(CONFIG_CONSTRUCTORS)
+#define KCSAN_DISCARDS	 						\
+	*(.eh_frame)
+#else
+#define KCSAN_DISCARDS
+#endif
+
 #define DISCARDS							\
 	/DISCARD/ : {							\
 	EXIT_DISCARDS							\
 	EXIT_CALL							\
+	KCSAN_DISCARDS							\
 	*(.discard)							\
 	*(.discard.*)							\
 	*(.modinfo)							\

-- 
Kees Cook

  reply	other threads:[~2020-06-27 15:45 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-24  1:49 [PATCH v3 0/9] Warn on orphan section placement Kees Cook
2020-06-24  1:49 ` Kees Cook
2020-06-24  1:49 ` [PATCH v3 1/9] vmlinux.lds.h: Add .gnu.version* to DISCARDS Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24  1:49 ` [PATCH v3 2/9] vmlinux.lds.h: Add .symtab, .strtab, and .shstrtab to STABS_DEBUG Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24 15:39   ` Arvind Sankar
2020-06-24 15:39     ` Arvind Sankar
2020-06-24 15:39     ` Arvind Sankar
2020-06-24 16:16     ` Fangrui Song
2020-06-24 16:16       ` Fangrui Song
2020-06-24 17:11       ` Arvind Sankar
2020-06-24 17:11         ` Arvind Sankar
2020-06-24 17:11         ` Arvind Sankar
2020-06-24 17:26         ` Fangrui Song
2020-06-24 17:26           ` Fangrui Song
2020-06-24 17:35           ` Arvind Sankar
2020-06-24 17:35             ` Arvind Sankar
2020-06-24 17:35             ` Arvind Sankar
2020-06-24  1:49 ` [PATCH v3 3/9] efi/libstub: Remove .note.gnu.property Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24  3:31   ` Fangrui Song
2020-06-24  3:31     ` Fangrui Song
2020-06-24  4:44     ` Kees Cook
2020-06-24  4:44       ` Kees Cook
2020-06-24 10:43       ` Will Deacon
2020-06-24 10:43         ` Will Deacon
2020-06-24 10:46         ` Ard Biesheuvel
2020-06-24 10:46           ` Ard Biesheuvel
2020-06-24 10:46           ` Ard Biesheuvel
2020-06-24 11:26           ` Will Deacon
2020-06-24 11:26             ` Will Deacon
2020-06-24 11:26             ` Will Deacon
2020-06-24 13:48             ` Dave Martin
2020-06-24 13:48               ` Dave Martin
2020-06-24 13:48               ` Dave Martin
2020-06-24 15:26               ` Will Deacon
2020-06-24 15:26                 ` Will Deacon
2020-06-24 15:26                 ` Will Deacon
2020-06-24 16:26                 ` Dave Martin
2020-06-24 16:26                   ` Dave Martin
2020-06-24 16:26                   ` Dave Martin
2020-06-24 15:21           ` Kees Cook
2020-06-24 15:21             ` Kees Cook
2020-06-24 15:21             ` Kees Cook
2020-06-24 15:31             ` Ard Biesheuvel
2020-06-24 15:31               ` Ard Biesheuvel
2020-06-24 15:31               ` Ard Biesheuvel
2020-06-24 15:45               ` Kees Cook
2020-06-24 15:45                 ` Kees Cook
2020-06-24 15:45                 ` Kees Cook
2020-06-24 15:48                 ` Ard Biesheuvel
2020-06-24 15:48                   ` Ard Biesheuvel
2020-06-24 15:48                   ` Ard Biesheuvel
2020-06-24 16:29                   ` Dave Martin
2020-06-24 16:29                     ` Dave Martin
2020-06-24 16:29                     ` Dave Martin
2020-06-24 16:40                     ` Ard Biesheuvel
2020-06-24 16:40                       ` Ard Biesheuvel
2020-06-24 16:40                       ` Ard Biesheuvel
2020-06-24 17:16                       ` Dave Martin
2020-06-24 17:16                         ` Dave Martin
2020-06-24 17:16                         ` Dave Martin
2020-06-24 18:23                         ` Ard Biesheuvel
2020-06-24 18:23                           ` Ard Biesheuvel
2020-06-24 18:23                           ` Ard Biesheuvel
2020-06-24 18:57                           ` Ard Biesheuvel
2020-06-24 18:57                             ` Ard Biesheuvel
2020-06-24 18:57                             ` Ard Biesheuvel
2020-06-24  1:49 ` [PATCH v3 4/9] x86/build: Warn on orphan section placement Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24 18:36   ` kernel test robot
2020-06-27 15:44     ` Kees Cook [this message]
2020-06-27 15:44       ` Kees Cook
2020-06-29 14:54       ` Marco Elver
2020-06-29 14:54         ` Marco Elver
2020-06-29 15:26         ` Kees Cook
2020-06-29 15:26           ` Kees Cook
2020-06-24  1:49 ` [PATCH v3 5/9] x86/boot: " Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24  1:49 ` [PATCH v3 6/9] arm/build: " Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24  1:49 ` [PATCH v3 7/9] arm/boot: " Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24  1:49 ` [PATCH v3 8/9] arm64/build: Use common DISCARDS in linker script Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24  1:49 ` [PATCH v3 9/9] arm64/build: Warn on orphan section placement Kees Cook
2020-06-24  1:49   ` Kees Cook
2020-06-24  7:57   ` Will Deacon
2020-06-24  7:57     ` Will Deacon
2020-06-24 15:36     ` Kees Cook
2020-06-24 15:36       ` Kees Cook

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=202006270840.E0BC752A72@keescook \
    --to=keescook@chromium.org \
    --cc=clang-built-linux@googlegroups.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kbuild-all@lists.01.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    /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.