Skip to content

Commit cc77fcf

Browse files
krystian-hebelrossphilipson
authored andcommitted
event_log: obtain event log location from SLRT and log SKL measurements
SKL hashes are no longer passed from the bootloader. Measured code and read-only data are not changed, and all other data is created at runtime so SKL is able to measure itself, which it now does. Those hashes are only used for event log entries, PCR was extended as a result of SKINIT instruction on Dynamic Launch Event. Signed-off-by: Krystian Hebel <[email protected]>
1 parent e36b5ae commit cc77fcf

File tree

2 files changed

+26
-41
lines changed

2 files changed

+26
-41
lines changed

event_log.c

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
*/
1818

1919
#include <boot.h>
20+
#include <sha1sum.h>
21+
#include <sha256.h>
22+
#include <slrt.h>
2023
#include <string.h>
21-
#include <tags.h>
2224
#include "tpmlib/tpm.h"
2325
#include "tpmlib/tpm2_constants.h"
2426

@@ -204,9 +206,12 @@ int log_event_tpm20(u32 pcr, u8 sha1[20], u8 sha256[32], char *event)
204206
int event_log_init(struct tpm *tpm)
205207
{
206208
unsigned int min_size;
207-
struct skl_tag_evtlog *t = next_of_type(&bootloader_data, SKL_TAG_EVENT_LOG);
209+
struct slr_entry_log_info *info;
210+
u8 hash[SHA1_DIGEST_SIZE];
208211

209-
if ( t == NULL || next_of_type(t, SKL_TAG_EVENT_LOG) != NULL )
212+
info = next_entry_with_tag(NULL, SLR_ENTRY_LOG_INFO);
213+
214+
if ( info == NULL || next_entry_with_tag(info, SLR_ENTRY_LOG_INFO) != NULL )
210215
goto err;
211216

212217
min_size = sizeof (tpm12_event_t);
@@ -227,11 +232,11 @@ int event_log_init(struct tpm *tpm)
227232
}
228233

229234
/* Note that min_size does not include tpmXX_event_t.event[] entries */
230-
if ( t->size < min_size )
235+
if ( info->size < min_size )
231236
goto err;
232237

233-
ptr_current = evtlog_base = _p(t->address);
234-
limit = _p(t->address + t->size);
238+
ptr_current = evtlog_base = _p(info->addr);
239+
limit = _p(info->addr + info->size);
235240

236241
/* Check for overflow */
237242
if ( ptr_current > limit )
@@ -245,7 +250,12 @@ int event_log_init(struct tpm *tpm)
245250
if ( !(_p(limit) < _p(_start) || _p(_start + SLB_SIZE) < _p(ptr_current)) )
246251
goto err;
247252

248-
memset(ptr_current, 0, t->size);
253+
memset(ptr_current, 0, info->size);
254+
255+
/* Check if log format matches TPM family */
256+
if ((tpm->family == TPM12 && info->format != SLR_LOG_FORMAT_TPM12_TXT) ||
257+
(tpm->family == TPM20 && info->format != SLR_LOG_FORMAT_TPM20_TCG))
258+
goto err;
249259

250260
/* Write log header */
251261
{
@@ -266,52 +276,26 @@ int event_log_init(struct tpm *tpm)
266276
if ( tpm->family == TPM12 ) {
267277
tpm12_spec_id_ev_t *id = (tpm12_spec_id_ev_t *)ptr_current;
268278
log_write(&tpm12_id_struct, sizeof(tpm12_id_struct));
269-
id->hdr.container_size = t->size;
279+
id->hdr.container_size = info->size;
270280
} else {
271281
tpm20_spec_id_ev_t *id = (tpm20_spec_id_ev_t *)ptr_current;
272282
log_write(&tpm20_id_struct, sizeof(tpm20_id_struct));
273-
id->el.allocated_event_container_size = t->size;
283+
id->el.allocated_event_container_size = info->size;
274284
id->el.phys_addr = _u(evtlog_base);
275285
}
276286

277287
/* Log what was done by SKINIT */
288+
sha1sum(hash, _start, _end_of_measured - _start);
278289
if ( tpm->family == TPM12 )
279290
{
280-
struct skl_tag_hash *h = next_of_type(&bootloader_data, SKL_TAG_SKL_HASH);
281-
282-
while ( h != NULL )
283-
{
284-
if ( h->algo_id == TPM_ALG_SHA1 )
285-
return log_event_tpm12(17, h->digest, "SKINIT");
286-
287-
h = next_of_type(h, SKL_TAG_SKL_HASH);
288-
}
289-
290-
/* No SHA1 hash was passed by a bootloader? */
291-
return 1;
291+
return log_event_tpm12(17, hash, "SKINIT");
292292
}
293-
else
293+
else if ( tpm->family == TPM20 )
294294
{
295-
struct skl_tag_hash *h = next_of_type(&bootloader_data, SKL_TAG_SKL_HASH);
296-
u8 *sha1 = NULL;
297-
u8 *sha256 = NULL;
298-
299-
while ( h != NULL )
300-
{
301-
if ( h->algo_id == TPM_ALG_SHA1 )
302-
sha1 = h->digest;
303-
304-
if ( h->algo_id == TPM_ALG_SHA256 )
305-
sha256 = h->digest;
295+
u8 sha256_hash[SHA256_DIGEST_SIZE];
306296

307-
if ( sha1 != NULL && sha256 != NULL )
308-
return log_event_tpm20(17, sha1, sha256, "SKINIT");
309-
310-
h = next_of_type(h, SKL_TAG_SKL_HASH);
311-
}
312-
313-
/* Either SHA1 or SHA256 hash wasn't passed by a bootloader? */
314-
return 1;
297+
sha256sum(sha256_hash, _start, _end_of_measured - _start);
298+
return log_event_tpm20(17, hash, sha256_hash, "SKINIT");
315299
}
316300

317301
err:

include/boot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define __BOOT_H__
4141

4242
extern const char _start[];
43+
extern const char _end_of_measured[];
4344

4445
typedef struct __packed sl_header {
4546
u16 skl_entry_point;

0 commit comments

Comments
 (0)