boot: boot_serial: Bound tail write alignment in upload #2985
All Vouch review confidence checks passed
Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.39 · 241 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 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
Diff Size
diff_size
0.328
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #2985"
general
weight: 0.35
d3zd3z
bs_upload()pads the unaligned end of the last image chunk to the flashwrite alignment in a stack buffer of
BOOT_MAX_ALIGNbytes: it copies up toflash_area_align(fap) - 1remaining bytes into it and then writesflash_area_align(fap)bytes from it. Nothing relates the write alignment ofthe upload target to
BOOT_MAX_ALIGN, which defaults to 8 and is derived froma single flash device, while the target can be any area the image number maps
to. With a larger alignment the copy runs past the end of the buffer and the
write reads past it. A first chunk (offset 0) shorter than the alignment is
enough to reach this, since its length is not checked against the image
length.
This change:
BOOT_MAX_ALIGNandMCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE, so devices with large write blocksthat already rely on the unaligned buffer keep working;
upload with
MGMT_ERR_EINVALif it is zero or does not fit the buffer(before the slot is erased);
write length.
Note the behaviour change: an upload target whose write alignment is larger
than both
BOOT_MAX_ALIGNand the unaligned buffer is now refused at thefirst chunk. Previously it worked only when the image size happened to be a
multiple of the alignment.
Testing
nrf52840dk/nrf52840serial recovery builds: unaligned buffer0 and default (64), direct image upload with swap-move, direct image
upload with swap-offset
boot_serial.c)with a write block larger than 8 bytes (for example LPC55xxx or MCXN)
and an image whose size is not a multiple of the write block