boot: bootutil: complete the trailer before a bootstrap copy is committed #2976
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.36) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 192 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.315
Real PR Conversation Timeline
1 comments
"Review active on #2976"
general
weight: 0.35
d3zd3z
With
MCUBOOT_BOOTSTRAPin a swap mode, boot_copy_image() writes the primary magic and erases the secondary trailer, and only then boot_perform_update() sets image_ok and copy_done. A reset between those writes leaves a primary trailer with a good magic but without image_ok and copy_done, and no request in the secondary slot. MCUboot keeps booting that image and can never revert it, since a revert needs copy_done, but boot_is_img_confirmed() reports it as not confirmed. An application that reboots a test image which does not confirm itself in time, or that refuses a new update until the running image is confirmed, is stuck. With swap-move and swap-offset the same trailer also reads as an interrupted swap in swap_status_source().Write image_ok (for a permanent or revert request, as boot_perform_update() does) and copy_done before the magic, so that the primary trailer is either complete or not valid at every point, and erase the secondary trailer only after that. swap_set_copy_done() now skips a flag that is already set, as swap_set_image_ok() does, so nothing is written twice.
The new simulator test bootstrap_with_fails interrupts a bootstrap at every flash operation, boots again, and checks that the primary slot holds the image with either a complete trailer or no trailer at all (no magic, as for an image written directly, which applications treat as confirmed). Without the fix it fails at the last trailer writes with bootstrap in swap-scratch, swap-move and swap-offset; with the fix it passes in all three.