fix: bound unauthenticated image size before RAM load#802
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a security-hardening issue in wolfBoot’s RAM-load paths by bounding an unauthenticated image length (read from a decrypted-but-not-yet-authenticated header) before it can drive RAM copies/decryption. This is especially important for EXT_ENCRYPTED stream-cipher configurations where ciphertext malleability can attacker-influence the decrypted length field.
Changes:
- Introduces a shared
wolfBoot_ramboot_check_size()helper to validate payload size against the RAM load region. - Uses the helper to reject oversized images in both
wolfBoot_ramboot()(RAM load) andwolfBoot_ram_decrypt()(MMU ramboot decrypt path) before copying/decrypt loops run. - Adds new unit tests (and Makefile targets) to regress oversized length, wraparound length, and ciphertext bit-flip manipulation of the length field.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/unit-tests/unit-update-ram-enc.c | Adds regression tests for encrypted/MMU RAM decrypt size-bounding (including wrap and malleation cases). |
| tools/unit-tests/Makefile | Adds build/run targets for the new encrypted RAM decrypt unit tests (fixed partitions + nopart/RAMBOOT_MAX_SIZE variants). |
| src/update_ram.c | Switches RAM-load size validation to the shared wolfBoot_ramboot_check_size() helper. |
| src/libwolfboot.c | Adds bounds checking in wolfBoot_ram_decrypt() before the decrypt/copy loop. |
| include/image.h | Adds the wolfBoot_ramboot_check_size() inline helper for consistent bounds validation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dgarske
left a comment
There was a problem hiding this comment.
Skoll Multi-Scan Review
Modes: review + review-securityOverall recommendation: COMMENT
Findings: 4 total — 4 posted, 0 skipped
4 finding(s) posted as inline comments (see file-level comments below)
Posted findings
- [Medium] [review] Bound-check edge cases not exercised: exact max-valid length and FIXED underflow guard —
tools/unit-tests/unit-update-ram-enc.c:118-300 - [Low] [review+review-security] WOLFBOOT_RAMBOOT_MAX_SIZE silently ignored when WOLFBOOT_FIXED_PARTITIONS is also defined —
src/libwolfboot.c:2418-2429 - [Low] [review-security] New length bound does not account for ENCRYPT_BLOCK_SIZE rounding of the decrypt copy loop —
src/libwolfboot.c:2418-2439 - [Low] [review] Overflow-length tcase is missing its tcase_set_timeout call —
tools/unit-tests/unit-update-ram-enc.c:323-326
Review generated by Skoll
ZD#21988