Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 1 | /* |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 2 | * Copyright (C) 2005, 2012 IBM Corporation |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 3 | * |
| 4 | * Authors: |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 5 | * Kent Yoder <key@linux.vnet.ibm.com> |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 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 | * |
Kent Yoder | 8e81cc1 | 2007-08-22 14:01:04 -0700 | [diff] [blame] | 11 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
| 12 | * |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 13 | * Access to the eventlog created by a system's firmware / BIOS |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <linux/seq_file.h> |
| 23 | #include <linux/fs.h> |
| 24 | #include <linux/security.h> |
| 25 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 27 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 28 | #include "tpm.h" |
Kent Yoder | e5dcd87 | 2012-07-11 10:08:12 -0500 | [diff] [blame] | 29 | #include "tpm_eventlog.h" |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 30 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 31 | |
| 32 | static const char* tcpa_event_type_strings[] = { |
| 33 | "PREBOOT", |
| 34 | "POST CODE", |
| 35 | "", |
| 36 | "NO ACTION", |
| 37 | "SEPARATOR", |
| 38 | "ACTION", |
| 39 | "EVENT TAG", |
| 40 | "S-CRTM Contents", |
| 41 | "S-CRTM Version", |
| 42 | "CPU Microcode", |
| 43 | "Platform Config Flags", |
| 44 | "Table of Devices", |
| 45 | "Compact Hash", |
| 46 | "IPL", |
| 47 | "IPL Partition Data", |
| 48 | "Non-Host Code", |
| 49 | "Non-Host Config", |
| 50 | "Non-Host Info" |
| 51 | }; |
| 52 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 53 | static const char* tcpa_pc_event_id_strings[] = { |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 54 | "", |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 55 | "SMBIOS", |
| 56 | "BIS Certificate", |
| 57 | "POST BIOS ", |
| 58 | "ESCD ", |
| 59 | "CMOS", |
| 60 | "NVRAM", |
| 61 | "Option ROM", |
| 62 | "Option ROM config", |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 63 | "", |
| 64 | "Option ROM microcode ", |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 65 | "S-CRTM Version", |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 66 | "S-CRTM Contents ", |
| 67 | "POST Contents ", |
| 68 | "Table of Devices", |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 71 | /* returns pointer to start of pos. entry of tcg log */ |
| 72 | static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos) |
| 73 | { |
| 74 | loff_t i; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 75 | struct tpm_bios_log *log = m->private; |
| 76 | void *addr = log->bios_event_log; |
| 77 | void *limit = log->bios_event_log_end; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 78 | struct tcpa_event *event; |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 79 | u32 converted_event_size; |
| 80 | u32 converted_event_type; |
| 81 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 82 | |
| 83 | /* read over *pos measurements */ |
| 84 | for (i = 0; i < *pos; i++) { |
| 85 | event = addr; |
| 86 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 87 | converted_event_size = |
| 88 | do_endian_conversion(event->event_size); |
| 89 | converted_event_type = |
| 90 | do_endian_conversion(event->event_type); |
| 91 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 92 | if ((addr + sizeof(struct tcpa_event)) < limit) { |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 93 | if ((converted_event_type == 0) && |
| 94 | (converted_event_size == 0)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 95 | return NULL; |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 96 | addr += (sizeof(struct tcpa_event) + |
| 97 | converted_event_size); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | /* now check if current entry is valid */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 102 | if ((addr + sizeof(struct tcpa_event)) >= limit) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 103 | return NULL; |
| 104 | |
| 105 | event = addr; |
| 106 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 107 | converted_event_size = do_endian_conversion(event->event_size); |
| 108 | converted_event_type = do_endian_conversion(event->event_type); |
| 109 | |
| 110 | if (((converted_event_type == 0) && (converted_event_size == 0)) |
| 111 | || ((addr + sizeof(struct tcpa_event) + converted_event_size) |
| 112 | >= limit)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 113 | return NULL; |
| 114 | |
| 115 | return addr; |
| 116 | } |
| 117 | |
| 118 | static void *tpm_bios_measurements_next(struct seq_file *m, void *v, |
| 119 | loff_t *pos) |
| 120 | { |
| 121 | struct tcpa_event *event = v; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 122 | struct tpm_bios_log *log = m->private; |
| 123 | void *limit = log->bios_event_log_end; |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 124 | u32 converted_event_size; |
| 125 | u32 converted_event_type; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 126 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 127 | converted_event_size = do_endian_conversion(event->event_size); |
| 128 | |
| 129 | v += sizeof(struct tcpa_event) + converted_event_size; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 130 | |
| 131 | /* now check if current entry is valid */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 132 | if ((v + sizeof(struct tcpa_event)) >= limit) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 133 | return NULL; |
| 134 | |
| 135 | event = v; |
| 136 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 137 | converted_event_size = do_endian_conversion(event->event_size); |
| 138 | converted_event_type = do_endian_conversion(event->event_type); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 139 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 140 | if (((converted_event_type == 0) && (converted_event_size == 0)) || |
| 141 | ((v + sizeof(struct tcpa_event) + converted_event_size) >= limit)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 142 | return NULL; |
| 143 | |
| 144 | (*pos)++; |
| 145 | return v; |
| 146 | } |
| 147 | |
| 148 | static void tpm_bios_measurements_stop(struct seq_file *m, void *v) |
| 149 | { |
| 150 | } |
| 151 | |
| 152 | static int get_event_name(char *dest, struct tcpa_event *event, |
| 153 | unsigned char * event_entry) |
| 154 | { |
| 155 | const char *name = ""; |
Eric Paris | fbaa586 | 2009-05-13 12:50:40 -0400 | [diff] [blame] | 156 | /* 41 so there is room for 40 data and 1 nul */ |
| 157 | char data[41] = ""; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 158 | int i, n_len = 0, d_len = 0; |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 159 | struct tcpa_pc_event *pc_event; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 160 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 161 | switch (do_endian_conversion(event->event_type)) { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 162 | case PREBOOT: |
| 163 | case POST_CODE: |
| 164 | case UNUSED: |
| 165 | case NO_ACTION: |
| 166 | case SCRTM_CONTENTS: |
| 167 | case SCRTM_VERSION: |
| 168 | case CPU_MICROCODE: |
| 169 | case PLATFORM_CONFIG_FLAGS: |
| 170 | case TABLE_OF_DEVICES: |
| 171 | case COMPACT_HASH: |
| 172 | case IPL: |
| 173 | case IPL_PARTITION_DATA: |
| 174 | case NONHOST_CODE: |
| 175 | case NONHOST_CONFIG: |
| 176 | case NONHOST_INFO: |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 177 | name = tcpa_event_type_strings[do_endian_conversion |
| 178 | (event->event_type)]; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 179 | n_len = strlen(name); |
| 180 | break; |
| 181 | case SEPARATOR: |
| 182 | case ACTION: |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 183 | if (MAX_TEXT_EVENT > |
| 184 | do_endian_conversion(event->event_size)) { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 185 | name = event_entry; |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 186 | n_len = do_endian_conversion(event->event_size); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 187 | } |
| 188 | break; |
| 189 | case EVENT_TAG: |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 190 | pc_event = (struct tcpa_pc_event *)event_entry; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 191 | |
| 192 | /* ToDo Row data -> Base64 */ |
| 193 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 194 | switch (do_endian_conversion(pc_event->event_id)) { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 195 | case SMBIOS: |
| 196 | case BIS_CERT: |
| 197 | case CMOS: |
| 198 | case NVRAM: |
| 199 | case OPTION_ROM_EXEC: |
| 200 | case OPTION_ROM_CONFIG: |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 201 | case S_CRTM_VERSION: |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 202 | name = tcpa_pc_event_id_strings[do_endian_conversion |
| 203 | (pc_event->event_id)]; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 204 | n_len = strlen(name); |
| 205 | break; |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 206 | /* hash data */ |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 207 | case POST_BIOS_ROM: |
| 208 | case ESCD: |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 209 | case OPTION_ROM_MICROCODE: |
| 210 | case S_CRTM_CONTENTS: |
| 211 | case POST_CONTENTS: |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 212 | name = tcpa_pc_event_id_strings[do_endian_conversion |
| 213 | (pc_event->event_id)]; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 214 | n_len = strlen(name); |
| 215 | for (i = 0; i < 20; i++) |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 216 | d_len += sprintf(&data[2*i], "%02x", |
| 217 | pc_event->event_data[i]); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 218 | break; |
| 219 | default: |
| 220 | break; |
| 221 | } |
| 222 | default: |
| 223 | break; |
| 224 | } |
| 225 | |
| 226 | return snprintf(dest, MAX_TEXT_EVENT, "[%.*s%.*s]", |
| 227 | n_len, name, d_len, data); |
| 228 | |
| 229 | } |
| 230 | |
| 231 | static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v) |
| 232 | { |
Seiji Munetoh | 44d7aff | 2006-05-30 21:25:52 -0700 | [diff] [blame] | 233 | struct tcpa_event *event = v; |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 234 | struct tcpa_event temp_event; |
| 235 | char *tempPtr; |
Seiji Munetoh | 44d7aff | 2006-05-30 21:25:52 -0700 | [diff] [blame] | 236 | int i; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 237 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 238 | memcpy(&temp_event, event, sizeof(struct tcpa_event)); |
| 239 | |
| 240 | /* convert raw integers for endianness */ |
| 241 | temp_event.pcr_index = do_endian_conversion(event->pcr_index); |
| 242 | temp_event.event_type = do_endian_conversion(event->event_type); |
| 243 | temp_event.event_size = do_endian_conversion(event->event_size); |
| 244 | |
| 245 | tempPtr = (char *)&temp_event; |
| 246 | |
| 247 | for (i = 0; i < sizeof(struct tcpa_event) + temp_event.event_size; i++) |
| 248 | seq_putc(m, tempPtr[i]); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 249 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 250 | return 0; |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 251 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static int tpm_bios_measurements_release(struct inode *inode, |
| 255 | struct file *file) |
| 256 | { |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 257 | struct seq_file *seq = file->private_data; |
| 258 | struct tpm_bios_log *log = seq->private; |
| 259 | |
| 260 | if (log) { |
| 261 | kfree(log->bios_event_log); |
| 262 | kfree(log); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 263 | } |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 264 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 265 | return seq_release(inode, file); |
| 266 | } |
| 267 | |
| 268 | static int tpm_ascii_bios_measurements_show(struct seq_file *m, void *v) |
| 269 | { |
| 270 | int len = 0; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 271 | char *eventname; |
| 272 | struct tcpa_event *event = v; |
| 273 | unsigned char *event_entry = |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 274 | (unsigned char *)(v + sizeof(struct tcpa_event)); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 275 | |
| 276 | eventname = kmalloc(MAX_TEXT_EVENT, GFP_KERNEL); |
| 277 | if (!eventname) { |
| 278 | printk(KERN_ERR "%s: ERROR - No Memory for event name\n ", |
| 279 | __func__); |
| 280 | return -EFAULT; |
| 281 | } |
| 282 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 283 | /* 1st: PCR */ |
| 284 | seq_printf(m, "%2d ", do_endian_conversion(event->pcr_index)); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 285 | |
| 286 | /* 2nd: SHA1 */ |
Andy Shevchenko | a3d64df | 2014-07-09 15:34:41 +0300 | [diff] [blame] | 287 | seq_printf(m, "%20phN", event->pcr_value); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 288 | |
| 289 | /* 3rd: event type identifier */ |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 290 | seq_printf(m, " %02x", do_endian_conversion(event->event_type)); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 291 | |
| 292 | len += get_event_name(eventname, event, event_entry); |
| 293 | |
| 294 | /* 4th: eventname <= max + \'0' delimiter */ |
| 295 | seq_printf(m, " %s\n", eventname); |
| 296 | |
Kylene Jo Hall | 59e89f3 | 2006-04-22 02:36:35 -0700 | [diff] [blame] | 297 | kfree(eventname); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 301 | static const struct seq_operations tpm_ascii_b_measurments_seqops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 302 | .start = tpm_bios_measurements_start, |
| 303 | .next = tpm_bios_measurements_next, |
| 304 | .stop = tpm_bios_measurements_stop, |
| 305 | .show = tpm_ascii_bios_measurements_show, |
| 306 | }; |
| 307 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 308 | static const struct seq_operations tpm_binary_b_measurments_seqops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 309 | .start = tpm_bios_measurements_start, |
| 310 | .next = tpm_bios_measurements_next, |
| 311 | .stop = tpm_bios_measurements_stop, |
| 312 | .show = tpm_binary_bios_measurements_show, |
| 313 | }; |
| 314 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 315 | static int tpm_ascii_bios_measurements_open(struct inode *inode, |
| 316 | struct file *file) |
| 317 | { |
| 318 | int err; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 319 | struct tpm_bios_log *log; |
| 320 | struct seq_file *seq; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 321 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 322 | log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL); |
| 323 | if (!log) |
| 324 | return -ENOMEM; |
| 325 | |
| 326 | if ((err = read_log(log))) |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 327 | goto out_free; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 328 | |
| 329 | /* now register seq file */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 330 | err = seq_open(file, &tpm_ascii_b_measurments_seqops); |
| 331 | if (!err) { |
| 332 | seq = file->private_data; |
| 333 | seq->private = log; |
| 334 | } else { |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 335 | goto out_free; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 336 | } |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 337 | |
| 338 | out: |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 339 | return err; |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 340 | out_free: |
| 341 | kfree(log->bios_event_log); |
| 342 | kfree(log); |
| 343 | goto out; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Adrian Bunk | 3bd6046 | 2008-07-25 19:44:58 -0700 | [diff] [blame] | 346 | static const struct file_operations tpm_ascii_bios_measurements_ops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 347 | .open = tpm_ascii_bios_measurements_open, |
| 348 | .read = seq_read, |
| 349 | .llseek = seq_lseek, |
| 350 | .release = tpm_bios_measurements_release, |
| 351 | }; |
| 352 | |
| 353 | static int tpm_binary_bios_measurements_open(struct inode *inode, |
| 354 | struct file *file) |
| 355 | { |
| 356 | int err; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 357 | struct tpm_bios_log *log; |
| 358 | struct seq_file *seq; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 359 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 360 | log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL); |
| 361 | if (!log) |
| 362 | return -ENOMEM; |
| 363 | |
| 364 | if ((err = read_log(log))) |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 365 | goto out_free; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 366 | |
| 367 | /* now register seq file */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 368 | err = seq_open(file, &tpm_binary_b_measurments_seqops); |
| 369 | if (!err) { |
| 370 | seq = file->private_data; |
| 371 | seq->private = log; |
| 372 | } else { |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 373 | goto out_free; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 374 | } |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 375 | |
| 376 | out: |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 377 | return err; |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 378 | out_free: |
| 379 | kfree(log->bios_event_log); |
| 380 | kfree(log); |
| 381 | goto out; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Adrian Bunk | 3bd6046 | 2008-07-25 19:44:58 -0700 | [diff] [blame] | 384 | static const struct file_operations tpm_binary_bios_measurements_ops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 385 | .open = tpm_binary_bios_measurements_open, |
| 386 | .read = seq_read, |
| 387 | .llseek = seq_lseek, |
| 388 | .release = tpm_bios_measurements_release, |
| 389 | }; |
| 390 | |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 391 | static int is_bad(void *p) |
| 392 | { |
| 393 | if (!p) |
| 394 | return 1; |
| 395 | if (IS_ERR(p) && (PTR_ERR(p) != -ENODEV)) |
| 396 | return 1; |
| 397 | return 0; |
| 398 | } |
| 399 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 400 | struct dentry **tpm_bios_log_setup(char *name) |
| 401 | { |
| 402 | struct dentry **ret = NULL, *tpm_dir, *bin_file, *ascii_file; |
| 403 | |
| 404 | tpm_dir = securityfs_create_dir(name, NULL); |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 405 | if (is_bad(tpm_dir)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 406 | goto out; |
| 407 | |
| 408 | bin_file = |
| 409 | securityfs_create_file("binary_bios_measurements", |
| 410 | S_IRUSR | S_IRGRP, tpm_dir, NULL, |
| 411 | &tpm_binary_bios_measurements_ops); |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 412 | if (is_bad(bin_file)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 413 | goto out_tpm; |
| 414 | |
| 415 | ascii_file = |
| 416 | securityfs_create_file("ascii_bios_measurements", |
| 417 | S_IRUSR | S_IRGRP, tpm_dir, NULL, |
| 418 | &tpm_ascii_bios_measurements_ops); |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 419 | if (is_bad(ascii_file)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 420 | goto out_bin; |
| 421 | |
| 422 | ret = kmalloc(3 * sizeof(struct dentry *), GFP_KERNEL); |
| 423 | if (!ret) |
| 424 | goto out_ascii; |
| 425 | |
| 426 | ret[0] = ascii_file; |
| 427 | ret[1] = bin_file; |
| 428 | ret[2] = tpm_dir; |
| 429 | |
| 430 | return ret; |
| 431 | |
| 432 | out_ascii: |
| 433 | securityfs_remove(ascii_file); |
| 434 | out_bin: |
| 435 | securityfs_remove(bin_file); |
| 436 | out_tpm: |
| 437 | securityfs_remove(tpm_dir); |
| 438 | out: |
| 439 | return NULL; |
| 440 | } |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 441 | |
| 442 | void tpm_bios_log_teardown(struct dentry **lst) |
| 443 | { |
| 444 | int i; |
| 445 | |
| 446 | for (i = 0; i < 3; i++) |
| 447 | securityfs_remove(lst[i]); |
| 448 | } |