Skip to content

Commit cc60441

Browse files
committed
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 bab5d00 commit cc60441

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
@@ -466,6 +466,11 @@ void *rmalloc_align(uint32_t flags, size_t bytes, uint32_t alignment)
466466
void *ptr;
467467
void *raw;
468468

469+
if (bytes > 16 * 1024 * 1024) {
470+
tr_err(&zephyr_tr, "rmalloc_align: requested %zu bytes exceeds 16MB limit", bytes);
471+
return NULL;
472+
}
473+
469474
if (alignment < sizeof(void *))
470475
alignment = sizeof(void *);
471476

0 commit comments

Comments
 (0)