Skip to content

Commit b250d78

Browse files
committed
fix tpm unseal auth size validation
F/729
1 parent 7631649 commit b250d78

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/tpm.c

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

10891089
/* if using password auth, set it otherwise use policy auth */
10901090
if (auth != NULL && authSz > 0) {
1091+
if (authSz > (int)sizeof(seal_blob->handle.auth.buffer))
1092+
return BAD_FUNC_ARG;
10911093
seal_blob->handle.auth.size = authSz;
10921094
memcpy(seal_blob->handle.auth.buffer, auth, authSz);
10931095
wolfTPM2_SetAuthHandle(&wolftpm_dev, 0, &seal_blob->handle);

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,29 @@ START_TEST(test_wolfBoot_unseal_blob_zeroes_unseal_output)
592592
}
593593
END_TEST
594594

595+
START_TEST(test_wolfBoot_unseal_blob_rejects_oversized_auth)
596+
{
597+
WOLFTPM2_KEYBLOB blob;
598+
uint8_t auth[sizeof(((WOLFTPM2_KEYBLOB*)0)->handle.auth.buffer) + 1];
599+
uint8_t secret[WOLFBOOT_MAX_SEAL_SZ];
600+
uint8_t pubkey_hint[WOLFBOOT_SHA_DIGEST_SIZE] = {0};
601+
uint8_t policy[sizeof(uint32_t) + 4] = {0};
602+
int secret_sz;
603+
int rc;
604+
605+
memset(&blob, 0, sizeof(blob));
606+
memset(auth, 0x88, sizeof(auth));
607+
memset(secret, 0, sizeof(secret));
608+
secret_sz = (int)sizeof(secret);
609+
current_mode = MOCK_OVERSIZE_PUB;
610+
611+
rc = wolfBoot_unseal_blob(pubkey_hint, policy, sizeof(policy), &blob,
612+
secret, &secret_sz, auth, (int)sizeof(auth));
613+
614+
ck_assert_int_eq(rc, BAD_FUNC_ARG);
615+
}
616+
END_TEST
617+
595618
START_TEST(test_wolfBoot_unseal_blob_rejects_output_larger_than_capacity)
596619
{
597620
struct {
@@ -655,6 +678,7 @@ static Suite *tpm_blob_suite(void)
655678
tcase_add_test(tc, test_wolfBoot_read_blob_rejects_oversized_public_area);
656679
tcase_add_test(tc, test_wolfBoot_read_blob_rejects_oversized_private_area);
657680
tcase_add_test(tc, test_wolfBoot_unseal_blob_zeroes_unseal_output);
681+
tcase_add_test(tc, test_wolfBoot_unseal_blob_rejects_oversized_auth);
658682
tcase_add_test(tc, test_wolfBoot_unseal_blob_rejects_output_larger_than_capacity);
659683
suite_add_tcase(s, tc);
660684
return s;

0 commit comments

Comments
 (0)