#120198·zephyr

drivers: memc: the memc API oopses when called from user mode

Author: oliverhuahuaCreated Sep 24, 2026Updated Sep 27, 2026
Labelspriority: lowarea: Userspacearea: MEMC

Describe the bug

memc.h declares memc_read(), memc_write(), memc_get_size() and memc_read_id() as __syscall, but the header is never passed to zephyr_syscall_header() and there are no z_vrfy_ handlers. The calls work from kernel threads, and a user thread that makes any of them is killed. K_SYSCALL_LIMIT is 148 in the build below and the four memc IDs are 456 to 459.

Regression

  • This is a regression.

Steps to reproduce

  1. Build an app for qemu_x86 with CONFIG_USERSPACE=y and CONFIG_MEMC=y that defines a memc device: DEVICE_DEFINE() with a DEVICE_API(memc, ...) that implements get_mem_base, get_size and read_id.
  2. Start a K_USER thread, grant it the device with k_object_access_grant(), and call memc_get_size() from it.
  3. The thread is killed with a kernel oops. The same call from a kernel thread returns 0. mps2/an385 behaves the same.

Relevant log output

bash
user   memc_get_size()        [00:00:00.010,000] <err> os: Bad system call id 456 invoked
[00:00:00.020,000] <err> os: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0

Impact

Functional Limitation – Some features not working as expected, but system usable.

Environment

  • OS: Ubuntu 24.04 (VM on macOS 26.6)
  • Toolchain: Zephyr SDK 1.0.1
  • Commit: 55303e23f59
  • Targets: qemu_x86, mps2/an385

Additional Context

Handlers have to check the range, not only the user buffer. memc_read() and memc_write() memcpy() straight from the get_mem_base() address plus addr, so a handler that only validates data would let a user thread read or write any kernel address through addr. The bbram handlers got the same check in 8438d3b9c1a and c3ea409fc4a.

Two ways to fix it:

  1. Register the header and add drivers/memc/memc_handlers.c: check the device object and the user buffer, then addr + len against memc_get_size(), and refuse the call when the driver has no get_size.
  2. Drop __syscall until someone needs memc from user mode.

Option 1 is in #120406.

Source: zephyrproject-rtos/zephyr