Skip to content

Commit 63940fb

Browse files
JuergenReppSITAndreasFuchsTPM
authored andcommitted
FAPI: Fix check of magic number in verify quote.
After deserializing the quote info it was not checked whether the magic number in the attest is equal TPM2_GENERATED_VALUE. So an malicious attacker could generate arbitrary quote data which was not detected by Fapi_VerifyQuote. Now the number magic number is checket in verify quote and also in the deserialization of TPM2_GENERATED. The check is also added to the Unmarshal function for TPMS_ATTEST. Fixes: CVE-2024-29040 Signed-off-by: Juergen Repp <[email protected]> Signed-off-by: Andreas Fuchs <[email protected]>
1 parent ca6e638 commit 63940fb

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/tss2-fapi/api/Fapi_VerifyQuote.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ Fapi_VerifyQuote_Finish(
287287
&command->fapi_quote_info);
288288
goto_if_error(r, "Get quote info.", error_cleanup);
289289

290+
if (command->fapi_quote_info.attest.magic != TPM2_GENERATED_VALUE) {
291+
goto_error(r, TSS2_FAPI_RC_SIGNATURE_VERIFICATION_FAILED,
292+
"Attest without TPM2 generated value", error_cleanup);
293+
}
294+
290295
/* Verify the signature over the attest2b structure. */
291296
r = ifapi_verify_signature_quote(&key_object,
292297
command->signature,

src/tss2-fapi/tpm_json_deserialize.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ ifapi_json_TPM2_GENERATED_deserialize(json_object *jso, TPM2_GENERATED *out)
715715
const char *s = json_object_get_string(jso);
716716
const char *str = strip_prefix(s, "TPM_", "TPM2_", "GENERATED_", NULL);
717717
LOG_TRACE("called for %s parsing %s", s, str);
718+
TSS2_RC r;
718719

719720
if (str) {
720721
for (size_t i = 0; i < sizeof(tab) / sizeof(tab[0]); i++) {
@@ -724,8 +725,14 @@ ifapi_json_TPM2_GENERATED_deserialize(json_object *jso, TPM2_GENERATED *out)
724725
}
725726
}
726727
}
727-
728-
return ifapi_json_UINT32_deserialize(jso, out);
728+
r = ifapi_json_UINT32_deserialize(jso, out);
729+
return_if_error(r, "Could not deserialize UINT32");
730+
if (*out != TPM2_GENERATED_VALUE) {
731+
return_error2(TSS2_FAPI_RC_BAD_VALUE,
732+
"Value %x not equal TPM self generated value %x",
733+
*out, TPM2_GENERATED_VALUE);
734+
}
735+
return TSS2_RC_SUCCESS;
729736
}
730737

731738
/** Deserialize a TPM2_ALG_ID json object.

src/tss2-mu/tpms-types.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@
2222
#define VAL
2323
#define TAB_SIZE(tab) (sizeof(tab) / sizeof(tab[0]))
2424

25+
static TSS2_RC
26+
TPM2_GENERATED_Unmarshal(
27+
uint8_t const buffer[],
28+
size_t buffer_size,
29+
size_t *offset,
30+
TPM2_GENERATED *magic)
31+
{
32+
TPM2_GENERATED mymagic = 0;
33+
TSS2_RC rc = Tss2_MU_UINT32_Unmarshal(buffer, buffer_size, offset, &mymagic);
34+
if (rc != TSS2_RC_SUCCESS) {
35+
return rc;
36+
}
37+
if (mymagic != TPM2_GENERATED_VALUE) {
38+
LOG_ERROR("Bad magic in tpms_attest");
39+
return TSS2_SYS_RC_BAD_VALUE;
40+
}
41+
if (magic != NULL)
42+
*magic = mymagic;
43+
return TSS2_RC_SUCCESS;
44+
}
45+
2546
#define TPMS_PCR_MARSHAL(type, firstFieldMarshal) \
2647
TSS2_RC \
2748
Tss2_MU_##type##_Marshal(const type *src, uint8_t buffer[], \
@@ -1227,7 +1248,7 @@ TPMS_MARSHAL_7_U(TPMS_ATTEST,
12271248
attested, ADDR, Tss2_MU_TPMU_ATTEST_Marshal)
12281249

12291250
TPMS_UNMARSHAL_7_U(TPMS_ATTEST,
1230-
magic, Tss2_MU_UINT32_Unmarshal,
1251+
magic, TPM2_GENERATED_Unmarshal,
12311252
type, Tss2_MU_TPM2_ST_Unmarshal,
12321253
qualifiedSigner, Tss2_MU_TPM2B_NAME_Unmarshal,
12331254
extraData, Tss2_MU_TPM2B_DATA_Unmarshal,

0 commit comments

Comments
 (0)