mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/5] ARM: mark early C setup functions as __prereloc
Date: Mon, 11 Sep 2023 17:08:57 +0200	[thread overview]
Message-ID: <20230911150900.3584523-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230911150900.3584523-1-a.fatoum@pengutronix.de>

In preparation for adding stack protector support, we need to start
marking functions run before the C environment is completely set up.

Introduce a __prereloc attribute for this use case and an even stronger
no noinstr (no instrumentation) attribute and start adding it at enough
places for bareboxproper to start up with -fstack-protector-all.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 arch/arm/cpu/common.c          | 2 +-
 arch/arm/cpu/start.c           | 4 ++--
 arch/arm/include/asm/reloc.h   | 2 +-
 arch/arm/lib64/string.c        | 2 +-
 include/linux/compiler_types.h | 7 +++++++
 lib/string.c                   | 2 +-
 6 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/arch/arm/cpu/common.c b/arch/arm/cpu/common.c
index 47da9fbe494f..e9118b450d3f 100644
--- a/arch/arm/cpu/common.c
+++ b/arch/arm/cpu/common.c
@@ -59,7 +59,7 @@ void pbl_barebox_break(void)
 /*
  * relocate binary to the currently running address
  */
-void relocate_to_current_adr(void)
+void __prereloc relocate_to_current_adr(void)
 {
 	unsigned long offset;
 	unsigned long __maybe_unused *dynsym, *dynend;
diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 2e987ec41d1e..15f5b2937227 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -137,7 +137,7 @@ static int barebox_memory_areas_init(void)
 }
 device_initcall(barebox_memory_areas_init);
 
-__noreturn __no_sanitize_address void barebox_non_pbl_start(unsigned long membase,
+__noreturn __prereloc void barebox_non_pbl_start(unsigned long membase,
 		unsigned long memsize, void *boarddata)
 {
 	unsigned long endmem = membase + memsize;
@@ -245,7 +245,7 @@ void start(unsigned long membase, unsigned long memsize, void *boarddata);
  * First function in the uncompressed image. We get here from
  * the pbl. The stack already has been set up by the pbl.
  */
-void NAKED __no_sanitize_address __section(.text_entry) start(unsigned long membase,
+void NAKED __prereloc __section(.text_entry) start(unsigned long membase,
 		unsigned long memsize, void *boarddata)
 {
 	barebox_non_pbl_start(membase, memsize, boarddata);
diff --git a/arch/arm/include/asm/reloc.h b/arch/arm/include/asm/reloc.h
index 0002c96c014c..95b4ef0af88b 100644
--- a/arch/arm/include/asm/reloc.h
+++ b/arch/arm/include/asm/reloc.h
@@ -12,7 +12,7 @@ unsigned long get_runtime_offset(void);
  * Get the offset of global variables when not running at the address we are
  * linked at.
  */
-static inline unsigned long global_variable_offset(void)
+static inline __prereloc unsigned long global_variable_offset(void)
 {
 #ifdef CONFIG_CPU_V8
 	unsigned long text;
diff --git a/arch/arm/lib64/string.c b/arch/arm/lib64/string.c
index 26a284be5a77..938790e1a9b2 100644
--- a/arch/arm/lib64/string.c
+++ b/arch/arm/lib64/string.c
@@ -7,7 +7,7 @@
 void *__arch_memset(void *dst, int c, __kernel_size_t size);
 void *__arch_memcpy(void * dest, const void *src, size_t count);
 
-static void *_memset(void *dst, int c, __kernel_size_t size)
+static __prereloc void *_memset(void *dst, int c, __kernel_size_t size)
 {
 	if (likely(get_cr() & CR_M))
 		return __arch_memset(dst, c, size);
diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index bc1b43aab0dc..9ce272bba5f3 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -305,4 +305,11 @@ struct ftrace_likely_data {
  */
 #define noinline_for_stack noinline
 
+/* code that can't be instrumented at all */
+#define noinstr \
+	noinline notrace __no_sanitize_address
+
+#define __prereloc \
+	notrace __no_sanitize_address
+
 #endif /* __LINUX_COMPILER_TYPES_H */
diff --git a/lib/string.c b/lib/string.c
index 8ea68044cc0a..166ef190d6aa 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -534,7 +534,7 @@ void *__default_memset(void * s, int c, size_t count)
 }
 EXPORT_SYMBOL(__default_memset);
 
-void __no_sanitize_address *__nokasan_default_memset(void * s, int c, size_t count)
+void __prereloc __no_sanitize_address *__nokasan_default_memset(void * s, int c, size_t count)
 {
 	char *xs = (char *) s;
 
-- 
2.39.2




  parent reply	other threads:[~2023-09-11 15:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 15:08 [PATCH 0/5] add stack protector and guard page support Ahmad Fatoum
2023-09-11 15:08 ` [PATCH 1/5] include: move PAGE_ definitions into linux/pagemap.h Ahmad Fatoum
2023-09-11 15:08 ` Ahmad Fatoum [this message]
2023-09-11 15:08 ` [PATCH 3/5] lib: add stackprotector support Ahmad Fatoum
2023-09-21  8:52   ` [PATCH] fixup! " Ahmad Fatoum
2023-09-11 15:08 ` [PATCH 4/5] ARM: mmu: catch stack overflowing into TTB with stack guard page Ahmad Fatoum
2023-09-11 15:09 ` [PATCH 5/5] commands: add stacksmash command for causing stack overflows Ahmad Fatoum
2023-09-12  4:48   ` Thorsten Scherer
2023-09-11 15:47 ` [PATCH] fixup! lib: add stackprotector support Ahmad Fatoum
2023-09-14  9:14 ` [PATCH] fixup! commands: add stacksmash command for causing stack overflows Ahmad Fatoum
2023-09-14 10:22   ` Thorsten Scherer
2023-09-14 11:05     ` Ahmad Fatoum
2023-09-21  8:49 ` [PATCH 0/5] add stack protector and guard page support Sascha Hauer

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=20230911150900.3584523-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox