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: David Dgien <dgienda125@gmail.com>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] fixup! tlsf: Add tracking of added tlsf memory pools
Date: Thu, 10 Apr 2025 12:46:25 +0200	[thread overview]
Message-ID: <20250410104625.2500755-1-a.fatoum@pengutronix.de> (raw)

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




             reply	other threads:[~2025-04-10 11:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10 10:46 Ahmad Fatoum [this message]
2025-04-11  7:14 ` 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=20250410104625.2500755-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=dgienda125@gmail.com \
    /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