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 master] ARM64: setupc: don't invoke KASAN before relocation
Date: Sat, 15 Apr 2023 10:34:47 +0200	[thread overview]
Message-ID: <20230415083447.3069903-1-a.fatoum@pengutronix.de> (raw)

Plain memset and memcpy are checked by KASAN if enabled before calling
unchecked __memset and __memcpy respectively.

KASAN uses a kasan_initialized variable as first condition in its memory
check, but that only works after relocation. For that reason, we must
take care not to invoke KASAN before then. This was done for ARM32, but
was missing for ARM64. Do so now.

This fixes an annoying issue where network booting a KASAN-enabled barebox
twice in a row would fail: The first happened to work because the memory
kasan_initialized was placed at was zero. The second would behave
erratically, because BSS initialization would silently fail and barebox
static storage would then be initialized with the final values of the
previous run.

Fixes: 932ef7a02e2f ("ARM: Add KASan support")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
I wondered if there's a way to print a KASAN error that early, but it's
not easy. Calling even global_variable_offset() in kasan_report caused
infinite recursion, despite use of __no_sanitize_address. Printing
unconditionally could be a way around this.
---
 arch/arm/cpu/setupc_64.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/cpu/setupc_64.S b/arch/arm/cpu/setupc_64.S
index d64281c148fc..f38f893be90b 100644
--- a/arch/arm/cpu/setupc_64.S
+++ b/arch/arm/cpu/setupc_64.S
@@ -14,7 +14,7 @@ ENTRY(setup_c)
 	mov	x1, #0
 	ldr	x2, =__bss_stop
 	sub	x2, x2, x0
-	bl	memset			/* clear bss */
+	bl	__memset		/* clear bss */
 	mov	x30, x15
 	ret
 ENDPROC(setup_c)
@@ -63,7 +63,7 @@ ENTRY(relocate_to_adr)
 	sub	x19, x19, x1		/* sub address where we are actually running */
 	add	x19, x19, x0		/* add address where we are going to run */
 
-	bl	memcpy			/* copy binary */
+	bl	__memcpy		/* copy binary */
 
 	bl	sync_caches_for_execution
 
-- 
2.39.2




             reply	other threads:[~2023-04-15  8:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-15  8:34 Ahmad Fatoum [this message]
2023-04-17  6:52 ` 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=20230415083447.3069903-1-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