mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] ARM: kasan: reserve shadow memory region
@ 2024-01-04  8:57 Ahmad Fatoum
  2024-01-04 11:23 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-01-04  8:57 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We did not have any protection in place to ensure that KASAN shadow memory
isn't overwritten during boot. Add that now to avoid strange effects
during debugging.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - fix build when CONFIG_KASAN is disabled (Sascha)
---
 arch/arm/cpu/start.c  | 4 ++++
 include/linux/kasan.h | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
index 15f5b2937227..9f4cdfe67fbf 100644
--- a/arch/arm/cpu/start.c
+++ b/arch/arm/cpu/start.c
@@ -133,6 +133,10 @@ static int barebox_memory_areas_init(void)
 		request_sdram_region("board data", (unsigned long)barebox_boarddata,
 				     barebox_boarddata_size);
 
+	if (IS_ENABLED(CONFIG_KASAN))
+		request_sdram_region("kasan shadow", kasan_shadow_base,
+				     mem_malloc_start() - kasan_shadow_base);
+
 	return 0;
 }
 device_initcall(barebox_memory_areas_init);
diff --git a/include/linux/kasan.h b/include/linux/kasan.h
index 54fb993f38ba..5fa0bebb796b 100644
--- a/include/linux/kasan.h
+++ b/include/linux/kasan.h
@@ -42,11 +42,11 @@
 #define KASAN_ALLOCA_LEFT	0xCA
 #define KASAN_ALLOCA_RIGHT	0xCB
 
-#if defined(CONFIG_KASAN) && !defined(__PBL__)
-
 extern unsigned long kasan_shadow_start;
 extern unsigned long kasan_shadow_base;
 
+#if defined(CONFIG_KASAN) && !defined(__PBL__)
+
 static inline void *kasan_mem_to_shadow(const void *addr)
 {
 	unsigned long a = (unsigned long)addr;
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] ARM: kasan: reserve shadow memory region
  2024-01-04  8:57 [PATCH v2] ARM: kasan: reserve shadow memory region Ahmad Fatoum
@ 2024-01-04 11:23 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-01-04 11:23 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Thu, Jan 04, 2024 at 09:57:36AM +0100, Ahmad Fatoum wrote:
> We did not have any protection in place to ensure that KASAN shadow memory
> isn't overwritten during boot. Add that now to avoid strange effects
> during debugging.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 -> v2:
>   - fix build when CONFIG_KASAN is disabled (Sascha)
> ---
>  arch/arm/cpu/start.c  | 4 ++++
>  include/linux/kasan.h | 4 ++--
>  2 files changed, 6 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/arch/arm/cpu/start.c b/arch/arm/cpu/start.c
> index 15f5b2937227..9f4cdfe67fbf 100644
> --- a/arch/arm/cpu/start.c
> +++ b/arch/arm/cpu/start.c
> @@ -133,6 +133,10 @@ static int barebox_memory_areas_init(void)
>  		request_sdram_region("board data", (unsigned long)barebox_boarddata,
>  				     barebox_boarddata_size);
>  
> +	if (IS_ENABLED(CONFIG_KASAN))
> +		request_sdram_region("kasan shadow", kasan_shadow_base,
> +				     mem_malloc_start() - kasan_shadow_base);
> +
>  	return 0;
>  }
>  device_initcall(barebox_memory_areas_init);
> diff --git a/include/linux/kasan.h b/include/linux/kasan.h
> index 54fb993f38ba..5fa0bebb796b 100644
> --- a/include/linux/kasan.h
> +++ b/include/linux/kasan.h
> @@ -42,11 +42,11 @@
>  #define KASAN_ALLOCA_LEFT	0xCA
>  #define KASAN_ALLOCA_RIGHT	0xCB
>  
> -#if defined(CONFIG_KASAN) && !defined(__PBL__)
> -
>  extern unsigned long kasan_shadow_start;
>  extern unsigned long kasan_shadow_base;
>  
> +#if defined(CONFIG_KASAN) && !defined(__PBL__)
> +
>  static inline void *kasan_mem_to_shadow(const void *addr)
>  {
>  	unsigned long a = (unsigned long)addr;
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-04 11:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-04  8:57 [PATCH v2] ARM: kasan: reserve shadow memory region Ahmad Fatoum
2024-01-04 11:23 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox