Skip to content

Commit a5139b1

Browse files
poetteringbluca
authored andcommitted
tpm2-util: tighten rules on the nvindex handle range we allocate from
Let's follow the conventions set by "Registry of Reserved TPM 2.0 Handles and Localities" and only allocate nvindex currently not assigned to any vendor. For details see: https://trustedcomputinggroup.org/resource/registry/ Section 2.2
1 parent 9afc6ac commit a5139b1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/shared/tpm2-util.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5800,7 +5800,8 @@ int tpm2_unseal(Tpm2Context *c,
58005800
}
58015801

58025802
static TPM2_HANDLE generate_random_nv_index(void) {
5803-
return TPM2_NV_INDEX_FIRST + (TPM2_HANDLE) random_u64_range(TPM2_NV_INDEX_LAST - TPM2_NV_INDEX_FIRST + 1);
5803+
return TPM2_NV_INDEX_UNASSIGNED_FIRST +
5804+
(TPM2_HANDLE) random_u64_range(TPM2_NV_INDEX_UNASSIGNED_LAST - TPM2_NV_INDEX_UNASSIGNED_FIRST + 1);
58045805
}
58055806

58065807
int tpm2_define_policy_nv_index(

src/shared/tpm2-util.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,14 @@ enum {
484484

485485
int tpm2_pcr_index_from_string(const char *s) _pure_;
486486
const char *tpm2_pcr_index_to_string(int pcr) _const_;
487+
488+
/* The first and last NV index handle that is not registered to any company, as per TCG's "Registry of
489+
* Reserved TPM 2.0 Handles and Localities", section 2.2.2. */
490+
#define TPM2_NV_INDEX_UNASSIGNED_FIRST UINT32_C(0x01800000)
491+
#define TPM2_NV_INDEX_UNASSIGNED_LAST UINT32_C(0x01BFFFFF)
492+
493+
#if HAVE_TPM2
494+
/* Verify that the above is indeed a subset of the general NV Index range */
495+
assert_cc(TPM2_NV_INDEX_UNASSIGNED_FIRST >= TPM2_NV_INDEX_FIRST);
496+
assert_cc(TPM2_NV_INDEX_UNASSIGNED_LAST <= TPM2_NV_INDEX_LAST);
497+
#endif

0 commit comments

Comments
 (0)