From: chalianis1@gmail.com
To: s.hauer@pengutronix.de
Cc: barebox@lists.infradead.org, Ahmad Fatoum <a.fatoum@barebox.org>,
Chali Anis <chalianis1@gmail.com>
Subject: [PATCH 04/11] tlsf: move kasan_poison_shadow into tlsf_add_pool
Date: Mon, 6 Oct 2025 00:15:05 -0400 [thread overview]
Message-ID: <20251006041512.1360284-4-chalianis1@gmail.com> (raw)
In-Reply-To: <20251006041512.1360284-1-chalianis1@gmail.com>
From: Ahmad Fatoum <a.fatoum@barebox.org>
Unallocated memory is poisoned by default to catch heap overflows.
Its control data can also be poisoned by default as the code takes care
to unpoison it on access.
Move the poisoning thus tlsf_add_pool(), so users need not worry about
it.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
Signed-off-by: Chali Anis <chalianis1@gmail.com>
---
common/tlsf.c | 7 +++++--
common/tlsf_malloc.c | 2 --
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/common/tlsf.c b/common/tlsf.c
index 8666b94ea387..4ee53a9b2f20 100644
--- a/common/tlsf.c
+++ b/common/tlsf.c
@@ -814,6 +814,7 @@ size_t tlsf_alloc_overhead(void)
pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
{
+ control_t* control = tlsf_cast(control_t*, tlsf);
block_header_t* block;
block_header_t* next;
@@ -844,7 +845,7 @@ pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
block_set_size(block, pool_bytes);
block_set_free(block);
block_set_prev_used(block);
- block_insert(tlsf_cast(control_t*, tlsf), block);
+ block_insert(control, block);
/* Split the block to create a zero-size sentinel block. */
next = block_link_next(block);
@@ -852,6 +853,9 @@ pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes)
block_set_used(next);
block_set_prev_free(next);
+ kasan_poison_shadow(mem, bytes, KASAN_TAG_INVALID);
+ kasan_poison_shadow(control, sizeof(control), KASAN_TAG_INVALID);
+
return mem;
}
@@ -927,7 +931,6 @@ tlsf_t tlsf_create_with_pool(void* mem, size_t bytes)
{
tlsf_t tlsf = tlsf_create(mem);
tlsf_add_pool(tlsf, (char*)mem + tlsf_size(), bytes - tlsf_size());
- kasan_poison_shadow(mem, bytes, KASAN_TAG_INVALID);
return tlsf;
}
diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index 6e9d48af26bb..74089fe7f390 100644
--- a/common/tlsf_malloc.c
+++ b/common/tlsf_malloc.c
@@ -115,8 +115,6 @@ 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;
--
2.34.1
next prev parent reply other threads:[~2025-10-06 4:16 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-06 4:15 [PATCH 01/11] common: filetype: add detection for x86 Linux kernel images chalianis1
2025-10-06 4:15 ` [PATCH 02/11] efi: payload: split out payload Kconfig symbols chalianis1
2025-10-06 4:15 ` [PATCH 03/11] efi: payload: add support for EFI initrd media protocol chalianis1
2025-10-06 11:31 ` Ahmad Fatoum
2025-10-06 4:15 ` chalianis1 [this message]
2025-10-06 4:15 ` [PATCH 05/11] tlsf: support on-demand requesting memory from external store chalianis1
2025-10-06 4:15 ` [PATCH 06/11] efi: payload: earlymem: allocate only the barebox needs in term of memory chalianis1
2025-10-06 11:32 ` Ahmad Fatoum
2025-10-06 4:15 ` [PATCH 07/11] efi: payload: split image handling from legacy handover boot chalianis1
2025-10-06 11:37 ` Ahmad Fatoum
2025-10-06 4:15 ` [PATCH 08/11] efi: payload: bootm: add support for efi stub boot chalianis1
2025-10-06 11:40 ` Ahmad Fatoum
2025-10-06 4:15 ` [PATCH 09/11] efi: payload: bootm: add support for fit image chalianis1
2025-10-06 11:41 ` Ahmad Fatoum
2025-10-06 4:15 ` [PATCH 10/11] efi: payload: make selectable without COMPILE_TEST chalianis1
2025-10-06 4:15 ` [PATCH 11/11] ARM: efi: add a generic defconfig for v8 efi payload chalianis1
2025-10-06 11:41 ` Ahmad Fatoum
2025-10-06 11:39 ` [PATCH 01/11] common: filetype: add detection for x86 Linux kernel images Ahmad Fatoum
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=20251006041512.1360284-4-chalianis1@gmail.com \
--to=chalianis1@gmail.com \
--cc=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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