tpm2.c (3eb66e91a25497065c5322b1268cbc3953642227) tpm2.c (c8faabfc6f48009fb0d9ad4203aecfa569e5ff8d)
1/*
2 * Copyright (C) 2016 IBM Corporation
3 *
4 * Authors:
5 * Nayna Jain <nayna@linux.vnet.ibm.com>
6 *
7 * Access to TPM 2.0 event log as written by Firmware.
8 * It assumes that writer of event log has followed TCG Specification

--- 23 unchanged lines hidden (view full) ---

32 * Agile Log Entry Format as defined in TCG EFI Protocol Specification
33 * Family "2.0".
34
35 * @event: event whose size is to be calculated.
36 * @event_header: the first event in the event log.
37 *
38 * Returns size of the event. If it is an invalid event, returns 0.
39 */
1/*
2 * Copyright (C) 2016 IBM Corporation
3 *
4 * Authors:
5 * Nayna Jain <nayna@linux.vnet.ibm.com>
6 *
7 * Access to TPM 2.0 event log as written by Firmware.
8 * It assumes that writer of event log has followed TCG Specification

--- 23 unchanged lines hidden (view full) ---

32 * Agile Log Entry Format as defined in TCG EFI Protocol Specification
33 * Family "2.0".
34
35 * @event: event whose size is to be calculated.
36 * @event_header: the first event in the event log.
37 *
38 * Returns size of the event. If it is an invalid event, returns 0.
39 */
40static int calc_tpm2_event_size(struct tcg_pcr_event2 *event,
40static int calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
41 struct tcg_pcr_event *event_header)
42{
41 struct tcg_pcr_event *event_header)
42{
43 struct tcg_efi_specid_event *efispecid;
43 struct tcg_efi_specid_event_head *efispecid;
44 struct tcg_event_field *event_field;
45 void *marker;
46 void *marker_start;
47 u32 halg_size;
48 size_t size;
49 u16 halg;
50 int i;
51 int j;
52
53 marker = event;
54 marker_start = marker;
55 marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type)
56 + sizeof(event->count);
57
44 struct tcg_event_field *event_field;
45 void *marker;
46 void *marker_start;
47 u32 halg_size;
48 size_t size;
49 u16 halg;
50 int i;
51 int j;
52
53 marker = event;
54 marker_start = marker;
55 marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type)
56 + sizeof(event->count);
57
58 efispecid = (struct tcg_efi_specid_event *)event_header->event;
58 efispecid = (struct tcg_efi_specid_event_head *)event_header->event;
59
60 /* Check if event is malformed. */
61 if (event->count > efispecid->num_algs)
62 return 0;
63
64 for (i = 0; i < event->count; i++) {
65 halg_size = sizeof(event->digests[i].alg_id);
66 memcpy(&halg, marker, halg_size);

--- 23 unchanged lines hidden (view full) ---

90
91static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos)
92{
93 struct tpm_chip *chip = m->private;
94 struct tpm_bios_log *log = &chip->log;
95 void *addr = log->bios_event_log;
96 void *limit = log->bios_event_log_end;
97 struct tcg_pcr_event *event_header;
59
60 /* Check if event is malformed. */
61 if (event->count > efispecid->num_algs)
62 return 0;
63
64 for (i = 0; i < event->count; i++) {
65 halg_size = sizeof(event->digests[i].alg_id);
66 memcpy(&halg, marker, halg_size);

--- 23 unchanged lines hidden (view full) ---

90
91static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos)
92{
93 struct tpm_chip *chip = m->private;
94 struct tpm_bios_log *log = &chip->log;
95 void *addr = log->bios_event_log;
96 void *limit = log->bios_event_log_end;
97 struct tcg_pcr_event *event_header;
98 struct tcg_pcr_event2 *event;
98 struct tcg_pcr_event2_head *event;
99 size_t size;
100 int i;
101
102 event_header = addr;
103 size = sizeof(struct tcg_pcr_event) - sizeof(event_header->event)
104 + event_header->event_size;
105
106 if (*pos == 0) {

--- 24 unchanged lines hidden (view full) ---

131
132 return addr;
133}
134
135static void *tpm2_bios_measurements_next(struct seq_file *m, void *v,
136 loff_t *pos)
137{
138 struct tcg_pcr_event *event_header;
99 size_t size;
100 int i;
101
102 event_header = addr;
103 size = sizeof(struct tcg_pcr_event) - sizeof(event_header->event)
104 + event_header->event_size;
105
106 if (*pos == 0) {

--- 24 unchanged lines hidden (view full) ---

131
132 return addr;
133}
134
135static void *tpm2_bios_measurements_next(struct seq_file *m, void *v,
136 loff_t *pos)
137{
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;
141 struct tpm_bios_log *log = &chip->log;
142 void *limit = log->bios_event_log_end;
143 size_t event_size;
144 void *marker;
145
146 event_header = log->bios_event_log;
147

--- 27 unchanged lines hidden (view full) ---

175{
176}
177
178static int tpm2_binary_bios_measurements_show(struct seq_file *m, void *v)
179{
180 struct tpm_chip *chip = m->private;
181 struct tpm_bios_log *log = &chip->log;
182 struct tcg_pcr_event *event_header = log->bios_event_log;
140 struct tpm_chip *chip = m->private;
141 struct tpm_bios_log *log = &chip->log;
142 void *limit = log->bios_event_log_end;
143 size_t event_size;
144 void *marker;
145
146 event_header = log->bios_event_log;
147

--- 27 unchanged lines hidden (view full) ---

175{
176}
177
178static int tpm2_binary_bios_measurements_show(struct seq_file *m, void *v)
179{
180 struct tpm_chip *chip = m->private;
181 struct tpm_bios_log *log = &chip->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;
185 size_t size;
186
187 if (v == SEQ_START_TOKEN) {
188 size = sizeof(struct tcg_pcr_event) -
189 sizeof(event_header->event) + event_header->event_size;
190
191 temp_ptr = event_header;

--- 19 unchanged lines hidden ---
184 void *temp_ptr;
185 size_t size;
186
187 if (v == SEQ_START_TOKEN) {
188 size = sizeof(struct tcg_pcr_event) -
189 sizeof(event_header->event) + event_header->event_size;
190
191 temp_ptr = event_header;

--- 19 unchanged lines hidden ---