Skip to content

Commit 7631649

Browse files
committed
fix tpm seal auth size validation
F/728
1 parent 73b5ad4 commit 7631649

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

src/tpm.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ int wolfBoot_seal_auth(const uint8_t* pubkey_hint,
893893

894894
if (auth == NULL && authSz > 0)
895895
return BAD_FUNC_ARG;
896+
if (authSz > (int)sizeof(seal_blob.handle.auth.buffer))
897+
return BAD_FUNC_ARG;
896898

897899
memset(&seal_blob, 0, sizeof(seal_blob));
898900

tools/unit-tests/unit-tpm-blob.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,61 @@ int wolfTPM2_PolicyRefMake(TPM_ALG_ID pcrAlg, byte* digest, word32* digestSz,
228228
return 0;
229229
}
230230

231+
int TPM2_GetHashDigestSize(TPMI_ALG_HASH hashAlg)
232+
{
233+
(void)hashAlg;
234+
return 32;
235+
}
236+
237+
int wolfTPM2_GetKeyTemplate_KeySeal(TPMT_PUBLIC* publicTemplate,
238+
TPM_ALG_ID nameAlg)
239+
{
240+
memset(publicTemplate, 0, sizeof(*publicTemplate));
241+
publicTemplate->nameAlg = nameAlg;
242+
return 0;
243+
}
244+
245+
int wolfTPM2_PolicyAuthorizeMake(TPM_ALG_ID hashAlg, const TPM2B_PUBLIC* pub,
246+
byte* digest, word32* digestSz, const byte* policyRef,
247+
word32 policyRefSz)
248+
{
249+
(void)hashAlg;
250+
(void)pub;
251+
(void)policyRef;
252+
(void)policyRefSz;
253+
memset(digest, 0x11, *digestSz);
254+
return 0;
255+
}
256+
257+
int wolfTPM2_CreateKeySeal_ex(WOLFTPM2_DEV* dev, WOLFTPM2_KEYBLOB* keyBlob,
258+
WOLFTPM2_HANDLE* parent, TPMT_PUBLIC* publicTemplate, const byte* auth,
259+
int authSz, TPM_ALG_ID alg, byte* pcrSel,
260+
word32 pcrSelSz, const byte* sealData, int sealSize)
261+
{
262+
(void)dev;
263+
(void)keyBlob;
264+
(void)parent;
265+
(void)publicTemplate;
266+
(void)auth;
267+
(void)authSz;
268+
(void)alg;
269+
(void)pcrSel;
270+
(void)pcrSelSz;
271+
(void)sealData;
272+
(void)sealSize;
273+
unexpected_nvcreate_calls++;
274+
ck_abort_msg("Unexpected wolfTPM2_CreateKeySeal_ex call");
275+
return -1;
276+
}
277+
278+
int wolfTPM2_GetNvAttributesTemplate(TPM_HANDLE authHandle,
279+
word32* attr)
280+
{
281+
(void)authHandle;
282+
*attr = 0;
283+
return 0;
284+
}
285+
231286
TPM_RC TPM2_Unseal(Unseal_In* in, Unseal_Out* out)
232287
{
233288
(void)in;
@@ -492,6 +547,27 @@ START_TEST(test_wolfBoot_delete_blob_rejects_oversized_auth)
492547
}
493548
END_TEST
494549

550+
START_TEST(test_wolfBoot_seal_auth_rejects_oversized_auth)
551+
{
552+
uint8_t auth[sizeof(((WOLFTPM2_KEYBLOB*)0)->handle.auth.buffer) + 1];
553+
uint8_t pubkey_hint[WOLFBOOT_SHA_DIGEST_SIZE] = {0};
554+
uint8_t policy[sizeof(uint32_t) + 4] = {0};
555+
uint8_t secret[8] = {0};
556+
int rc;
557+
558+
memset(auth, 0x77, sizeof(auth));
559+
560+
rc = wolfBoot_seal_auth(pubkey_hint, policy, sizeof(policy), 0,
561+
secret, sizeof(secret), auth, (int)sizeof(auth));
562+
563+
ck_assert_int_eq(rc, BAD_FUNC_ARG);
564+
ck_assert_int_eq(unexpected_nvcreate_calls, 0);
565+
ck_assert_int_eq(unexpected_nvwrite_calls, 0);
566+
ck_assert_int_eq(unexpected_nvopen_calls, 0);
567+
ck_assert_int_eq(unexpected_nvdelete_calls, 0);
568+
}
569+
END_TEST
570+
495571
START_TEST(test_wolfBoot_unseal_blob_zeroes_unseal_output)
496572
{
497573
uint8_t secret[WOLFBOOT_MAX_SEAL_SZ];
@@ -575,6 +651,7 @@ static Suite *tpm_blob_suite(void)
575651
tcase_add_test(tc, test_wolfBoot_store_blob_rejects_oversized_auth);
576652
tcase_add_test(tc, test_wolfBoot_read_blob_rejects_oversized_auth);
577653
tcase_add_test(tc, test_wolfBoot_delete_blob_rejects_oversized_auth);
654+
tcase_add_test(tc, test_wolfBoot_seal_auth_rejects_oversized_auth);
578655
tcase_add_test(tc, test_wolfBoot_read_blob_rejects_oversized_public_area);
579656
tcase_add_test(tc, test_wolfBoot_read_blob_rejects_oversized_private_area);
580657
tcase_add_test(tc, test_wolfBoot_unseal_blob_zeroes_unseal_output);

0 commit comments

Comments
 (0)