From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 2/4] tlsf: unpoison whole block in malloc_usable_size()
Date: Mon, 24 Aug 2026 13:59:56 +0200 [thread overview]
Message-ID: <20260824120022.3299742-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260824120022.3299742-1-a.fatoum@pengutronix.de>
malloc_usable_size() tells the caller how many bytes beyond the
originally requested size may be accessed, but TLSF only unpoisons the
requested size, leaving the padding up to the block size poisoned.
free_sensitive() zeroes the whole usable size, so with CONFIG_KASAN
enabled, freeing sensitive memory whose size is not a multiple of the
poisoning granule falsely reports a use-after-poison in
memzero_explicit().
Unpoison the whole block when its usable size is queried, so callers
can do what the API promises.
Fixes: 0af97b298266 ("malloc: implement free_sensitive()")
Assisted-by: Claude:fable-5
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/tlsf_malloc.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index 36fdc307cc26..8315073105cc 100644
--- a/common/tlsf_malloc.c
+++ b/common/tlsf_malloc.c
@@ -52,7 +52,16 @@ EXPORT_SYMBOL(free);
size_t malloc_usable_size(void *mem)
{
- return tlsf_block_size(mem);
+ size_t size = tlsf_block_size(mem);
+
+ /*
+ * Callers like free_sensitive() may access the whole usable
+ * size, so unpoison the padding beyond the requested size.
+ */
+ if (size)
+ kasan_unpoison_shadow(mem, size);
+
+ return size;
}
EXPORT_SYMBOL(malloc_usable_size);
--
2.47.3
next prev parent reply other threads:[~2026-08-24 12:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 11:59 [PATCH master 1/4] of: only replace a device tree that is actually tentative Ahmad Fatoum
2026-08-24 11:59 ` Ahmad Fatoum [this message]
2026-08-24 11:59 ` [PATCH master 3/4] partitions: dos: bound extended partition chain Ahmad Fatoum
2026-08-24 11:59 ` [PATCH master 4/4] of: fdt: bound node nesting depth in __of_unflatten_dtb Ahmad Fatoum
2026-08-24 12:58 ` [PATCH master 1/4] of: only replace a device tree that is actually tentative 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=20260824120022.3299742-2-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