mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fixup! tlsf: Add tracking of added tlsf memory pools
@ 2025-04-10 10:46 Ahmad Fatoum
  2025-04-11  7:14 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-04-10 10:46 UTC (permalink / raw)
  To: barebox; +Cc: David Dgien, Ahmad Fatoum

tlsf: fix KASAN poisoning of TLSF pool

By poisoning all of the heap after the first malloc, new_pool_entry
becomes a pointer to poisoned memory, which causes a KASAN error right
away at startup.

Move the kasan_poison_shadow call directly after tlsf_add_pool to
fix this.

Cc: David Dgien <dgienda125@gmail.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/tlsf_malloc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index 4acf1c1c5071..6e9d48af26bb 100644
--- a/common/tlsf_malloc.c
+++ b/common/tlsf_malloc.c
@@ -115,12 +115,12 @@ void *malloc_add_pool(void *mem, size_t bytes)
 	if (!new_pool)
 		return NULL;
 
+	kasan_poison_shadow(mem, bytes, KASAN_TAG_INVALID);
+
 	new_pool_entry = malloc(sizeof(*new_pool_entry));
 	if (!new_pool_entry)
 		return NULL;
 
-	kasan_poison_shadow(mem, bytes, KASAN_TAG_INVALID);
-
 	new_pool_entry->pool = new_pool;
 	list_add(&new_pool_entry->list, &mem_pool_list);
 
-- 
2.39.5




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

* Re: [PATCH] fixup! tlsf: Add tracking of added tlsf memory pools
  2025-04-10 10:46 [PATCH] fixup! tlsf: Add tracking of added tlsf memory pools Ahmad Fatoum
@ 2025-04-11  7:14 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-04-11  7:14 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox, David Dgien

On Thu, Apr 10, 2025 at 12:46:25PM +0200, Ahmad Fatoum wrote:
> tlsf: fix KASAN poisoning of TLSF pool
> 
> By poisoning all of the heap after the first malloc, new_pool_entry
> becomes a pointer to poisoned memory, which causes a KASAN error right
> away at startup.
> 
> Move the kasan_poison_shadow call directly after tlsf_add_pool to
> fix this.
> 
> Cc: David Dgien <dgienda125@gmail.com>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  common/tlsf_malloc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
> index 4acf1c1c5071..6e9d48af26bb 100644
> --- a/common/tlsf_malloc.c
> +++ b/common/tlsf_malloc.c
> @@ -115,12 +115,12 @@ void *malloc_add_pool(void *mem, size_t bytes)
>  	if (!new_pool)
>  		return NULL;
>  
> +	kasan_poison_shadow(mem, bytes, KASAN_TAG_INVALID);
> +
>  	new_pool_entry = malloc(sizeof(*new_pool_entry));
>  	if (!new_pool_entry)
>  		return NULL;
>  
> -	kasan_poison_shadow(mem, bytes, KASAN_TAG_INVALID);
> -
>  	new_pool_entry->pool = new_pool;
>  	list_add(&new_pool_entry->list, &mem_pool_list);
>  
> -- 
> 2.39.5
> 
> 
> 

-- 
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:[~2025-04-11  7:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-10 10:46 [PATCH] fixup! tlsf: Add tracking of added tlsf memory pools Ahmad Fatoum
2025-04-11  7:14 ` Sascha Hauer

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