[libc-commits] [libc] [libc] add option for hardened freelist (PR #205382)
Daniel Thornburgh via libc-commits
libc-commits at lists.llvm.org
Tue Jul 14 16:48:00 PDT 2026
================
@@ -80,35 +88,44 @@ template <size_t BUFF_SIZE> class FreeListHeapBuffer : public FreeListHeap {
cpp::byte buffer[BUFF_SIZE];
};
-LIBC_INLINE void FreeListHeap::init() {
+[[gnu::noinline]] LIBC_INLINE void
+FreeListHeap::init(const FreeListSecrets &secrets_arg) {
LIBC_ASSERT(!is_initialized && "duplicate initialization");
+ secrets = secrets_arg;
auto result = BlockRef::init(region());
BlockRef block = *result;
free_store.set_range({0, cpp::bit_ceil(block.inner_size())});
- free_store.insert(block);
+ free_store.insert(block, secrets);
is_initialized = true;
}
LIBC_INLINE void *FreeListHeap::allocate_impl(size_t alignment, size_t size) {
if (size == 0)
return nullptr;
- if (!is_initialized)
+ if (!is_initialized) {
+#if LIBC_COPT_HARDEN_FREELIST
----------------
mysterymath wrote:
This seems onerous from a user point of view; all of this stuff is intended to be very internal. So, we'd need to invent something user-facing, which would invariably take the form of an embedding ABI. So, probably a C function like `__libc_malloc_init_secrets` that took 3 pointer args? I'd also wonder whether we could provide a reasonable default... not sure if there's a good cross-baremetal-device way to generate secrets, or an existing API we could call? Might be worth scanning around llvm for prior art here.
https://github.com/llvm/llvm-project/pull/205382
More information about the libc-commits
mailing list