Skip to content

Commit 9c209bc

Browse files
lrgirdwolgirdwood
authored andcommitted
zephyr: alloc: Add 16MB allocation limit to native_sim host allocator
When building the native_sim fuzzer, the host allocator does not possess the strict bounds of the internal Zephyr memory pools. If the fuzzer generates a malformed payload requesting an excessively large size (e.g. 4GB), it passes directly to the host ASAN allocator which aborts due to OOM or protection limits. Adding a 16MB cap allows these to fail gracefully. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
1 parent 8048ea3 commit 9c209bc

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

zephyr/lib/alloc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ void *rmalloc_align(uint32_t flags, size_t bytes, uint32_t alignment)
475475
void *ptr;
476476
void *raw;
477477

478+
if (bytes > 16 * 1024 * 1024) {
479+
tr_err(&zephyr_tr, "rmalloc_align: requested %zu bytes exceeds 16MB limit", bytes);
480+
return NULL;
481+
}
482+
478483
if (alignment < sizeof(void *))
479484
alignment = sizeof(void *);
480485

0 commit comments

Comments
 (0)