2 * Copyright (C) 2005, 2012 IBM Corporation
5 * Kent Yoder <key@linux.vnet.ibm.com>
6 * Seiji Munetoh <munetoh@jp.ibm.com>
7 * Stefan Berger <stefanb@us.ibm.com>
8 * Reiner Sailer <sailer@watson.ibm.com>
9 * Kylene Hall <kjhall@us.ibm.com>
10 * Nayna Jain <nayna@linux.vnet.ibm.com>
12 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
14 * Access to the event log created by a system's firmware / BIOS
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version
19 * 2 of the License, or (at your option) any later version.
23 #include <linux/seq_file.h>
24 #include <linux/efi.h>
26 #include <linux/security.h>
27 #include <linux/module.h>
28 #include <linux/slab.h>
29 #include <linux/tpm_eventlog.h>
35 static const char* tcpa_event_type_strings
[] = {
46 "Platform Config Flags",
56 static const char* tcpa_pc_event_id_strings
[] = {
67 "Option ROM microcode ",
74 /* returns pointer to start of pos. entry of tcg log */
75 static void *tpm1_bios_measurements_start(struct seq_file
*m
, loff_t
*pos
)
78 struct tpm_chip
*chip
= m
->private;
79 struct tpm_bios_log
*log
= &chip
->log
;
80 void *addr
= log
->bios_event_log
;
81 void *limit
= log
->bios_event_log_end
;
82 struct tcpa_event
*event
;
83 u32 converted_event_size
;
84 u32 converted_event_type
;
87 /* read over *pos measurements */
88 for (i
= 0; i
< *pos
; i
++) {
91 converted_event_size
=
92 do_endian_conversion(event
->event_size
);
93 converted_event_type
=
94 do_endian_conversion(event
->event_type
);
96 if ((addr
+ sizeof(struct tcpa_event
)) < limit
) {
97 if ((converted_event_type
== 0) &&
98 (converted_event_size
== 0))
100 addr
+= (sizeof(struct tcpa_event
) +
101 converted_event_size
);
105 /* now check if current entry is valid */
106 if ((addr
+ sizeof(struct tcpa_event
)) >= limit
)
111 converted_event_size
= do_endian_conversion(event
->event_size
);
112 converted_event_type
= do_endian_conversion(event
->event_type
);
114 if (((converted_event_type
== 0) && (converted_event_size
== 0))
115 || ((addr
+ sizeof(struct tcpa_event
) + converted_event_size
)
122 static void *tpm1_bios_measurements_next(struct seq_file
*m
, void *v
,
125 struct tcpa_event
*event
= v
;
126 struct tpm_chip
*chip
= m
->private;
127 struct tpm_bios_log
*log
= &chip
->log
;
128 void *limit
= log
->bios_event_log_end
;
129 u32 converted_event_size
;
130 u32 converted_event_type
;
132 converted_event_size
= do_endian_conversion(event
->event_size
);
134 v
+= sizeof(struct tcpa_event
) + converted_event_size
;
136 /* now check if current entry is valid */
137 if ((v
+ sizeof(struct tcpa_event
)) >= limit
)
142 converted_event_size
= do_endian_conversion(event
->event_size
);
143 converted_event_type
= do_endian_conversion(event
->event_type
);
145 if (((converted_event_type
== 0) && (converted_event_size
== 0)) ||
146 ((v
+ sizeof(struct tcpa_event
) + converted_event_size
) >= limit
))
153 static void tpm1_bios_measurements_stop(struct seq_file
*m
, void *v
)
157 static int get_event_name(char *dest
, struct tcpa_event
*event
,
158 unsigned char * event_entry
)
160 const char *name
= "";
161 /* 41 so there is room for 40 data and 1 nul */
163 int i
, n_len
= 0, d_len
= 0;
164 struct tcpa_pc_event
*pc_event
;
166 switch (do_endian_conversion(event
->event_type
)) {
174 case PLATFORM_CONFIG_FLAGS
:
175 case TABLE_OF_DEVICES
:
178 case IPL_PARTITION_DATA
:
182 name
= tcpa_event_type_strings
[do_endian_conversion
183 (event
->event_type
)];
184 n_len
= strlen(name
);
189 do_endian_conversion(event
->event_size
)) {
191 n_len
= do_endian_conversion(event
->event_size
);
195 pc_event
= (struct tcpa_pc_event
*)event_entry
;
197 /* ToDo Row data -> Base64 */
199 switch (do_endian_conversion(pc_event
->event_id
)) {
204 case OPTION_ROM_EXEC
:
205 case OPTION_ROM_CONFIG
:
207 name
= tcpa_pc_event_id_strings
[do_endian_conversion
208 (pc_event
->event_id
)];
209 n_len
= strlen(name
);
214 case OPTION_ROM_MICROCODE
:
215 case S_CRTM_CONTENTS
:
217 name
= tcpa_pc_event_id_strings
[do_endian_conversion
218 (pc_event
->event_id
)];
219 n_len
= strlen(name
);
220 for (i
= 0; i
< 20; i
++)
221 d_len
+= sprintf(&data
[2*i
], "%02x",
222 pc_event
->event_data
[i
]);
231 return snprintf(dest
, MAX_TEXT_EVENT
, "[%.*s%.*s]",
232 n_len
, name
, d_len
, data
);
236 static int tpm1_binary_bios_measurements_show(struct seq_file
*m
, void *v
)
238 struct tcpa_event
*event
= v
;
239 struct tcpa_event temp_event
;
243 memcpy(&temp_event
, event
, sizeof(struct tcpa_event
));
245 /* convert raw integers for endianness */
246 temp_event
.pcr_index
= do_endian_conversion(event
->pcr_index
);
247 temp_event
.event_type
= do_endian_conversion(event
->event_type
);
248 temp_event
.event_size
= do_endian_conversion(event
->event_size
);
250 temp_ptr
= (char *) &temp_event
;
252 for (i
= 0; i
< (sizeof(struct tcpa_event
) - 1) ; i
++)
253 seq_putc(m
, temp_ptr
[i
]);
255 temp_ptr
= (char *) v
;
257 for (i
= (sizeof(struct tcpa_event
) - 1);
258 i
< (sizeof(struct tcpa_event
) + temp_event
.event_size
); i
++)
259 seq_putc(m
, temp_ptr
[i
]);
265 static int tpm1_ascii_bios_measurements_show(struct seq_file
*m
, void *v
)
269 struct tcpa_event
*event
= v
;
270 unsigned char *event_entry
=
271 (unsigned char *)(v
+ sizeof(struct tcpa_event
));
273 eventname
= kmalloc(MAX_TEXT_EVENT
, GFP_KERNEL
);
275 printk(KERN_ERR
"%s: ERROR - No Memory for event name\n ",
281 seq_printf(m
, "%2d ", do_endian_conversion(event
->pcr_index
));
284 seq_printf(m
, "%20phN", event
->pcr_value
);
286 /* 3rd: event type identifier */
287 seq_printf(m
, " %02x", do_endian_conversion(event
->event_type
));
289 len
+= get_event_name(eventname
, event
, event_entry
);
291 /* 4th: eventname <= max + \'0' delimiter */
292 seq_printf(m
, " %s\n", eventname
);
298 const struct seq_operations tpm1_ascii_b_measurements_seqops
= {
299 .start
= tpm1_bios_measurements_start
,
300 .next
= tpm1_bios_measurements_next
,
301 .stop
= tpm1_bios_measurements_stop
,
302 .show
= tpm1_ascii_bios_measurements_show
,
305 const struct seq_operations tpm1_binary_b_measurements_seqops
= {
306 .start
= tpm1_bios_measurements_start
,
307 .next
= tpm1_bios_measurements_next
,
308 .stop
= tpm1_bios_measurements_stop
,
309 .show
= tpm1_binary_bios_measurements_show
,