← Back to Pull requests

boot: bootutil: complete the trailer before a bootstrap copy is committed #2976

Open
unknown opened this pull request with 192 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 13, 2026 10:48 UTC
Author

With MCUBOOT_BOOTSTRAP in 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.

Diff: 192 lines (+144 / -48) across 2 files Reviewer: d3zd3z Review duration: 24951m
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
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
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
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% 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: 35.9% (MEDIUM) · Higher = larger blast radius
35.9%
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: 46.7% · Lower = rushed or shallow review
46.7%
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: 19.2% · Safe to merge
19.2%