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.
Unified · Split
| @@ -37,10 +37,10 @@ · 36 unmodified lines | |||
| 37 | * | 37 | * |
| 38 | * Returns size of the event. If it is an invalid event, returns 0. | 38 | * Returns size of the event. If it is an invalid event, returns 0. |
| 39 | */ | 39 | */ |
| 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, |
| 41 | struct tcg_pcr_event *event_header) | 41 | struct tcg_pcr_event *event_header) |
| 42 | { | 42 | { |
| 43 | struct tcg_efi_specid_event *efispecid; | 43 | struct tcg_efi_specid_event_head *efispecid; |
| 44 | struct tcg_event_field *event_field; | 44 | struct tcg_event_field *event_field; |
| 45 | void *marker; | 45 | void *marker; |
| 46 | void *marker_start; | 46 | void *marker_start; |
| @@ -55,7 +55,7 @@ static int calc_tpm2_event_size(struct tcg_pcr_event2 *event, · 8 unmodified lines | |||
| 55 | marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type) | 55 | marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type) |
| 56 | + sizeof(event->count); | 56 | + sizeof(event->count); |
| 57 | 57 | ||
| 58 | efispecid = (struct tcg_efi_specid_event *)event_header->event; | 58 | efispecid = (struct tcg_efi_specid_event_head *)event_header->event; |
| 59 | 59 | ||
| 60 | /* Check if event is malformed. */ | 60 | /* Check if event is malformed. */ |
| 61 | if (event->count > efispecid->num_algs) | 61 | if (event->count > efispecid->num_algs) |
| @@ -95,7 +95,7 @@ static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos) · 33 unmodified lines | |||
| 95 | void *addr = log->bios_event_log; | 95 | void *addr = log->bios_event_log; |
| 96 | void *limit = log->bios_event_log_end; | 96 | void *limit = log->bios_event_log_end; |
| 97 | struct tcg_pcr_event *event_header; | 97 | struct tcg_pcr_event *event_header; |
| 98 | struct tcg_pcr_event2 *event; | 98 | struct tcg_pcr_event2_head *event; |
| 99 | size_t size; | 99 | size_t size; |
| 100 | int i; | 100 | int i; |
| 101 | 101 | ||
| @@ -136,7 +136,7 @@ static void *tpm2_bios_measurements_next(struct seq_file *m, void *v, · 34 unmodified lines | |||
| 136 | loff_t *pos) | 136 | loff_t *pos) |
| 137 | { | 137 | { |
| 138 | struct tcg_pcr_event *event_header; | 138 | struct tcg_pcr_event *event_header; |
| 139 | struct tcg_pcr_event2 *event; | 139 | struct tcg_pcr_event2_head *event; |
| 140 | struct tpm_chip *chip = m->private; | 140 | struct tpm_chip *chip = m->private; |
| 141 | struct tpm_bios_log *log = &chip->log; | 141 | struct tpm_bios_log *log = &chip->log; |
| 142 | void *limit = log->bios_event_log_end; | 142 | void *limit = log->bios_event_log_end; |
| @@ -180,7 +180,7 @@ static int tpm2_binary_bios_measurements_show(struct seq_file *m, void *v) · 37 unmodified lines | |||
| 180 | struct tpm_chip *chip = m->private; | 180 | struct tpm_chip *chip = m->private; |
| 181 | struct tpm_bios_log *log = &chip->log; | 181 | struct tpm_bios_log *log = &chip->log; |
| 182 | struct tcg_pcr_event *event_header = log->bios_event_log; | 182 | 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; |
| 184 | void *temp_ptr; | 184 | void *temp_ptr; |
| 185 | size_t size; | 185 | size_t size; |
| 186 | 186 | ||
| @@ -8,7 +8,6 @@ · 7 unmodified lines | |||
| 8 | #define TCG_EVENT_NAME_LEN_MAX 255 | 8 | #define TCG_EVENT_NAME_LEN_MAX 255 |
| 9 | #define MAX_TEXT_EVENT 1000 /* Max event string length */ | 9 | #define MAX_TEXT_EVENT 1000 /* Max event string length */ |
| 10 | #define ACPI_TCPA_SIG "TCPA" /* 0x41504354 /'TCPA' */ | 10 | #define ACPI_TCPA_SIG "TCPA" /* 0x41504354 /'TCPA' */ |
| 11 | #define TPM2_ACTIVE_PCR_BANKS 3 | ||
| 12 | 11 | ||
| 13 | #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 0x1 | 12 | #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 0x1 |
| 14 | #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 0x2 | 13 | #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 0x2 |
| @@ -82,7 +81,7 @@ struct tcg_efi_specid_event_algs { · 67 unmodified lines | |||
| 82 | u16 digest_size; | 81 | u16 digest_size; |
| 83 | } __packed; | 82 | } __packed; |
| 84 | 83 | ||
| 85 | struct tcg_efi_specid_event { | 84 | struct tcg_efi_specid_event_head { |
| 86 | u8 signature[16]; | 85 | u8 signature[16]; |
| 87 | u32 platform_class; | 86 | u32 platform_class; |
| 88 | u8 spec_version_minor; | 87 | u8 spec_version_minor; |
| @@ -90,9 +89,7 @@ struct tcg_efi_specid_event { · 1 unmodified line | |||
| 90 | u8 spec_errata; | 89 | u8 spec_errata; |
| 91 | u8 uintnsize; | 90 | u8 uintnsize; |
| 92 | u32 num_algs; | 91 | u32 num_algs; |
| 93 | struct tcg_efi_specid_event_algs digest_sizes[TPM2_ACTIVE_PCR_BANKS]; | 92 | struct tcg_efi_specid_event_algs digest_sizes[]; |
| 94 | u8 vendor_info_size; | ||
| 95 | u8 vendor_info[0]; | ||
| 96 | } __packed; | 93 | } __packed; |
| 97 | 94 | ||
| 98 | struct tcg_pcr_event { | 95 | struct tcg_pcr_event { |
| @@ -113,12 +110,11 @@ struct tpm2_digest { · 14 unmodified lines | |||
| 113 | u8 digest[SHA512_DIGEST_SIZE]; | 110 | u8 digest[SHA512_DIGEST_SIZE]; |
| 114 | } __packed; | 111 | } __packed; |
| 115 | 112 | ||
| 116 | struct tcg_pcr_event2 { | 113 | struct tcg_pcr_event2_head { |
| 117 | u32 pcr_idx; | 114 | u32 pcr_idx; |
| 118 | u32 event_type; | 115 | u32 event_type; |
| 119 | u32 count; | 116 | u32 count; |
| 120 | struct tpm2_digest digests[TPM2_ACTIVE_PCR_BANKS]; | 117 | struct tpm2_digest digests[]; |
| 121 | struct tcg_event_field event; | ||
| 122 | } __packed; | 118 | } __packed; |
| 123 | 119 | ||
| 124 | #endif | 120 | #endif |