Skip to content

Some native subsystems and drivers are using libc/userspace heap. #100112

@iabdalkader

Description

@iabdalkader

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:

tmp_conn = malloc(sizeof(*tmp_conn));

key_name = (char *)malloc(key.len + 1);

Drivers:

deftgts = malloc(data_len);

*mock_eeprom = (char *)malloc(size);

lib:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions