All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: <linuxppc-dev@lists.ozlabs.org>
Cc: sudipm.mukherjee@gmail.com, keescook@chromium.org,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org,
	torvalds@linux-foundation.org
Subject: [PATCH] powerpc/64s: Disable stack variable initialisation for prom_init
Date: Mon, 18 Jul 2022 23:44:18 +1000	[thread overview]
Message-ID: <20220718134418.354114-1-mpe@ellerman.id.au> (raw)
In-Reply-To: <87cze3docs.fsf@mpe.ellerman.id.au>

With GCC 12 allmodconfig prom_init fails to build:

  Error: External symbol 'memset' referenced from prom_init.c
  make[2]: *** [arch/powerpc/kernel/Makefile:204: arch/powerpc/kernel/prom_init_check] Error 1

The allmodconfig build enables KASAN, so all calls to memset in
prom_init should be converted to __memset by the #ifdefs in
asm/string.h, because prom_init must use the non-KASAN instrumented
versions.

The build failure happens because there's a call to memset that hasn't
been caught by the pre-processor and converted to __memset. Typically
that's because it's a memset generated by the compiler itself, and that
is the case here.

With GCC 12, allmodconfig enables CONFIG_INIT_STACK_ALL_PATTERN, which
causes the compiler to emit memset calls to initialise on-stack
variables with a pattern.

Because prom_init is non-user-facing boot-time only code, as a
workaround just disable stack variable initialisation to unbreak the
build.

Reported-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kernel/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index f91f0f29a566..c8cf924bf9c0 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -20,6 +20,7 @@ CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
 CFLAGS_prom_init.o += -fno-stack-protector
 CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING
 CFLAGS_prom_init.o += -ffreestanding
+CFLAGS_prom_init.o += $(call cc-option, -ftrivial-auto-var-init=uninitialized)
 
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace early boot code
-- 
2.35.3


WARNING: multiple messages have this Message-ID (diff)
From: Michael Ellerman <mpe@ellerman.id.au>
To: <linuxppc-dev@lists.ozlabs.org>
Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	linux-hardening@vger.kernel.org, sudipm.mukherjee@gmail.com,
	keescook@chromium.org
Subject: [PATCH] powerpc/64s: Disable stack variable initialisation for prom_init
Date: Mon, 18 Jul 2022 23:44:18 +1000	[thread overview]
Message-ID: <20220718134418.354114-1-mpe@ellerman.id.au> (raw)
In-Reply-To: <87cze3docs.fsf@mpe.ellerman.id.au>

With GCC 12 allmodconfig prom_init fails to build:

  Error: External symbol 'memset' referenced from prom_init.c
  make[2]: *** [arch/powerpc/kernel/Makefile:204: arch/powerpc/kernel/prom_init_check] Error 1

The allmodconfig build enables KASAN, so all calls to memset in
prom_init should be converted to __memset by the #ifdefs in
asm/string.h, because prom_init must use the non-KASAN instrumented
versions.

The build failure happens because there's a call to memset that hasn't
been caught by the pre-processor and converted to __memset. Typically
that's because it's a memset generated by the compiler itself, and that
is the case here.

With GCC 12, allmodconfig enables CONFIG_INIT_STACK_ALL_PATTERN, which
causes the compiler to emit memset calls to initialise on-stack
variables with a pattern.

Because prom_init is non-user-facing boot-time only code, as a
workaround just disable stack variable initialisation to unbreak the
build.

Reported-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kernel/Makefile | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
index f91f0f29a566..c8cf924bf9c0 100644
--- a/arch/powerpc/kernel/Makefile
+++ b/arch/powerpc/kernel/Makefile
@@ -20,6 +20,7 @@ CFLAGS_prom.o += $(DISABLE_LATENT_ENTROPY_PLUGIN)
 CFLAGS_prom_init.o += -fno-stack-protector
 CFLAGS_prom_init.o += -DDISABLE_BRANCH_PROFILING
 CFLAGS_prom_init.o += -ffreestanding
+CFLAGS_prom_init.o += $(call cc-option, -ftrivial-auto-var-init=uninitialized)
 
 ifdef CONFIG_FUNCTION_TRACER
 # Do not trace early boot code
-- 
2.35.3


  parent reply	other threads:[~2022-07-18 13:44 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-14  8:55 mainline build failure of powerpc allmodconfig for prom_init_check Sudip Mukherjee (Codethink)
2022-07-14  8:55 ` Sudip Mukherjee (Codethink)
2022-07-17  9:12 ` Sudip Mukherjee
2022-07-17  9:12   ` Sudip Mukherjee
2022-07-17 14:44   ` Linus Torvalds
2022-07-17 14:44     ` Linus Torvalds
2022-07-17 19:54     ` Segher Boessenkool
2022-07-17 19:54       ` Segher Boessenkool
2022-07-18  3:52       ` Michael Ellerman
2022-07-18  3:52         ` Michael Ellerman
2022-07-18 14:56         ` Segher Boessenkool
2022-07-18 14:56           ` Segher Boessenkool
2022-07-17 20:25     ` Sudip Mukherjee
2022-07-17 20:25       ` Sudip Mukherjee
2022-07-17 20:29       ` Linus Torvalds
2022-07-17 20:29         ` Linus Torvalds
2022-07-17 20:38         ` Sudip Mukherjee
2022-07-17 20:38           ` Sudip Mukherjee
2022-07-17 20:56           ` Linus Torvalds
2022-07-17 20:56             ` Linus Torvalds
2022-07-17 20:56         ` Segher Boessenkool
2022-07-17 20:56           ` Segher Boessenkool
2022-07-17 21:11           ` Linus Torvalds
2022-07-17 21:11             ` Linus Torvalds
2022-07-17 21:45             ` Segher Boessenkool
2022-07-17 21:45               ` Segher Boessenkool
2022-07-18  1:38               ` Linus Torvalds
2022-07-18  1:38                 ` Linus Torvalds
2022-07-18  4:41   ` Michael Ellerman
2022-07-18  4:41     ` Michael Ellerman
2022-07-18  7:51     ` David Laight
2022-07-18  7:51       ` David Laight
2022-07-18 13:44     ` Michael Ellerman [this message]
2022-07-18 13:44       ` [PATCH] powerpc/64s: Disable stack variable initialisation for prom_init Michael Ellerman
2022-07-18 15:03       ` Sudip Mukherjee
2022-07-18 15:03         ` Sudip Mukherjee
2022-07-18 18:34       ` Linus Torvalds
2022-07-18 18:34         ` Linus Torvalds
2022-07-27 12:02       ` Michael Ellerman
2022-07-18 19:06     ` mainline build failure of powerpc allmodconfig for prom_init_check Linus Torvalds
2022-07-18 19:06       ` Linus Torvalds
2022-07-18 22:08       ` Segher Boessenkool
2022-07-18 22:08         ` Segher Boessenkool
2022-07-18 22:55         ` Linus Torvalds
2022-07-18 22:55           ` Linus Torvalds
2022-07-19 13:35       ` Michael Ellerman
2022-07-19 13:35         ` Michael Ellerman

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=20220718134418.354114-1-mpe@ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=sudipm.mukherjee@gmail.com \
    --cc=torvalds@linux-foundation.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.