← Back to Pull requests

boot: boot_serial: Bound tail write alignment in upload #2985

Closed
unknown closed this pull request without merging on Nov 25, 2026 20:37 UTC
View on GitHub
unknown unknown commented on Nov 14, 2026 21:26 UTC
Author

bs_upload() pads the unaligned end of the last image chunk to the flash
write alignment in a stack buffer of BOOT_MAX_ALIGN bytes: it copies up to
flash_area_align(fap) - 1 remaining bytes into it and then writes
flash_area_align(fap) bytes from it. Nothing relates the write alignment of
the upload target to BOOT_MAX_ALIGN, which defaults to 8 and is derived from
a 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:

  • sizes the tail buffer as the larger of BOOT_MAX_ALIGN and

  • MCUBOOT_SERIAL_UNALIGNED_BUFFER_SIZE, so devices with large write blocks
    that already rely on the unaligned buffer keep working;
  • reads the alignment once after opening the flash area and rejects the

  • upload with MGMT_ERR_EINVAL if it is zero or does not fit the buffer
    (before the slot is erased);
  • uses that one value for the remainder, the aligned write path and the final

  • write length.

    Note the behaviour change: an upload target whose write alignment is larger
    than both BOOT_MAX_ALIGN and the unaligned buffer is now refused at the
    first chunk. Previously it worked only when the image size happened to be a
    multiple of the alignment.

    Testing

  • Zephyr nrf52840dk/nrf52840 serial recovery builds: unaligned buffer

  • 0 and default (64), direct image upload with swap-move, direct image
    upload with swap-offset
  • Simulator default build unchanged (the simulator does not build

  • boot_serial.c)
  • Hardware test of serial recovery upload, ideally including a device

  • 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

    Diff: 241 lines (+180 / -61) across 3 files Reviewer: d3zd3z Review duration: 15790m
    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
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.328
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2985"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 38.8% (MEDIUM) · Higher = larger blast radius
    38.8%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 15.3% · Safe to merge
    15.3%