Skip to content

boot: bootutil: Fix pure image validation check with offset swap #2433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions boot/bootutil/src/image_validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,22 @@ BOOT_LOG_MODULE_DECLARE(mcuboot);
*
* Value of TLV does not matter, presence decides.
*/
static int bootutil_check_for_pure(const struct image_header *hdr,
const struct flash_area *fap)
#if defined(MCUBOOT_SWAP_USING_OFFSET)
static int bootutil_check_for_pure(const struct image_header *hdr, const struct flash_area *fap,
uint32_t start_off)
#else
static int bootutil_check_for_pure(const struct image_header *hdr, const struct flash_area *fap)
#endif
{
struct image_tlv_iter it;
uint32_t off;
uint16_t len;
int32_t rc;

#if defined(MCUBOOT_SWAP_USING_OFFSET)
it.start_off = start_off;
#endif

rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_SIG_PURE, false);
if (rc) {
return -1;
Expand Down Expand Up @@ -246,19 +254,23 @@ bootutil_img_validate(struct boot_loader_state *state,
}
#endif

#if defined(MCUBOOT_SWAP_USING_OFFSET)
it.start_off = boot_get_state_secondary_offset(state, fap);
#endif

#if defined(MCUBOOT_SIGN_PURE)
/* If Pure type signature is expected then it has to be there */
#if defined(MCUBOOT_SWAP_USING_OFFSET)
rc = bootutil_check_for_pure(hdr, fap, it.start_off);
#else
rc = bootutil_check_for_pure(hdr, fap);
#endif
if (rc != 0) {
BOOT_LOG_DBG("bootutil_img_validate: pure expected");
goto out;
}
#endif

#if defined(MCUBOOT_SWAP_USING_OFFSET)
it.start_off = boot_get_state_secondary_offset(state, fap);
#endif

rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_ANY, false);
if (rc) {
BOOT_LOG_DBG("bootutil_img_validate: TLV iteration failed %d", rc);
Expand Down
Loading