-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslr_table_grub.h
296 lines (255 loc) · 7.05 KB
/
slr_table_grub.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2023 Oracle and/or its affiliates.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*
* Secure Launch Resource Table definitions
*/
#ifndef GRUB_SLR_TABLE_H
#define GRUB_SLR_TABLE_H 1
#define GRUB_UEFI_SLR_TABLE_GUID \
{ 0x877a9b2a, 0x0385, 0x45d1, { 0xa0, 0x34, 0x9d, 0xac, 0x9c, 0x9e, 0x56, 0x5f }}
/* SLR table header values */
#define GRUB_SLR_TABLE_MAGIC 0x4452544d
#define GRUB_SLR_TABLE_REVISION 1
/* Current revisions for the policy and UEFI config */
#define GRUB_SLR_POLICY_REVISION 1
#define GRUB_SLR_UEFI_CONFIG_REVISION 1
/* SLR defined architectures */
#define GRUB_SLR_INTEL_TXT 1
#define GRUB_SLR_AMD_SKINIT 2
/* SLR defined bootloaders */
#define GRUB_SLR_BOOTLOADER_INVALID 0
#define GRUB_SLR_BOOTLOADER_GRUB 1
/* Log formats */
#define GRUB_SLR_DRTM_TPM12_LOG 1
#define GRUB_SLR_DRTM_TPM20_LOG 2
/* DRTM Policy Entry Flags */
#define GRUB_SLR_POLICY_FLAG_MEASURED 0x1
#define GRUB_SLR_POLICY_IMPLICIT_SIZE 0x2
/* Array Lengths */
#define GRUB_TPM_EVENT_INFO_LENGTH 32
#define GRUB_TXT_VARIABLE_MTRRS_LENGTH 32
/* Tags */
#define GRUB_SLR_ENTRY_INVALID 0x0000
#define GRUB_SLR_ENTRY_DL_INFO 0x0001
#define GRUB_SLR_ENTRY_LOG_INFO 0x0002
#define GRUB_SLR_ENTRY_ENTRY_POLICY 0x0003
#define GRUB_SLR_ENTRY_INTEL_INFO 0x0004
#define GRUB_SLR_ENTRY_AMD_INFO 0x0005
#define GRUB_SLR_ENTRY_ARM_INFO 0x0006
#define GRUB_SLR_ENTRY_UEFI_INFO 0x0007
#define GRUB_SLR_ENTRY_UEFI_CONFIG 0x0008
#define GRUB_SLR_ENTRY_END 0xffff
/* Entity Types */
#define GRUB_SLR_ET_UNSPECIFIED 0x0000
#define GRUB_SLR_ET_SLRT 0x0001
#define GRUB_SLR_ET_BOOT_PARAMS 0x0002
#define GRUB_SLR_ET_SETUP_DATA 0x0003
#define GRUB_SLR_ET_CMDLINE 0x0004
#define GRUB_SLR_ET_UEFI_MEMMAP 0x0005
#define GRUB_SLR_ET_RAMDISK 0x0006
#define GRUB_SLR_ET_TXT_OS2MLE 0x0010
#define GRUB_SLR_ET_UNUSED 0xffff
/*
* Primary SLR Table Header
*/
struct grub_slr_table
{
grub_uint32_t magic;
grub_uint16_t revision;
grub_uint16_t architecture;
grub_uint32_t size;
grub_uint32_t max_size;
/* entries[] */
} GRUB_PACKED;
/*
* Common SLRT Table Header
*/
struct grub_slr_entry_hdr
{
grub_uint16_t tag;
grub_uint16_t size;
} GRUB_PACKED;
/*
* Boot loader context
*/
struct grub_slr_bl_context
{
grub_uint16_t bootloader;
grub_uint16_t reserved;
grub_uint64_t context;
} GRUB_PACKED;
/*
* DRTM Dynamic Launch Configuration
*/
struct grub_slr_entry_dl_info
{
struct grub_slr_entry_hdr hdr;
struct grub_slr_bl_context bl_context;
grub_uint64_t dl_handler;
grub_uint64_t dce_base;
grub_uint32_t dce_size;
grub_uint64_t dlme_entry;
} GRUB_PACKED;
/*
* TPM Log Information
*/
struct grub_slr_entry_log_info
{
struct grub_slr_entry_hdr hdr;
grub_uint16_t format;
grub_uint16_t reserved;
grub_uint64_t addr;
grub_uint32_t size;
} GRUB_PACKED;
/*
* DRTM Measurement Policy
*/
struct grub_slr_entry_policy
{
struct grub_slr_entry_hdr hdr;
grub_uint16_t revision;
grub_uint16_t nr_entries;
/* policy_entries[] */
} GRUB_PACKED;
/*
* DRTM Measurement Entry
*/
struct grub_slr_policy_entry
{
grub_uint16_t pcr;
grub_uint16_t entity_type;
grub_uint16_t flags;
grub_uint16_t reserved;
grub_uint64_t entity;
grub_uint64_t size;
char evt_info[GRUB_TPM_EVENT_INFO_LENGTH];
} GRUB_PACKED;
/*
* Secure Launch defined MTRR saving structures
*/
struct grub_slr_txt_mtrr_pair
{
grub_uint64_t mtrr_physbase;
grub_uint64_t mtrr_physmask;
} GRUB_PACKED;
struct grub_slr_txt_mtrr_state
{
grub_uint64_t default_mem_type;
grub_uint64_t mtrr_vcnt;
struct grub_slr_txt_mtrr_pair mtrr_pair[GRUB_TXT_VARIABLE_MTRRS_LENGTH];
} GRUB_PACKED;
/*
* Intel TXT Info table
*/
struct grub_slr_entry_intel_info
{
struct grub_slr_entry_hdr hdr;
grub_uint64_t saved_misc_enable_msr;
struct grub_slr_txt_mtrr_state saved_bsp_mtrrs;
} GRUB_PACKED;
/*
* AMD SKINIT Info table
*/
struct grub_slr_entry_amd_info
{
struct grub_slr_entry_hdr hdr;
} GRUB_PACKED;
/*
* ARM DRTM Info table
*/
struct grub_slr_entry_arm_info
{
struct grub_slr_entry_hdr hdr;
} GRUB_PACKED;
struct grub_slr_entry_uefi_config
{
struct grub_slr_entry_hdr hdr;
grub_uint16_t revision;
grub_uint16_t nr_entries;
/* uefi_cfg_entries[] */
} GRUB_PACKED;
struct grub_slr_uefi_cfg_entry
{
grub_uint16_t pcr;
grub_uint16_t reserved;
grub_uint64_t cfg; /* address or value */
grub_uint32_t size;
char evt_info[GRUB_TPM_EVENT_INFO_LENGTH];
} GRUB_PACKED;
static inline void *
grub_slr_end_of_entrys (struct grub_slr_table *table)
{
return (void *)(((grub_uint8_t *)table) + table->size);
}
static inline struct grub_slr_entry_hdr *
grub_slr_next_entry (struct grub_slr_table *table,
struct grub_slr_entry_hdr *curr)
{
struct grub_slr_entry_hdr *next = (struct grub_slr_entry_hdr *)
((grub_uint8_t *)curr + curr->size);
if ((void *)next >= grub_slr_end_of_entrys(table))
return NULL;
if (next->tag == GRUB_SLR_ENTRY_END)
return NULL;
return next;
}
static inline struct grub_slr_entry_hdr *
grub_slr_next_entry_by_tag (struct grub_slr_table *table,
struct grub_slr_entry_hdr *entry,
grub_uint16_t tag)
{
if (!entry) /* Start from the beginning */
entry = (struct grub_slr_entry_hdr *)(((grub_uint8_t *)table) + sizeof(*table));
for ( ; ; )
{
if (entry->tag == tag)
return entry;
entry = grub_slr_next_entry (table, entry);
if (!entry)
return NULL;
}
return NULL;
}
static inline int
grub_slr_add_entry (struct grub_slr_table *table,
struct grub_slr_entry_hdr *entry)
{
struct grub_slr_entry_hdr *end;
if ((table->size + entry->size) > table->max_size)
return -1;
grub_memcpy((grub_uint8_t *)table + table->size - sizeof(*end), entry, entry->size);
table->size += entry->size;
end = (struct grub_slr_entry_hdr *)((grub_uint8_t *)table + table->size - sizeof(*end));
end->tag = GRUB_SLR_ENTRY_END;
end->size = sizeof(*end);
return 0;
}
static inline void
grub_slr_init_table(struct grub_slr_table *slrt, grub_uint16_t architecture,
grub_uint32_t max_size)
{
struct grub_slr_entry_hdr *end;
slrt->magic = GRUB_SLR_TABLE_MAGIC;
slrt->revision = GRUB_SLR_TABLE_REVISION;
slrt->architecture = architecture;
slrt->size = sizeof(*slrt) + sizeof(*end);
slrt->max_size = max_size;
end = (struct grub_slr_entry_hdr *)((grub_uint8_t *)slrt + sizeof(*slrt));
end->tag = GRUB_SLR_ENTRY_END;
end->size = sizeof(*end);
}
#endif /* GRUB_SLR_TABLE_H */