GHSA-c38r-v552-gh5g: Cortex-M module ports save a preempted user-mode module thread’s registers through its unchecked stack pointer in privileged mode

GHSA ID

GHSA‑c38r‑v552‑gh5g

CVE ID

CVE‑2026‑115653

Severity

High

CWE

CWE-787, CWE-822

Published

2026‑11‑01

Last updated

2026‑11‑01

Affected packages

Package Vulnerable versions Patched versions

ThreadX

>= 6.0.1, ⇐ 6.5.2.202603

6.5.2.202603b

Description

Summary

On the Cortex-M module ports, the PendSV handler saves a preempted thread’s callee-saved registers and its exception-return value in privileged mode, at addresses taken from the thread’s process stack pointer, without checking that pointer against the thread’s stack. A user-mode, memory-protected module that points its stack pointer just above the start of any region it may write has up to nine words — 25 with the floating-point unit — written in privileged mode into the memory immediately below that region, eight of them with values it chose, and reads back what is there when the thread is next switched in.

Details

When a thread is switched out, PendSV, running in Handler mode, reads the PSP and stores r4–r11, s16–s31 when the thread’s exception frame includes floating-point state, and the EXC_RETURN value downward from it, then records the result as the thread’s saved stack pointer. No Cortex-M module port compares the PSP, or the lowest address the stores reach, with the thread’s stack bounds, and the memory protection unit is enabled with the privileged default map, so the stores reach any memory.

A user-mode thread may set its stack pointer freely. Exception-entry stacking of the eight-word hardware frame is performed with the thread’s own privilege, so the frame must land in memory the module may write; the stores PendSV adds below it are privileged. Setting the stack pointer to 32 bytes above the start of the module’s data region, or of a writable shared region the application granted, places the hardware frame inside the region and PendSV’s stores in the 36 bytes, or 100 with floating-point state, immediately below it. On ARMv8-M ports, PSPLIM bounds the hardware frame and the thread’s own stack-pointer writes but not PendSV’s stores; a module can place a thread’s stack at the start of its data region.

When the thread is switched back in, PendSV reloads the same words in privileged mode, sets the PSP above them and branches to the reloaded EXC_RETURN value.

Impact

A user-mode module can write eight values of its choice, 24 with floating-point state, and an EXC_RETURN value into memory it is not permitted to access, immediately below the start of its data region or of any writable shared region. Below a shared region this is application memory. Below the data region it is, depending on the module manager’s memory layout, alignment padding of the module’s own allocation, or byte-pool metadata and the end of the preceding allocation. The module also reads back, on its next switch-in, whatever the kernel or application has written to those words since. Because the thread’s saved stack pointer then lies outside the module, PendSV branches in Handler mode to whatever value occupies the EXC_RETURN slot when the thread is resumed.

Affected configurations

Systems that use the Module Manager on a Cortex-M module port (Cortex-M0+, M3, M4, M7, M23 or M33, with any supported toolchain) and load a user-mode, memory-protected module that an attacker controls. A writable shared memory region granted to that module makes the target memory application data in every layout.

Affected versions: [6.0.1, 6.5.2.202603]: 6.0.1 through 6.5.2.202603 for the Cortex-M3 and M4 IAR and Cortex-M7 AC5 and IAR ports, and each other Cortex-M module port from the release that introduced it through 6.5.2.202603.

Severity

CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:L/VI:H/VA:H/SC:N/SI:N/SA:N, CVSS-B 7.0 (High). CWE-822: Untrusted Pointer Dereference; CWE-787: Out-of-bounds Write.

What occupies the memory below the module’s regions depends on the system’s layout and is stated above rather than scored as an attack requirement.

Patches

Fixed in ThreadX 6.5.2.202603b. When the preempted thread is a user-mode thread of a memory-protected module, PendSV now saves its context through its stack pointer only if the pointer is within the thread’s stack and the stores fit above the stack’s start. Otherwise it saves the context on the thread’s kernel stack, which the module cannot reach, so the thread faults when it resumes and is terminated. This applies to the Cortex-M0+, M3, M4, M7, M23 and M33 module ports for every toolchain; kernel-mode threads are unaffected.

A new test on QEMU moves two protected-module threads' stack pointers to just above the start of the shared area and of the module’s data. Without the fix, nine words below each region changed on Cortex-M3 and 25 on Cortex-M4 with the FPU, and no thread faulted; with it, nothing changed and both threads were terminated. The IAR and AC5 sources were changed identically but not assembled, and the Cortex-M0+, M7, M23 and M33 ports were not run.

Credits

Found and fixed by Frédéric Desbiens.

The analysis, fix and regression test were produced with AI assistance under human review, in accordance with the Eclipse Foundation’s Generative AI Usage Guidelines.