Full name: StackPatch is a name, not an abbreviation. It joins the words stack, as in stack frame, and patch.
What it is
StackPatch is a hotpatching §14.33 framework for microcontroller §6.1 firmware: it repairs a known vulnerability in running code without a restart. Ming Zhou and six co-authors described it in a paper accepted at the 2025 ACM (Association for Computing Machinery) Conference on Computer and Communications Security. At the start of the vulnerable code, a breakpoint §14.29 makes the processor run an exception handler §6.15. The handler saves the registers on the stack as one block, the stack frame; patch code edits the saved frame; the handler then resumes the program from the edited frame.
Basis of this account
This account rests on the authors’ preprint on the arXiv server, arXiv:2509.10213, version 1 of 12 September 2025: Ming Zhou, Xupu Hu, Zhihao Wang, Haining Wang, Hui Wen, Limin Sun and Peng Zhang, “Dynamic Vulnerability Patching for Heterogeneous Embedded Systems Using Stack Frame Reconstruction”. The arXiv record states that the paper was accepted at ACM CCS 2025 (the Conference on Computer and Communications Security) and links the publisher’s digital object identifier (DOI) 10.1145/3719027.3765200. The published text was not read or compared. Sections 1 to 3, Section 4.1 and the first part of Section 4.2, Sections 6 to 8, and Tables 4 and 5 were read; the rest of Section 4, Section 5 (related work) and the appendix were not. Nothing was run or measured for this account.
What the paper claims
The authors make these claims.
Novelty. They call StackPatch “the first stack-frame reconstruction-based hot patching framework for embedded devices”.
Portability. Because it relies on the exception mechanism that almost every microcontroller has, one design serves three processor families: Arm (they used Cortex-M4 §6.3 boards), RISC-V (an open instruction set; RISC stands for reduced instruction set computer) and Xtensa. They name the limits of two earlier systems: HERA §21.6, an earlier hotpatching system, needs a hardware unit found only in Arm Cortex-M3 and Cortex-M4 processors, and RapidPatch §21.5 adds an eBPF §2.1 (extended Berkeley Packet Filter) virtual machine §2.3, a program that executes patches written as bytecode §2.4, which costs memory and time.
Effectiveness. Of 107 published vulnerabilities in real-time operating systems (RTOS) and libraries, StackPatch repaired 102 on four development boards §6.5. The vendor fixes of the 5 it could not repair contain dozens of edits and change four to seven macro definitions; two of them also change build files.
Speed. The whole intervention, from the exception to the return, took on average between 92 and 260 processor cycles, depending on the board and the patch. The exception handler alone took 61 to 90 cycles.
Robustness to compiler optimization §3.39. For 12 vulnerabilities built at each of the optimization levels
-O0to-O3, they found the same update points and equivalent patches, and all 12 were repaired at every level.More than code. StackPatch also applies fixes that change global variables (a new value, a removed variable, an added variable or a larger variable) or macro definitions.
Applications. They patched a bare-metal soft PLC (programmable logic controller, an industrial control computer), a heart-rate monitor and network servers while these applications kept running.
How it works
On the patching host, before deployment.
An analyst locates the vulnerable code by hand. The analyst builds the vulnerable and the officially fixed firmware, disassembles both, and compares them with the binary-comparison tool BinDiff.
The update point is the first instruction at which the two versions differ in meaning. It must not be a stack operation (
pushorpop), it must lie where a trigger can be set, and it must not lie in StackPatch’s own update service. Every variable that the fix reads must already hold its value there; the authors check this with data flow analysis §3.15 in the reverse-engineering tool Ghidra.Two maps are built. From Ghidra’s intermediate representation §3.37, a machine-independent form of the code, StackPatch derives which register holds each local variable at the update point. From the order in which the modified exception handler saves registers, it derives the offset from the stack pointer at which each register is saved. Composing the two maps gives each variable’s position in the saved frame.
The official C fix is rewritten so that every variable becomes a read or a write at its position in the frame. The patch may change the saved return value and the saved return address, but it may not push or pop.
A filter rejects a patch that contains an unbounded loop, a call to a C function or a dangerous instruction, and a patch that is too slow. The delay is , the time of the exception handler, of finding the patch and of running it. With the timeout §9.34 of the watchdog §6.16, the timer that resets a device that stops responding, and the worst-case execution time §9.33 of a critical task, the delay must stay below .
On the device.
An update service of the lowest priority (in an RTOS, the idle task; on bare metal, the end of a control cycle) receives a list of patches over Bluetooth, Wi-Fi or a wired debug or serial connection, stores each patch in RAM and sets its trigger.
The trigger is a hardware breakpoint (an address comparator in the processor, of which 2 to 8 are typically available), a software breakpoint (the instruction at the update point is replaced by a breakpoint instruction such as
bkpton Arm,ebreakon RISC-V orbreakon Xtensa; this works only for code in RAM) or a hook (a jump placed in the code).When the program counter §2.9 reaches the update point, the processor raises an exception. The handler selects the stack in use (Arm Cortex-M processors have two stack pointers, one for the operating system and interrupts §6.11 and one for tasks), reserves space, and saves the return address first and then the general registers. This saved block is the frame . The handler sets the processor status so that the patch runs at the priority of the interrupted task; more urgent tasks can still preempt it.
A dispatcher finds the patch for this address by binary search in a table, and the patch runs on the frame, turning it into the edited frame .
The handler restores the general registers from , restores the return address last, releases the space and returns. Execution continues at the return address stored in .
The edited return address decides where execution continues. Pass sets it just past the update-point instruction. That instruction never ran: the trigger fires before it executes, and a software breakpoint has even overwritten it. The patch must therefore perform the instruction’s work itself. Redirect sets it either to the vulnerable function’s own return instruction, so that the function returns to its caller at once, or to the first instruction after the vulnerable code.
Worked example
This is the preprint’s own example; only the packet values are invented. The vulnerability CVE-2018-16601 (CVE stands for Common Vulnerabilities and Exposures, a public catalog of vulnerabilities) affects the network code of FreeRTOS, a widely used open-source RTOS, up to version 10.0.1. The function prvProcessIPPacket, which handles a received IP (Internet Protocol) packet, does not check the header length that the packet declares. The official fix adds a check: the header length must not exceed the received data length minus the 14-byte Ethernet header, and must be at least 20 bytes, the minimum IPv4 (Internet Protocol version 4) header.
The firmware is compiled for an Arm Cortex-M4 into Thumb-2 §4.40 code, which mixes 16-bit instructions of the compact Thumb instruction set with 32-bit instructions. In this code the header length is already in register R6 at the update point 0x8004CCA. That instruction, ldrb.w r8, [r9, #0x17], is 4 bytes long and loads one byte, the protocol field of the packet, into register R8. It is the first instruction whose meaning differs between the versions, and a software breakpoint replaces it.
The frame is a sequence of 32-bit words counted from the stack pointer, which the patch, a C function, receives as sp, a pointer to 32-bit words. Word 0 holds the value that tells the exception return which stack and mode to resume. Words 1 to 8 hold R4 to R11, which the handler saved. Words 9 to 16 hold R0, R1, R2, R3, R12, the link register §4.45 (LR), the return address and the combined program status register (xPSR), which the processor saved automatically on entry. So *(sp + 3u) (the suffix u marks an unsigned constant) is word 3, at byte offset : the saved R6, the header length. The descriptor of the received buffer is addressed by R4 (word 1), the packet by R9 (word 6), the return value R0 is word 9 (byte offset ) and the return address is word 15 (byte offset ).
The patch does the official fix’s work on the frame.
Let be the data length, which the descriptor stores at offset
0x1C. If word 3 is larger than , or smaller than 20, the patch writes the constanteReleaseBufferinto word 9, so that the function will return “release this buffer”, and adds 174 to word 15. The return address becomes0x8004CCAplus 174, which is0xAEin hexadecimal, giving0x8004D78: the function’s return instructionpop.w {r4-r10, pc}, which restores the registers that the function saved on entry and returns to the caller.Otherwise the patch performs the replaced instruction itself: it stores the byte at the packet address (word 6) plus
0x17into word 5, the saved R8, and adds 4 to word 15, so that execution resumes at0x8004CCE, just after the 4-byte instruction.
Take a received frame of 60 bytes, so the data length is 60 and the bound is . The low 4 bits of the first header byte give the header length in 4-byte words. An honest packet whose first header byte is 0x45 declares bytes. Since and , the patch passes: R8 receives the protocol byte and the function continues as before. A crafted packet whose first header byte is 0x4F declares bytes. Since , the patch makes the function return eReleaseBuffer before it reads past the received data.
On the nRF52840 §6.4 board, whose Cortex-M4 runs at 64 MHz (megahertz, millions of cycles per second), the largest average total the authors report for that board, 259 cycles, is microseconds.
What this account does not establish
The results are the authors’ own, and this account reproduced none of them.
Locating the vulnerable code and choosing the update point are manual; the authors list this as a limitation. The frame positions are correct only if the register map that the analysis derived matches the compiled code at the update point.
The filter checks time, loops, calls and kinds of instruction. It does not show that the patched function behaves like the officially fixed one, nor that the frame the patch leaves behind is valid for the code at the new return address. Both rest on the analyst’s choice of update point and return target.
Under Pass, the patch must redo the replaced instruction completely. If that instruction also set the condition flags §4.42, the bits in the status register that record the outcome of a comparison, the patch would also have to update word 16. This is an observation of this account, not of the paper; the paper’s example instruction is a load, which sets no flags.
The authors state that StackPatch targets single-core processors. With several cores, per-core caches could disagree during a hot patch, and they leave the handling of this to future work.
Patches live in RAM and are lost when the device loses power, as the authors note.
The preprint does not describe how a device checks that a received patch comes from an authorized sender.
The authors state that StackPatch does not robustly support fixes that change several multi-line macros or complex expressions at once, or fixes that change build or configuration files.
Questions answered
What must a reconstructed frame preserve?
A reconstructed frame must preserve everything that the code at the resume address will read, in exactly the place and form that this code expects. The frame is the block of registers that an exception handler saved on the stack; a patch edits it, and the handler reloads it, so the processor resumes in whatever state the edited frame describes. In detail, the frame must hold:
a valid resume address: the start of a whole instruction in the intended code, at a point whose expected stack layout matches the frame, for example the function’s own epilogue, the code that restores saved registers and returns; on Arm Cortex-M processors the saved status register must also keep the bit that marks Thumb code;
every live value: each register or stack slot that the code from the resume address reads before overwriting it, its live-in registers §4.44, holds the value the repaired program would have there, under the register assignment that the compiler chose at the resume address, which can differ from the one at the update point;
what the function promised its caller: the callee-saved registers and the stack pointer reach the caller unchanged, and the stack keeps the alignment §4.22 that the calling convention requires, 8 bytes at function calls under the Arm procedure call standard;
the return value and the return path: if the patch makes the function return early, the result sits in the result register (R0 on Arm), and the function returns through its own epilogue to its real caller;
all effects of a replaced instruction: its result register, any memory it writes and any condition flags it sets;
the processor state: the saved status register, the record of which stack and privilege mode §6.10 to return to, and the interrupt priority.
Memory-safety checks, which show only that the patch writes inside the frame, establish none of these properties. StackPatch (Zhou and others, 2025), a hotpatching framework for microcontrollers, protects several of them through design rules: the update point avoids stack operations, a patch may not push or pop, it redirects only to the function’s own return instruction or to the instruction after the vulnerable code, and the handler restores the return address last. The others, above all the live values and the full effects of a replaced instruction, still rest on the analyst’s choice of update point and return target and on the patch code itself.
Related entries: Live state transfer and representation invariants (§19.5.2), Native application binary interface (ABI) (§12.47), Dynamic patching and hot update (§14.33), Breakpoint and watchpoint (§14.29), Exception and fault handler (§6.15), Link register (LR) (§4.45), Live-in register (§4.44), Condition flags (APSR) (§4.42), RapidPatch: virtual patches and trigger contracts (§21.5), HERA: hardware-assisted hotpatching (§21.6), AutoPatch: deriving a hotpatch from an official repair (§21.7), Kintsugi: code shadowing and a patch-application boundary (§21.8). Further reading: [210].