Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
e5dcd87f | 2 | |
fd3ec366 TW |
3 | #ifndef __LINUX_TPM_EVENTLOG_H__ |
4 | #define __LINUX_TPM_EVENTLOG_H__ | |
e5dcd87f | 5 | |
aa042475 | 6 | #include <linux/tpm.h> |
4d23cc32 | 7 | |
e5dcd87f KY |
8 | #define TCG_EVENT_NAME_LEN_MAX 255 |
9 | #define MAX_TEXT_EVENT 1000 /* Max event string length */ | |
10 | #define ACPI_TCPA_SIG "TCPA" /* 0x41504354 /'TCPA' */ | |
11 | ||
4d01d29d TW |
12 | #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 0x1 |
13 | #define EFI_TCG2_EVENT_LOG_FORMAT_TCG_2 0x2 | |
14 | ||
0cc698af HCVL |
15 | #ifdef CONFIG_PPC64 |
16 | #define do_endian_conversion(x) be32_to_cpu(x) | |
17 | #else | |
18 | #define do_endian_conversion(x) x | |
19 | #endif | |
20 | ||
e5dcd87f KY |
21 | enum bios_platform_class { |
22 | BIOS_CLIENT = 0x00, | |
23 | BIOS_SERVER = 0x01, | |
24 | }; | |
25 | ||
e5dcd87f KY |
26 | struct tcpa_event { |
27 | u32 pcr_index; | |
28 | u32 event_type; | |
29 | u8 pcr_value[20]; /* SHA1 */ | |
30 | u32 event_size; | |
31 | u8 event_data[0]; | |
32 | }; | |
33 | ||
34 | enum tcpa_event_types { | |
35 | PREBOOT = 0, | |
36 | POST_CODE, | |
37 | UNUSED, | |
38 | NO_ACTION, | |
39 | SEPARATOR, | |
40 | ACTION, | |
41 | EVENT_TAG, | |
42 | SCRTM_CONTENTS, | |
43 | SCRTM_VERSION, | |
44 | CPU_MICROCODE, | |
45 | PLATFORM_CONFIG_FLAGS, | |
46 | TABLE_OF_DEVICES, | |
47 | COMPACT_HASH, | |
48 | IPL, | |
49 | IPL_PARTITION_DATA, | |
50 | NONHOST_CODE, | |
51 | NONHOST_CONFIG, | |
52 | NONHOST_INFO, | |
53 | }; | |
54 | ||
55 | struct tcpa_pc_event { | |
56 | u32 event_id; | |
57 | u32 event_size; | |
58 | u8 event_data[0]; | |
59 | }; | |
60 | ||
61 | enum tcpa_pc_event_ids { | |
62 | SMBIOS = 1, | |
63 | BIS_CERT, | |
64 | POST_BIOS_ROM, | |
65 | ESCD, | |
66 | CMOS, | |
67 | NVRAM, | |
68 | OPTION_ROM_EXEC, | |
69 | OPTION_ROM_CONFIG, | |
70 | OPTION_ROM_MICROCODE = 10, | |
71 | S_CRTM_VERSION, | |
72 | S_CRTM_CONTENTS, | |
73 | POST_CONTENTS, | |
74 | HOST_TABLE_OF_DEVICES, | |
75 | }; | |
76 | ||
4d23cc32 NJ |
77 | /* http://www.trustedcomputinggroup.org/tcg-efi-protocol-specification/ */ |
78 | ||
79 | struct tcg_efi_specid_event_algs { | |
80 | u16 alg_id; | |
81 | u16 digest_size; | |
82 | } __packed; | |
83 | ||
c8faabfc | 84 | struct tcg_efi_specid_event_head { |
4d23cc32 NJ |
85 | u8 signature[16]; |
86 | u32 platform_class; | |
87 | u8 spec_version_minor; | |
88 | u8 spec_version_major; | |
89 | u8 spec_errata; | |
90 | u8 uintnsize; | |
91 | u32 num_algs; | |
c8faabfc | 92 | struct tcg_efi_specid_event_algs digest_sizes[]; |
4d23cc32 NJ |
93 | } __packed; |
94 | ||
95 | struct tcg_pcr_event { | |
96 | u32 pcr_idx; | |
97 | u32 event_type; | |
98 | u8 digest[20]; | |
99 | u32 event_size; | |
100 | u8 event[0]; | |
101 | } __packed; | |
102 | ||
103 | struct tcg_event_field { | |
104 | u32 event_size; | |
105 | u8 event[0]; | |
106 | } __packed; | |
107 | ||
c8faabfc | 108 | struct tcg_pcr_event2_head { |
4d23cc32 NJ |
109 | u32 pcr_idx; |
110 | u32 event_type; | |
111 | u32 count; | |
aa042475 | 112 | struct tpm_digest digests[]; |
4d23cc32 NJ |
113 | } __packed; |
114 | ||
44038bc5 MG |
115 | /** |
116 | * __calc_tpm2_event_size - calculate the size of a TPM2 event log entry | |
117 | * @event: Pointer to the event whose size should be calculated | |
118 | * @event_header: Pointer to the initial event containing the digest lengths | |
119 | * | |
120 | * The TPM2 event log format can contain multiple digests corresponding to | |
121 | * separate PCR banks, and also contains a variable length of the data that | |
122 | * was measured. This requires knowledge of how long each digest type is, | |
123 | * and this information is contained within the first event in the log. | |
124 | * | |
125 | * We calculate the length by examining the number of events, and then looking | |
126 | * at each event in turn to determine how much space is used for events in | |
127 | * total. Once we've done this we know the offset of the data length field, | |
128 | * and can calculate the total size of the event. | |
129 | * | |
130 | * Return: size of the event on success, <0 on failure | |
131 | */ | |
132 | ||
133 | static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event, | |
134 | struct tcg_pcr_event *event_header) | |
135 | { | |
136 | struct tcg_efi_specid_event_head *efispecid; | |
137 | struct tcg_event_field *event_field; | |
138 | void *marker; | |
139 | void *marker_start; | |
140 | u32 halg_size; | |
141 | size_t size; | |
142 | u16 halg; | |
143 | int i; | |
144 | int j; | |
145 | ||
146 | marker = event; | |
147 | marker_start = marker; | |
148 | marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type) | |
149 | + sizeof(event->count); | |
150 | ||
151 | efispecid = (struct tcg_efi_specid_event_head *)event_header->event; | |
152 | ||
153 | /* Check if event is malformed. */ | |
154 | if (event->count > efispecid->num_algs) | |
155 | return 0; | |
156 | ||
157 | for (i = 0; i < event->count; i++) { | |
158 | halg_size = sizeof(event->digests[i].alg_id); | |
159 | memcpy(&halg, marker, halg_size); | |
160 | marker = marker + halg_size; | |
161 | for (j = 0; j < efispecid->num_algs; j++) { | |
162 | if (halg == efispecid->digest_sizes[j].alg_id) { | |
163 | marker += | |
164 | efispecid->digest_sizes[j].digest_size; | |
165 | break; | |
166 | } | |
167 | } | |
168 | /* Algorithm without known length. Such event is unparseable. */ | |
169 | if (j == efispecid->num_algs) | |
170 | return 0; | |
171 | } | |
172 | ||
173 | event_field = (struct tcg_event_field *)marker; | |
174 | marker = marker + sizeof(event_field->event_size) | |
175 | + event_field->event_size; | |
176 | size = marker - marker_start; | |
177 | ||
178 | if ((event->event_type == 0) && (event_field->event_size == 0)) | |
179 | return 0; | |
180 | ||
181 | return size; | |
182 | } | |
e5dcd87f | 183 | #endif |