Summary
Zephyr's flash_copy() system call may trust user-controlled device pointers when userspace is enabled, allowing an unprivileged thread to pass forged or invalid kernel object references.
Under those conditions, the kernel may call attacker-chosen function pointers, potentially enabling privilege escalation into supervisor mode, with crashes or information disclosure as additional outcomes.
Affected context
The issue occurs in Zephyr builds with CONFIG_USERSPACE enabled, where z_vrfy_flash_copy() serves as the kernel-side boundary for a userspace caller. Risk is present when the system call accepts src_dev and dst_dev without verifying that they are permitted, registered flash-driver objects before the implementation dereferences their driver API tables.
Exploit preconditions
- Attack surface: The userspace-facing
flash_copy()system call - Required access: An unprivileged local thread able to execute userspace code and invoke the system call
- Trigger point: Kernel verification of the source and destination device arguments
- Why exploitation is possible: Missing device-object validation permits user-controlled pointers to reach kernel code that dereferences device structures and invokes their driver API function tables
Why this happens
The verification handler validated the output buffer but did not validate the src_dev and dst_dev pointers with the flash-driver object checks used by sibling system calls. As a result, untrusted pointer values crossed the userspace-to-kernel boundary and were later treated as valid kernel objects.
This maps primarily to CWE-822: Untrusted Pointer Dereference. The related CWE-862: Missing Authorization concern reflects the absence of an authorization-style check confirming that the calling thread may use the referenced flash-driver objects. The insecure pattern is accepting caller-supplied object references without validating object identity, type, registration, and access permissions before dereference or indirect function dispatch.
Potential impact
- An unprivileged userspace thread may execute code with supervisor-mode privileges
- The system may experience a kernel crash or denial of service
- Invalid pointer handling may cause out-of-bounds reads or other memory-safety failures
- Sensitive kernel or device-related information could be disclosed
- Other protected system resources may be accessed or modified
General mitigation guidance
Mitigation generally centers on enforcing a complete kernel object trust boundary for every userspace argument.
Common defensive patterns include:
- Validate every device pointer with the appropriate object-type and driver-permission check before dereference
- Confirm that referenced objects are registered kernel objects and are authorized for the calling thread
- Keep pointer validation immediately at the system-call boundary
- Avoid indirect function-table dispatch until object identity and access checks succeed
- Apply least-privilege permissions to userspace threads and device capabilities
- Prefer secure-by-default syscall wrappers that consistently validate all pointer-bearing arguments
How teams detect issues like this
Detection approaches can include:
- Static analysis rules identifying system-call handlers that pass userspace pointers directly to implementations
- Searches for device-structure dereferences or function-table calls without preceding object validation
- Code review checks comparing each syscall verifier with equivalent sibling handlers
- Policy enforcement requiring type, registration, and authorization checks for kernel object references
- Runtime testing with malformed or unauthorized object references to verify rejection without dereference
Automated code review and taint-analysis tools may help identify user-controlled pointers reaching indirect calls.

