Skip to content

Commit c8faabf

Browse files
robertosassuJarkko Sakkinen
authored andcommitted
tpm: add _head suffix to tcg_efi_specid_event and tcg_pcr_event2
TCG defines two structures, TCG_EfiSpecIDEventStruct and TCG_PCR_EVENT2, which contain variable-sized arrays in the middle of the definition. Since these structures are not suitable for type casting, this patch removes structure members after the variable-sized arrays and adds the _head suffix to the structure name, to indicate that the renamed structures do not contain all fields defined by TCG. Lastly, given that variable-sized arrays are now in the last position, and given that the size of the arrays cannot be determined in advance, this patch also sets the size of those arrays to zero and removes the definition of TPM2_ACTIVE_PCR_BANKS. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Tested-by: Nayna Jain <nayna@linux.ibm.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
1 parent 64494d3 commit c8faabf

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

‎drivers/char/tpm/eventlog/tpm2.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
*
3838
* Returns size of the event. If it is an invalid event, returns 0.
3939
*/
40-
static int calc_tpm2_event_size(struct tcg_pcr_event2 *event,
40+
static int calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
4141
struct tcg_pcr_event *event_header)
4242
{
43-
struct tcg_efi_specid_event *efispecid;
43+
struct tcg_efi_specid_event_head *efispecid;
4444
struct tcg_event_field *event_field;
4545
void *marker;
4646
void *marker_start;
@@ -55,7 +55,7 @@ static int calc_tpm2_event_size(struct tcg_pcr_event2 *event,
5555
marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type)
5656
+ sizeof(event->count);
5757

58-
efispecid = (struct tcg_efi_specid_event *)event_header->event;
58+
efispecid = (struct tcg_efi_specid_event_head *)event_header->event;
5959

6060
/* Check if event is malformed. */
6161
if (event->count > efispecid->num_algs)
@@ -95,7 +95,7 @@ static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos)
9595
void *addr = log->bios_event_log;
9696
void *limit = log->bios_event_log_end;
9797
struct tcg_pcr_event *event_header;
98-
struct tcg_pcr_event2 *event;
98+
struct tcg_pcr_event2_head *event;
9999
size_t size;
100100
int i;
101101

@@ -136,7 +136,7 @@ static void *tpm2_bios_measurements_next(struct seq_file *m, void *v,
136136
loff_t *pos)
137137
{
138138
struct tcg_pcr_event *event_header;
139-
struct tcg_pcr_event2 *event;
139+
struct tcg_pcr_event2_head *event;
140140
struct tpm_chip *chip = m->private;
141141
struct tpm_bios_log *log = &chip->log;
142142
void *limit = log->bios_event_log_end;
@@ -180,7 +180,7 @@ static int tpm2_binary_bios_measurements_show(struct seq_file *m, void *v)
180180
struct tpm_chip *chip = m->private;
181181
struct tpm_bios_log *log = &chip->log;
182182
struct tcg_pcr_event *event_header = log->bios_event_log;
183-
struct tcg_pcr_event2 *event = v;
183+
struct tcg_pcr_event2_head *event = v;
184184
void *temp_ptr;
185185
size_t size;
186186

‎include/linux/tpm_eventlog.h‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#define TCG_EVENT_NAME_LEN_MAX 255
99
#define MAX_TEXT_EVENT 1000 /* Max event string length */
1010
#define ACPI_TCPA_SIG "TCPA" /* 0x41504354 /'TCPA' */
11-
#define TPM2_ACTIVE_PCR_BANKS 3
1211

1312
#define EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 0x1
1413
#define EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 0x2
@@ -82,17 +81,15 @@ struct tcg_efi_specid_event_algs {
8281
u16 digest_size;
8382
} __packed;
8483

85-
struct tcg_efi_specid_event {
84+
struct tcg_efi_specid_event_head {
8685
u8 signature[16];
8786
u32 platform_class;
8887
u8 spec_version_minor;
8988
u8 spec_version_major;
9089
u8 spec_errata;
9190
u8 uintnsize;
9291
u32 num_algs;
93-
struct tcg_efi_specid_event_algs digest_sizes[TPM2_ACTIVE_PCR_BANKS];
94-
u8 vendor_info_size;
95-
u8 vendor_info[0];
92+
struct tcg_efi_specid_event_algs digest_sizes[];
9693
} __packed;
9794

9895
struct tcg_pcr_event {
@@ -113,12 +110,11 @@ struct tpm2_digest {
113110
u8 digest[SHA512_DIGEST_SIZE];
114111
} __packed;
115112

116-
struct tcg_pcr_event2 {
113+
struct tcg_pcr_event2_head {
117114
u32 pcr_idx;
118115
u32 event_type;
119116
u32 count;
120-
struct tpm2_digest digests[TPM2_ACTIVE_PCR_BANKS];
121-
struct tcg_event_field event;
117+
struct tpm2_digest digests[];
122118
} __packed;
123119

124120
#endif

0 commit comments

Comments
 (0)