Skip to content
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

serial recovery: image list not working with encrypted images and single slot #1864

Closed
wag-thom opened this issue Nov 23, 2023 · 2 comments · Fixed by #1865
Closed

serial recovery: image list not working with encrypted images and single slot #1864

wag-thom opened this issue Nov 23, 2023 · 2 comments · Fixed by #1865

Comments

@wag-thom
Copy link

wag-thom commented Nov 23, 2023

Problem

In serial recovery, the image list command does not list encrypted images if only one slot is used (MCUBOOT_SINGLE_APPLICATION_SLOT)

> mcumgr -c my_conn image list
Images:
Split status: N/A (0)

Cause

A similar Issue #1753 was fixed by #1747, but the added check && MUST_DECRYPT(...) does not work for single slot applications.

if (IS_ENCRYPTED(&hdr) && MUST_DECRYPT(fap, image_index, &hdr)) {
    FIH_CALL(boot_image_validate_encrypted, fih_rc, fap,
             &hdr, tmpbuf, sizeof(tmpbuf));
} else {
...

boot_serial.c @ L297

The MUST_DECRYPT() macro seems to determine if decryption is necessary, by checking if the image is in the second slot. Since we do not have a second slot in a single slot application, the macro FLASH_AREA_IMAGE_SECONDARY() will return the index of the first slot and is therefore always true.

#define MUST_DECRYPT(fap, idx, hdr) \
    (flash_area_get_id(fap) == FLASH_AREA_IMAGE_SECONDARY(idx) && IS_ENCRYPTED(hdr))

image.h @ L160

Possible Fix

A possible fix could be to only use MUST_DECRYPT if we are not in a single slot setup:

if (IS_ENCRYPTED(&hdr) && (MUST_DECRYPT(fap, image_index, &hdr) && !MCUBOOT_SINGLE_APPLICATION_SLOT)) {
...

On the other hand, I do not exactly understand why the encrypted-flags in the image header are set at that point. The image in this scenario was decrypted in-place right after it was uploaded by serial recovery. Shouldn't the header also get updated with cleared encrypted-flags once it is decrypted? I do not exactly know how MCUboot is intended to work, so maybe that is intentional for some reason I do not see...

@thedjnK
Copy link

thedjnK commented Nov 23, 2023

I remember this issue being fixed, what commit of mcuboot are you using? Indeed seems broken

@nordicjm
Copy link
Collaborator

Fix: #1865

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants