Skip to content

Commit fa4d1a0

Browse files
authored
Merge pull request #725 from danielinux/fixes-2026-03-16
Fix back-end for keyvaults, minor delta trailing escape, TPM seal/unseal size, elf digest timing
2 parents 3932343 + e52beab commit fa4d1a0

20 files changed

+488
-31
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,19 @@ tools/unit-tests/unit-string
158158
tools/unit-tests/unit-update-flash
159159
tools/unit-tests/unit-update-flash-enc
160160
tools/unit-tests/unit-update-ram
161+
tools/unit-tests/unit-boot-x86-fsp
162+
tools/unit-tests/unit-image-rsa
163+
tools/unit-tests/unit-multiboot
164+
tools/unit-tests/unit-psa_store
165+
tools/unit-tests/unit-qspi-flash
166+
tools/unit-tests/unit-tpm-rsa-exp
167+
tools/unit-tests/unit-image-nopart
168+
tools/unit-tests/unit-image-sha3-384
169+
tools/unit-tests/unit-image-sha384
170+
tools/unit-tests/unit-store-sbrk
171+
tools/unit-tests/unit-tpm-blob
172+
tools/unit-tests/unit-update-disk
173+
161174

162175

163176
# Elf preprocessing tools

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ set(WOLFBOOT_SOURCES "include/loader.h"
557557
"src/image.c"
558558
"src/loader.c")
559559

560+
if((DEFINED WOLFCRYPT_TZ_PKCS11 AND NOT WOLFCRYPT_TZ_PKCS11 STREQUAL "0") OR
561+
(DEFINED WOLFCRYPT_TZ_PSA AND NOT WOLFCRYPT_TZ_PSA STREQUAL "0"))
562+
list(APPEND WOLFBOOT_SOURCES "src/store_sbrk.c")
563+
endif()
564+
560565
if(DEFINED WOLFCRYPT_TZ_PSA AND NOT WOLFCRYPT_TZ_PSA STREQUAL "0")
561566
list(APPEND WOLFBOOT_SOURCES "src/dice/dice.c")
562567
endif()

hal/stm32h5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void RAMFUNCTION hal_flash_opt_unlock(void)
323323
DMB();
324324
FLASH_OPTKEYR = FLASH_OPTKEY2;
325325
DMB();
326-
while ((FLASH_CR & FLASH_CR_LOCK) != 0)
326+
while ((FLASH_OPTCR & FLASH_OPTCR_OPTLOCK) != 0)
327327
;
328328
}
329329

hal/stm32l5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void RAMFUNCTION hal_flash_opt_unlock(void)
228228
DMB();
229229
FLASH_OPTKEYR = FLASH_OPTKEY2;
230230
DMB();
231-
while ((FLASH_CR & FLASH_CR_LOCK) != 0)
231+
while ((FLASH_CR & FLASH_CR_OPTLOCK) != 0)
232232
;
233233
}
234234

hal/stm32u5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void RAMFUNCTION hal_flash_opt_unlock(void)
158158
DMB();
159159
FLASH_NS_OPTKEYR = FLASH_OPTKEY2;
160160
DMB();
161-
while ((FLASH_NS_CR & FLASH_CR_LOCK) != 0)
161+
while ((FLASH_NS_CR & FLASH_CR_OPTLOCK) != 0)
162162
;
163163
}
164164
}

lib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ target_link_libraries(wolfcrypt target user_settings)
219219
target_compile_definitions(
220220
wolfcrypt
221221
PUBLIC WOLFSSL_USER_SETTINGS
222-
PRIVATE ${WOLFCRYPT_DEFS} ${SIGN_OPTIONS})
222+
PRIVATE ${WOLFCRYPT_DEFS} ${SIGN_OPTIONS} ${WOLFBOOT_DEFS})
223223

224224
if(WOLFBOOT_SMALL_STACK)
225225
target_compile_definitions(wolfcrypt PRIVATE WOLFBOOT_SMALL_STACK XMALLOC_USER)

