Skip to content

Missing negative-offset/overflow check in SF32LB MPI QSPI NOR flash driver allows out-of-bounds read and write

Moderate
d3zd3z published GHSA-c6wh-gwg4-fj5j Aug 7, 2026

Software

zephyr

Affected versions

>= 4.3.0, <= 4.4.1

Patched versions

4.4.2

Description

The SF32LB MPI QSPI NOR flash driver (drivers/flash/flash_sf32lb_mpi_qspi_nor.c) validated the flash offset and length on its read and write paths with the test (offset + size) > data->size. Because offset is a signed off_t while size is unsigned, a negative offset is converted to a large unsigned value and the addition can wrap to a small result that passes the check. The read path then performs memcpy(dst, (void *)(data->base + offset), size) and the write path programs flash at offset and cache-invalidates data->base + offset, in both cases accessing memory outside the mapped flash window. The driver's erase path already rejected negative offsets, but read and write did not.

In builds with CONFIG_USERSPACE, flash_read and flash_write are syscalls whose verifiers validate the device object and the caller's buffer but deliberately delegate offset bounds checking to the driver. An unprivileged thread that has been granted access to this flash device can therefore call the syscall with a crafted negative offset and a buffer valid in its own memory domain, and reach the unchecked access.

The most direct impact is on the read path: by choosing a negative offset and matching size, an attacker slides the memcpy source below the flash base and copies arbitrary CPU-addressable memory into its own buffer, disclosing memory it is not authorized to read. The write path additionally allows programming flash at an out-of-range address and invalidating an attacker-chosen cache range, affecting integrity and availability. Reachability requires userspace to be enabled and the raw flash device object to be granted to an untrusted thread.

The fix replaces the check with qspi_nor_range_is_valid(), which rejects negative offsets and performs the bound comparison in overflow-safe 64-bit arithmetic on both paths, and additionally adds an SRAM DMA bounce buffer plus source/destination overlap rejection to prevent a separate DMA bus-hang condition.

Affected components

  • drivers/flash/flash_sf32lb_mpi_qspi_nor.c

Affected versions

v4.3.0 and v4.4.0 (driver present since the v4.3.0 release; fix not yet in a release tag)

Fix

Fixed (merged) in 909eb56

Projected fixed version: 4.5.0 (the fix is merged on main but not yet released; this forecast should be confirmed against the actual release).

Introduced by: f9cca21 (drivers: flash: sf32lb_mpi_qspi_nor: add initial driver), first released in v4.3.0

Evidence

  • drivers/flash/flash_sf32lb_mpi_qspi_nor.c:342-356 — post-fix read path uses qspi_nor_range_is_valid(); pre-fix used (offset + size) > data->size, which a negative/overflowing offset bypasses before memcpy from data->base+offset
  • drivers/flash/flash_sf32lb_mpi_qspi_nor.c:360-374 — write path same broken guard pre-fix; new overflow-safe validation plus NULL/zero handling
  • drivers/flash/flash_sf32lb_mpi_qspi_nor.c:289-300 — new qspi_nor_range_is_valid(): rejects offset<0 and computes size <= (uint64_t)data->size - (uint64_t)offset
  • drivers/flash/flash_handlers.c:11-30 — z_vrfy_flash_read/write validate device object and user buffer (K_SYSCALL_MEMORY_READ/WRITE) but NOT offset; offset bounds checking delegated to the driver = the privilege boundary
  • include/zephyr/drivers/flash.h:291,319 — flash_read/flash_write are __syscall, reachable from userspace threads granted the flash device object
  • drivers/flash/flash_sf32lb_mpi_qspi_nor.c (pre-fix erase) — erase already guarded (offset < 0) || (offset + size) > data->size, confirming read/write were the inconsistent, under-validated paths

Patches

Branch Pull request Status
main #107793 merged
v4.4-branch #112433 merged
v4.3-branch #112434 open

For more information

If you have any questions or comments about this advisory:

embargo: 2026-08-07

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Local
Attack complexity
Low
Privileges required
Low
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
Low
Availability
Low

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:L/A:L

CVE ID

CVE-2026-11743

Weaknesses

Out-of-bounds Read

The product reads data past the end, or before the beginning, of the intended buffer. Learn more on MITRE.