-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Summary
Some native Zephyr subsystems and drivers use malloc instead of the kernel heap, as they should. This is not only inconsistent with other subsystems and drivers, but also problematic because:
a) It may introduce a security risk, since libc heap memory is user-accessible
b) Those allocations can fail if CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=0.
For example, the following should probably use k_malloc:
Subsystem:
zephyr/subsys/sensing/sensor_mgmt.c
Line 356 in ad867a1
| tmp_conn = malloc(sizeof(*tmp_conn)); |
| key_name = (char *)malloc(key.len + 1); |
Drivers:
zephyr/drivers/i3c/i3c_common.c
Line 1297 in ad867a1
| deftgts = malloc(data_len); |
| *mock_eeprom = (char *)malloc(size); |
lib:
zephyr/lib/posix/options/net.c
Line 141 in ad867a1
| ni = malloc((n + 1) * sizeof(*ni)); |
I was going to send fixes, but I thought I should raise an issue first, perhaps I'm missing something obvious, or there's a good reason those files are using malloc.
Describe the solution you'd like
Use kernel heap for Zephyr subsystems drivers.
Alternatives
No response
Additional Context
No response