options.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ ifeq ($(WOLFCRYPT_TZ_PKCS11),1)
793793
CFLAGS+=-I$(WOLFBOOT_LIB_WOLFPKCS11)
794794
CFLAGS+=-DWP11_HASH_PIN_COST=3
795795
LDFLAGS+=--specs=nano.specs
796+
WOLFCRYPT_OBJS+=src/store_sbrk.o
796797
WOLFCRYPT_OBJS+=src/pkcs11_store.o
797798
WOLFCRYPT_OBJS+=src/pkcs11_callable.o
798799
WOLFCRYPT_OBJS+=$(WOLFBOOT_LIB_WOLFSSL)/wolfcrypt/src/pwdbased.o
@@ -839,6 +840,7 @@ ifeq ($(WOLFCRYPT_TZ_PSA),1)
839840
WOLFPSA_CFLAGS+=-I$(WOLFBOOT_LIB_WOLFPSA)
840841
WOLFPSA_CFLAGS+=-I$(WOLFBOOT_LIB_WOLFPSA)/wolfpsa
841842
LDFLAGS+=--specs=nano.specs
843+
WOLFCRYPT_OBJS+=src/store_sbrk.o
842844
WOLFCRYPT_OBJS+=src/psa_store.o
843845
WOLFCRYPT_OBJS+=src/arm_tee_psa_veneer.o
844846
WOLFCRYPT_OBJS+=src/arm_tee_psa_ipc.o

src/delta.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
397397

398398
if (!found) {
399399
if (*(ctx->src_b + ctx->off_b) == ESC) {
400+
if ((p_off + 1) >= (len - BLOCK_HDR_SIZE))
401+
break;
400402
*(patch + p_off++) = ESC;
401403
*(patch + p_off++) = ESC;
402404
} else {
@@ -407,6 +409,8 @@ int wb_diff(WB_DIFF_CTX *ctx, uint8_t *patch, uint32_t len)
407409
}
408410
while ((p_off < len - BLOCK_HDR_SIZE) && ctx->off_b < ctx->size_b) {
409411
if (*(ctx->src_b + ctx->off_b) == ESC) {
412+
if ((p_off + 1) >= (len - BLOCK_HDR_SIZE))
413+
break;
410414
*(patch + p_off++) = ESC;
411415
*(patch + p_off++) = ESC;
412416
} else {

src/image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ int wolfBoot_check_flash_image_elf(uint8_t part, unsigned long* entry_out)
19891989

19901990
/* Finalize SHA calculation */
19911991
final_hash(&ctx, calc_digest);
1992-
if (memcmp(calc_digest, exp_digest, WOLFBOOT_SHA_DIGEST_SIZE) != 0) {
1992+
if (!image_CT_compare(exp_digest, calc_digest, WOLFBOOT_SHA_DIGEST_SIZE)) {
19931993
wolfBoot_printf("ELF: [CHECK] SHA verification FAILED\n");
19941994
wolfBoot_printf(
19951995
"ELF: [CHECK] Expected %02x%02x%02x%02x%02x%02x%02x%02x\n",

src/pkcs11_store.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <string.h>
2525

2626
#include "hal.h"
27+
#include "store_sbrk.h"
2728

2829
#ifdef SECURE_PKCS11
2930

@@ -72,17 +73,7 @@ void * _sbrk(unsigned int incr)
7273
{
7374
static uint8_t *heap = NULL;
7475
static uint32_t heapsize = (uint32_t)&_heap_size;
75-
void *old_heap = heap;
76-
(void)heapsize;
77-
if (((incr >> 2) << 2) != incr)
78-
incr = ((incr >> 2) + 1) << 2;
79-
80-
if (heap == NULL) {
81-
heap = (uint8_t*)&_start_heap;
82-
old_heap = heap;
83-
} else
84-
heap += incr;
85-
return old_heap;
76+
return wolfboot_store_sbrk(incr, &heap, (uint8_t *)&_start_heap, heapsize);
8677
}
8778
#endif
8879

@@ -227,7 +218,7 @@ static void check_vault(void)
227218

228219
static void delete_object(int32_t type, uint32_t tok_id, uint32_t obj_id)
229220
{
230-
struct obj_hdr *hdr = (struct obj_hdr *)cached_sector;
221+
struct obj_hdr *hdr = (struct obj_hdr *)(cached_sector + STORE_PRIV_HDR_OFFSET);
231222
check_vault();
232223
memcpy(cached_sector, vault_base, WOLFBOOT_SECTOR_SIZE);
233224

0 commit comments

Comments
 (0)