← Back to Pull requests

boot: espressif: bound flash_area_get_sectors to caller capacity #2899

Open
sylvioalves opened this pull request with 18 lines diff across 2 files
View on GitHub
sylvioalves sylvioalves commented on Oct 14, 2026 15:23 UTC
Author

The Espressif port's flash_area_get_sectors() ignored the capacity passed in *count and wrote one entry for every flash sector in the area. With 4 KiB sectors and MCUBOOT_MAX_IMG_SECTORS at 512, any image slot or scratch area larger than 2 MiB overran the bootutil sector table on every boot. The function also dereferenced a NULL pointer when given an unknown flash area ID.

The function now stops at the given capacity and returns -ENOMEM, matching the Zephyr flash map, and rejects unknown IDs. A second commit adds static assertions on the configured slot and scratch sizes, so a layout that can never work fails at build time instead of at boot.

How to test

Build the port with an image slot larger than 2 MiB (768 sectors):

cd boot/espressif
printf 'CONFIG_ESP_FLASH_SIZE=8MB\nCONFIG_ESP_APPLICATION_SIZE=0x300000\nCONFIG_ESP_IMAGE0_SECONDARY_START_ADDRESS=0x320000\nCONFIG_ESP_SCRATCH_OFFSET=0x620000\n' > big-slot.conf
cmake -DCMAKE_TOOLCHAIN_FILE=tools/toolchain-esp32c3.cmake -DMCUBOOT_TARGET=esp32c3 -DESP_HAL_PATH=<ESP_HAL_PATH> -DMCUBOOT_CONFIG_FILE="$PWD/port/esp32c3/bootloader.conf $PWD/big-slot.conf" -B build -GNinja
ninja -C build/

Without this change the build succeeds and the bootloader writes past the end of the sector table at boot. With it, the build fails with Image slot exceeds MCUBOOT_MAX_IMG_SECTORS sectors.

The change is not target-specific, so the same steps apply to other targets:

cmake -DCMAKE_TOOLCHAIN_FILE=tools/toolchain-esp32.cmake -DMCUBOOT_TARGET=esp32 -DESP_HAL_PATH=<ESP_HAL_PATH> -DMCUBOOT_CONFIG_FILE="$PWD/port/esp32/bootloader.conf $PWD/big-slot.conf" -B build -GNinja
cmake -DCMAKE_TOOLCHAIN_FILE=tools/toolchain-esp32s3.cmake -DMCUBOOT_TARGET=esp32s3 -DESP_HAL_PATH=<ESP_HAL_PATH> -DMCUBOOT_CONFIG_FILE="$PWD/port/esp32s3/bootloader.conf $PWD/big-slot.conf" -B build -GNinja

Diff: 18 lines (+17 / -1) across 2 files Reviewer: nordicjm Review duration: 5989m
All Vouch review confidence checks passed
Residual risk 0.06 = Change Risk (0.22) × (1 − Review Confidence (0.72)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.22 · 18 lines diff across 2 files
0.22
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.54 · 3 substantive comment(s)
0.54
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
71%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.176
Real PR Conversation Timeline
6 items
sylvioalves sylvioalves commented on Oct 14, 2026 20:54 UTC
Author

@nordicjm any ideas why CI is failing?

nordicjm nordicjm commented on Oct 15, 2026 06:09 UTC
Contributor

@nordicjm any ideas why CI is failing?

Can be ignored, the pypy project broke a feature and did a release, they've fixed it but not done another release

nordicjm nordicjm approved these changes on Oct 16, 2026 11:22 UTC
Approved Reviewer

Approved these changes.

nordicjm nordicjm commented on Oct 16, 2026 11:22 UTC
Contributor

@almir-okato can you review?

almir-okato almir-okato approved these changes on Oct 16, 2026 12:56 UTC
Approved Reviewer

Approved these changes.

Reviewers
Assignees
sylvioalves sylvioalves
Labels
risk: low confidence: 71.6% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 22.1% (LOW) · Higher = larger blast radius
22.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 71.6% · Lower = rushed or shallow review
71.6%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 6.3% · Safe to merge
6.3%