CVE-2026-16666 in MCUboot
Summary
by MITRE • 11/25/2026
When MCUboot resumes an interrupted image swap it takes the number of bytes to move straight from the flash-resident status trailer. In boot_swap_image() (boot/bootutil/src/loader.c) the fresh-swap branch recomputes copy_size from the image headers and is bounded — swap_run() in boot/bootutil/src/swap_move.c carries an explicit "not enough free space" check (last_idx >= first_trailer_idx) — but that check runs only inside if (boot_status_is_reset(bs)). On the resume branch the code instead does boot_read_swap_size(fap, &bs->swap_size); copy_size = bs->swap_size; and passes the value to swap_run() with no re-derivation and no bound.
swap_run() turns that byte count into a sector index by summing sector sizes until it reaches the count, with no ceiling on the real sector count: find_last_idx() in swap_move.c and swap_offset.c, and find_last_sector_idx() in swap_scratch.c, are all while (1) loops. The resulting index is fed to boot_img_sector_off() / boot_img_sector_size() (boot/bootutil/src/bootutil_priv.h), which index the fixed BOOT_MAX_IMG_SECTORS sectors[] arrays with no bounds check. Past num_sectors the loop reads zero-initialised — and past BOOT_MAX_IMG_SECTORS, adjacent-struct — entries; a sector size of 0 makes the loop never terminate, and a bogus computed offset is handed to boot_erase_region() / boot_copy_region() as an out-of-bounds flash erase or copy.
MCUboot itself only ever writes a validated, slot-bounded swap_size (swap_misc.c, fixup_revert()), so reaching the defect requires writing the trailer from outside. Serial recovery provides exactly that: an upload writes attacker bytes contiguously from offset 0 of the primary slot (boot/boot_serial/src/boot_serial.c, via flash_area_id_from_multi_image_slot()), bounded only by img_size <= area_size, so it controls the whole trailer — magic, swap_info, op/idx/state and swap_size. The resume gate boot_status_is_reset() keys solely on those op/idx/state fields, and boot_find_status() explicitly trusts valid magic as implying valid metadata. A forged in-progress status with an oversized swap_size therefore drives the unbounded walk during swap setup — before the primary image's signature is validated, and serial recovery is unauthenticated by design.
The outcome is an out-of-bounds flash erase or copy, or a non-terminating loop, inside the bootloader: an unbootable or bricked device, with the possibility of bootloader memory corruption. That exceeds what serial recovery is designed to grant, which is only the ability to stage an image that must still pass signature verification.
Exposure requires a swap-based update backend — MCUBOOT_SWAP_USING_MOVE (the default for swap builds), MCUBOOT_SWAP_USING_SCRATCH or MCUBOOT_SWAP_USING_OFFSET; overwrite-only, direct-XIP and RAM-load builds are unaffected — together with MCUBOOT_SERIAL_RECOVERY. Without serial recovery the path is only reachable by an attacker who can already write flash directly, which is outside the threat model.
The fix is to treat the trailer's swap_size as untrusted: reject or clamp it in boot_swap_image() before it becomes copy_size, bounding it by the primary slot's usable image area (sector count x sector size, excluding the trailer) rather than the raw flash_area_get_size(), and aborting recovery with a non-zero error on overflow. The same guard should cover the independent boot_read_swap_size() reads in each backend's boot_read_image_header().
If you want to get best quality of vulnerability data, you may have to visit VulDB.
Analysis
by VulDB Data Team • 11/25/2026
The vulnerability resides within the MCUboot bootloader’s image swap mechanism, specifically affecting systems that utilize move-based or scratch-based update backends combined with serial recovery capabilities. When an interrupted firmware update is resumed, the bootloader retrieves a byte count for the remaining data to be moved directly from the flash-resident status trailer without performing any independent validation against the actual image headers. This design flaw allows an attacker who can control the contents of this trailer to dictate the volume of data processed by subsequent functions. The core issue arises because the code path responsible for resuming a swap operation bypasses the safety checks that are present in other branches, such as those used during initial swap operations where copy sizes are recomputed and bounded against available space.
In the specific function boot_swap_image(), when handling a resume scenario, the system reads the swap_size value from the status trailer and assigns it directly to the local variable copy_size without re-deriving this value from the image headers or verifying its consistency with the actual flash layout. This untrusted value is then passed to swap_run() which converts the byte count into a sector index by summing sector sizes in an infinite loop structure found in helper functions like find_last_idx and find_last_sector_idx. These loops continue until they reach the specified count, lacking any ceiling on the real sector count or validation that the target sectors exist within the allocated memory space. Consequently, if the provided swap_size is artificially inflated, these loops may iterate beyond the boundaries of the defined flash sectors array.
The resulting out-of-bounds access occurs when the computed index exceeds the maximum number of supported image sectors, BOOT_MAX_IMG_SECTORS. The code then indexes into fixed-size arrays using this invalid index without bounds checking. If the loop encounters a sector with zero size due to memory corruption or adjacent struct entries being read as zeros, it may enter an infinite non-terminating state. Alternatively, if valid but out-of-bounds data is accessed, the system proceeds to execute flash erase and copy operations on regions outside the intended primary slot area. This can lead to bootloader memory corruption, overwriting critical configuration structures or other firmware images stored in adjacent flash sectors, potentially resulting in a permanently bricked device that cannot boot.
Exploitation of this vulnerability requires specific conditions aligned with the MCUboot threat model for serial recovery. The attacker must have access to the serial interface used for firmware updates and be able to upload crafted data into the primary slot starting from offset zero. Serial recovery is designed to allow staging images without immediate authentication, relying on signature verification later in the process. However, because the status trailer can be overwritten during this initial stage, an attacker can forge a valid-looking but malicious swap state with an oversized swap_size field. The bootloader’s trust model explicitly validates magic numbers and metadata fields to determine if a resume is possible, meaning that as long as the forged trailer appears structurally valid according to these basic checks, the system will proceed with the dangerous unbounded operation before any cryptographic signature verification takes place.
The impact of this flaw extends beyond simple denial of service. By manipulating flash regions outside the primary image slot, an attacker could potentially corrupt secondary images, configuration data, or even other parts of the bootloader itself if memory layout permits adjacent access. This represents a significant escalation from the intended scope of serial recovery, which is limited to staging unauthenticated code that must still pass strict signature checks before execution. The vulnerability effectively allows pre-authentication arbitrary write and read operations within the flash memory map, undermining the integrity guarantees provided by secure boot mechanisms.
Mitigation strategies focus on treating all data retrieved from external or user-controlled sources as untrusted until validated against system constraints. Specifically, the swap_size value obtained from the status trailer must be clamped or rejected if it exceeds the maximum allowable size for the primary slot’s usable image area. This calculation should exclude the space occupied by trailers and other metadata to ensure that only valid sector ranges are targeted during copy operations. Additionally, developers should implement explicit bounds checking in all functions that convert byte counts into sector indices, ensuring loops terminate correctly even if provided with malformed input values. The same validation logic must be applied consistently across different swap backends, including those using scratch pads or offset-based moves, to prevent similar bypasses through alternative code paths.
From a standards perspective, this vulnerability aligns with CWE-125 Out-of-bounds Read and CWE-787 Out-of-bounds Write due to the lack of boundary validation on array indices derived from external input. It also relates to CWE-20 Improper Input Validation as the system fails to verify that the swap_size corresponds to actual available space within the designated flash area. In terms of MITRE ATT&CK, this flaw facilitates lateral movement or persistence by allowing an attacker to modify bootloader components directly via serial recovery, bypassing intended authentication gates. Securing these embedded systems requires rigorous input sanitization at every boundary where external data influences internal control flow and memory access patterns.