Skip to content

Commit da2e2ab

Browse files
d3zd3zdavidvincze
authored andcommitted
boot: Enforce TLV entries to be protected
Only allow TLV entries that are needed for signature verification to be placed in the unprotected area of the TLV. Signed-off-by: David Brown <david.brown@linaro.org>
1 parent ea1cdfd commit da2e2ab

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

boot/bootutil/src/image_validate.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,30 @@ bootutil_get_img_security_cnt(struct image_header *hdr,
349349
return 0;
350350
}
351351

352+
#ifndef ALLOW_ROGUE_TLVS
353+
/*
354+
* The following list of TLVs are the only entries allowed in the unprotected
355+
* TLV section. All other TLV entries must be in the protected section.
356+
*/
357+
static const uint16_t allowed_unprot_tlvs[] = {
358+
IMAGE_TLV_KEYHASH,
359+
IMAGE_TLV_PUBKEY,
360+
IMAGE_TLV_SHA256,
361+
IMAGE_TLV_SHA384,
362+
IMAGE_TLV_RSA2048_PSS,
363+
IMAGE_TLV_ECDSA224,
364+
IMAGE_TLV_ECDSA_SIG,
365+
IMAGE_TLV_RSA3072_PSS,
366+
IMAGE_TLV_ED25519,
367+
IMAGE_TLV_ENC_RSA2048,
368+
IMAGE_TLV_ENC_KW,
369+
IMAGE_TLV_ENC_EC256,
370+
IMAGE_TLV_ENC_X25519,
371+
/* Mark end with ANY. */
372+
IMAGE_TLV_ANY,
373+
};
374+
#endif
375+
352376
/*
353377
* Verify the integrity of the image.
354378
* Return non-zero if image could not be validated/does not validate.
@@ -420,6 +444,27 @@ bootutil_img_validate(struct enc_key_data *enc_state, int image_index,
420444
break;
421445
}
422446

447+
#ifndef ALLOW_ROGUE_TLVS
448+
/*
449+
* Ensure that the non-protected TLV only has entries necessary to hold
450+
* the signature. We also allow encryption related keys to be in the
451+
* unprotected area.
452+
*/
453+
if (!bootutil_tlv_iter_is_prot(&it, off)) {
454+
bool found = false;
455+
for (const uint16_t *p = allowed_unprot_tlvs; *p != IMAGE_TLV_ANY; p++) {
456+
if (type == *p) {
457+
found = true;
458+
break;
459+
}
460+
}
461+
if (!found) {
462+
FIH_SET(fih_rc, FIH_FAILURE);
463+
goto out;
464+
}
465+
}
466+
#endif
467+
423468
if (type == EXPECTED_HASH_TLV) {
424469
/* Verify the image hash. This must always be present. */
425470
if (len != sizeof(hash)) {

0 commit comments

Comments
 (0)