Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 IBM Corporation |
| 3 | * |
| 4 | * Authors: |
| 5 | * Seiji Munetoh <munetoh@jp.ibm.com> |
| 6 | * Stefan Berger <stefanb@us.ibm.com> |
| 7 | * Reiner Sailer <sailer@watson.ibm.com> |
| 8 | * Kylene Hall <kjhall@us.ibm.com> |
| 9 | * |
Kent Yoder | 8e81cc1 | 2007-08-22 14:01:04 -0700 | [diff] [blame] | 10 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
| 11 | * |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 12 | * Access to the eventlog extended by the TCG BIOS of PC platform |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; either version |
| 17 | * 2 of the License, or (at your option) any later version. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <linux/seq_file.h> |
| 22 | #include <linux/fs.h> |
| 23 | #include <linux/security.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <acpi/acpi.h> |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 26 | #include "tpm.h" |
| 27 | |
| 28 | #define TCG_EVENT_NAME_LEN_MAX 255 |
| 29 | #define MAX_TEXT_EVENT 1000 /* Max event string length */ |
| 30 | #define ACPI_TCPA_SIG "TCPA" /* 0x41504354 /'TCPA' */ |
| 31 | |
Kylene Jo Hall | 8b006db | 2006-04-22 02:39:07 -0700 | [diff] [blame] | 32 | enum bios_platform_class { |
| 33 | BIOS_CLIENT = 0x00, |
| 34 | BIOS_SERVER = 0x01, |
| 35 | }; |
| 36 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 37 | struct tpm_bios_log { |
| 38 | void *bios_event_log; |
| 39 | void *bios_event_log_end; |
| 40 | }; |
| 41 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 42 | struct acpi_tcpa { |
| 43 | struct acpi_table_header hdr; |
Kylene Jo Hall | 8b006db | 2006-04-22 02:39:07 -0700 | [diff] [blame] | 44 | u16 platform_class; |
| 45 | union { |
| 46 | struct client_hdr { |
| 47 | u32 log_max_len __attribute__ ((packed)); |
| 48 | u64 log_start_addr __attribute__ ((packed)); |
| 49 | } client; |
| 50 | struct server_hdr { |
| 51 | u16 reserved; |
| 52 | u64 log_max_len __attribute__ ((packed)); |
| 53 | u64 log_start_addr __attribute__ ((packed)); |
| 54 | } server; |
| 55 | }; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | struct tcpa_event { |
| 59 | u32 pcr_index; |
| 60 | u32 event_type; |
| 61 | u8 pcr_value[20]; /* SHA1 */ |
| 62 | u32 event_size; |
| 63 | u8 event_data[0]; |
| 64 | }; |
| 65 | |
| 66 | enum tcpa_event_types { |
| 67 | PREBOOT = 0, |
| 68 | POST_CODE, |
| 69 | UNUSED, |
| 70 | NO_ACTION, |
| 71 | SEPARATOR, |
| 72 | ACTION, |
| 73 | EVENT_TAG, |
| 74 | SCRTM_CONTENTS, |
| 75 | SCRTM_VERSION, |
| 76 | CPU_MICROCODE, |
| 77 | PLATFORM_CONFIG_FLAGS, |
| 78 | TABLE_OF_DEVICES, |
| 79 | COMPACT_HASH, |
| 80 | IPL, |
| 81 | IPL_PARTITION_DATA, |
| 82 | NONHOST_CODE, |
| 83 | NONHOST_CONFIG, |
| 84 | NONHOST_INFO, |
| 85 | }; |
| 86 | |
| 87 | static const char* tcpa_event_type_strings[] = { |
| 88 | "PREBOOT", |
| 89 | "POST CODE", |
| 90 | "", |
| 91 | "NO ACTION", |
| 92 | "SEPARATOR", |
| 93 | "ACTION", |
| 94 | "EVENT TAG", |
| 95 | "S-CRTM Contents", |
| 96 | "S-CRTM Version", |
| 97 | "CPU Microcode", |
| 98 | "Platform Config Flags", |
| 99 | "Table of Devices", |
| 100 | "Compact Hash", |
| 101 | "IPL", |
| 102 | "IPL Partition Data", |
| 103 | "Non-Host Code", |
| 104 | "Non-Host Config", |
| 105 | "Non-Host Info" |
| 106 | }; |
| 107 | |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 108 | struct tcpa_pc_event { |
| 109 | u32 event_id; |
| 110 | u32 event_size; |
| 111 | u8 event_data[0]; |
| 112 | }; |
| 113 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 114 | enum tcpa_pc_event_ids { |
| 115 | SMBIOS = 1, |
| 116 | BIS_CERT, |
| 117 | POST_BIOS_ROM, |
| 118 | ESCD, |
| 119 | CMOS, |
| 120 | NVRAM, |
| 121 | OPTION_ROM_EXEC, |
| 122 | OPTION_ROM_CONFIG, |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 123 | OPTION_ROM_MICROCODE = 10, |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 124 | S_CRTM_VERSION, |
| 125 | S_CRTM_CONTENTS, |
| 126 | POST_CONTENTS, |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 127 | HOST_TABLE_OF_DEVICES, |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | static const char* tcpa_pc_event_id_strings[] = { |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 131 | "", |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 132 | "SMBIOS", |
| 133 | "BIS Certificate", |
| 134 | "POST BIOS ", |
| 135 | "ESCD ", |
| 136 | "CMOS", |
| 137 | "NVRAM", |
| 138 | "Option ROM", |
| 139 | "Option ROM config", |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 140 | "", |
| 141 | "Option ROM microcode ", |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 142 | "S-CRTM Version", |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 143 | "S-CRTM Contents ", |
| 144 | "POST Contents ", |
| 145 | "Table of Devices", |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 148 | /* returns pointer to start of pos. entry of tcg log */ |
| 149 | static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos) |
| 150 | { |
| 151 | loff_t i; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 152 | struct tpm_bios_log *log = m->private; |
| 153 | void *addr = log->bios_event_log; |
| 154 | void *limit = log->bios_event_log_end; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 155 | struct tcpa_event *event; |
| 156 | |
| 157 | /* read over *pos measurements */ |
| 158 | for (i = 0; i < *pos; i++) { |
| 159 | event = addr; |
| 160 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 161 | if ((addr + sizeof(struct tcpa_event)) < limit) { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 162 | if (event->event_type == 0 && event->event_size == 0) |
| 163 | return NULL; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 164 | addr += sizeof(struct tcpa_event) + event->event_size; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
| 168 | /* now check if current entry is valid */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 169 | if ((addr + sizeof(struct tcpa_event)) >= limit) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 170 | return NULL; |
| 171 | |
| 172 | event = addr; |
| 173 | |
| 174 | if ((event->event_type == 0 && event->event_size == 0) || |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 175 | ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 176 | return NULL; |
| 177 | |
| 178 | return addr; |
| 179 | } |
| 180 | |
| 181 | static void *tpm_bios_measurements_next(struct seq_file *m, void *v, |
| 182 | loff_t *pos) |
| 183 | { |
| 184 | struct tcpa_event *event = v; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 185 | struct tpm_bios_log *log = m->private; |
| 186 | void *limit = log->bios_event_log_end; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 187 | |
| 188 | v += sizeof(struct tcpa_event) + event->event_size; |
| 189 | |
| 190 | /* now check if current entry is valid */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 191 | if ((v + sizeof(struct tcpa_event)) >= limit) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 192 | return NULL; |
| 193 | |
| 194 | event = v; |
| 195 | |
| 196 | if (event->event_type == 0 && event->event_size == 0) |
| 197 | return NULL; |
| 198 | |
| 199 | if ((event->event_type == 0 && event->event_size == 0) || |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 200 | ((v + sizeof(struct tcpa_event) + event->event_size) >= limit)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 201 | return NULL; |
| 202 | |
| 203 | (*pos)++; |
| 204 | return v; |
| 205 | } |
| 206 | |
| 207 | static void tpm_bios_measurements_stop(struct seq_file *m, void *v) |
| 208 | { |
| 209 | } |
| 210 | |
| 211 | static int get_event_name(char *dest, struct tcpa_event *event, |
| 212 | unsigned char * event_entry) |
| 213 | { |
| 214 | const char *name = ""; |
Eric Paris | fbaa586 | 2009-05-13 12:50:40 -0400 | [diff] [blame] | 215 | /* 41 so there is room for 40 data and 1 nul */ |
| 216 | char data[41] = ""; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 217 | int i, n_len = 0, d_len = 0; |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 218 | struct tcpa_pc_event *pc_event; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 219 | |
| 220 | switch(event->event_type) { |
| 221 | case PREBOOT: |
| 222 | case POST_CODE: |
| 223 | case UNUSED: |
| 224 | case NO_ACTION: |
| 225 | case SCRTM_CONTENTS: |
| 226 | case SCRTM_VERSION: |
| 227 | case CPU_MICROCODE: |
| 228 | case PLATFORM_CONFIG_FLAGS: |
| 229 | case TABLE_OF_DEVICES: |
| 230 | case COMPACT_HASH: |
| 231 | case IPL: |
| 232 | case IPL_PARTITION_DATA: |
| 233 | case NONHOST_CODE: |
| 234 | case NONHOST_CONFIG: |
| 235 | case NONHOST_INFO: |
| 236 | name = tcpa_event_type_strings[event->event_type]; |
| 237 | n_len = strlen(name); |
| 238 | break; |
| 239 | case SEPARATOR: |
| 240 | case ACTION: |
| 241 | if (MAX_TEXT_EVENT > event->event_size) { |
| 242 | name = event_entry; |
| 243 | n_len = event->event_size; |
| 244 | } |
| 245 | break; |
| 246 | case EVENT_TAG: |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 247 | pc_event = (struct tcpa_pc_event *)event_entry; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 248 | |
| 249 | /* ToDo Row data -> Base64 */ |
| 250 | |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 251 | switch (pc_event->event_id) { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 252 | case SMBIOS: |
| 253 | case BIS_CERT: |
| 254 | case CMOS: |
| 255 | case NVRAM: |
| 256 | case OPTION_ROM_EXEC: |
| 257 | case OPTION_ROM_CONFIG: |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 258 | case S_CRTM_VERSION: |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 259 | name = tcpa_pc_event_id_strings[pc_event->event_id]; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 260 | n_len = strlen(name); |
| 261 | break; |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 262 | /* hash data */ |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 263 | case POST_BIOS_ROM: |
| 264 | case ESCD: |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 265 | case OPTION_ROM_MICROCODE: |
| 266 | case S_CRTM_CONTENTS: |
| 267 | case POST_CONTENTS: |
| 268 | name = tcpa_pc_event_id_strings[pc_event->event_id]; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 269 | n_len = strlen(name); |
| 270 | for (i = 0; i < 20; i++) |
Seiji Munetoh | de66a69 | 2006-05-30 21:25:47 -0700 | [diff] [blame] | 271 | d_len += sprintf(&data[2*i], "%02x", |
| 272 | pc_event->event_data[i]); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 273 | break; |
| 274 | default: |
| 275 | break; |
| 276 | } |
| 277 | default: |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | return snprintf(dest, MAX_TEXT_EVENT, "[%.*s%.*s]", |
| 282 | n_len, name, d_len, data); |
| 283 | |
| 284 | } |
| 285 | |
| 286 | static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v) |
| 287 | { |
Seiji Munetoh | 44d7aff | 2006-05-30 21:25:52 -0700 | [diff] [blame] | 288 | struct tcpa_event *event = v; |
| 289 | char *data = v; |
| 290 | int i; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 291 | |
Seiji Munetoh | 44d7aff | 2006-05-30 21:25:52 -0700 | [diff] [blame] | 292 | for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 293 | seq_putc(m, data[i]); |
| 294 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static int tpm_bios_measurements_release(struct inode *inode, |
| 299 | struct file *file) |
| 300 | { |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 301 | struct seq_file *seq = file->private_data; |
| 302 | struct tpm_bios_log *log = seq->private; |
| 303 | |
| 304 | if (log) { |
| 305 | kfree(log->bios_event_log); |
| 306 | kfree(log); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 307 | } |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 308 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 309 | return seq_release(inode, file); |
| 310 | } |
| 311 | |
| 312 | static int tpm_ascii_bios_measurements_show(struct seq_file *m, void *v) |
| 313 | { |
| 314 | int len = 0; |
| 315 | int i; |
| 316 | char *eventname; |
| 317 | struct tcpa_event *event = v; |
| 318 | unsigned char *event_entry = |
| 319 | (unsigned char *) (v + sizeof(struct tcpa_event)); |
| 320 | |
| 321 | eventname = kmalloc(MAX_TEXT_EVENT, GFP_KERNEL); |
| 322 | if (!eventname) { |
| 323 | printk(KERN_ERR "%s: ERROR - No Memory for event name\n ", |
| 324 | __func__); |
| 325 | return -EFAULT; |
| 326 | } |
| 327 | |
| 328 | seq_printf(m, "%2d ", event->pcr_index); |
| 329 | |
| 330 | /* 2nd: SHA1 */ |
| 331 | for (i = 0; i < 20; i++) |
| 332 | seq_printf(m, "%02x", event->pcr_value[i]); |
| 333 | |
| 334 | /* 3rd: event type identifier */ |
| 335 | seq_printf(m, " %02x", event->event_type); |
| 336 | |
| 337 | len += get_event_name(eventname, event, event_entry); |
| 338 | |
| 339 | /* 4th: eventname <= max + \'0' delimiter */ |
| 340 | seq_printf(m, " %s\n", eventname); |
| 341 | |
Kylene Jo Hall | 59e89f3 | 2006-04-22 02:36:35 -0700 | [diff] [blame] | 342 | kfree(eventname); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 343 | return 0; |
| 344 | } |
| 345 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 346 | static const struct seq_operations tpm_ascii_b_measurments_seqops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 347 | .start = tpm_bios_measurements_start, |
| 348 | .next = tpm_bios_measurements_next, |
| 349 | .stop = tpm_bios_measurements_stop, |
| 350 | .show = tpm_ascii_bios_measurements_show, |
| 351 | }; |
| 352 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 353 | static const struct seq_operations tpm_binary_b_measurments_seqops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 354 | .start = tpm_bios_measurements_start, |
| 355 | .next = tpm_bios_measurements_next, |
| 356 | .stop = tpm_bios_measurements_stop, |
| 357 | .show = tpm_binary_bios_measurements_show, |
| 358 | }; |
| 359 | |
| 360 | /* read binary bios log */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 361 | static int read_log(struct tpm_bios_log *log) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 362 | { |
| 363 | struct acpi_tcpa *buff; |
| 364 | acpi_status status; |
Kylene Jo Hall | 10296cb | 2006-02-01 03:05:04 -0800 | [diff] [blame] | 365 | struct acpi_table_header *virt; |
Kylene Jo Hall | 8b006db | 2006-04-22 02:39:07 -0700 | [diff] [blame] | 366 | u64 len, start; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 367 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 368 | if (log->bios_event_log != NULL) { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 369 | printk(KERN_ERR |
| 370 | "%s: ERROR - Eventlog already initialized\n", |
| 371 | __func__); |
| 372 | return -EFAULT; |
| 373 | } |
| 374 | |
| 375 | /* Find TCPA entry in RSDT (ACPI_LOGICAL_ADDRESSING) */ |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 376 | status = acpi_get_table(ACPI_SIG_TCPA, 1, |
| 377 | (struct acpi_table_header **)&buff); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 378 | |
| 379 | if (ACPI_FAILURE(status)) { |
| 380 | printk(KERN_ERR "%s: ERROR - Could not get TCPA table\n", |
| 381 | __func__); |
| 382 | return -EIO; |
| 383 | } |
| 384 | |
Kylene Jo Hall | 8b006db | 2006-04-22 02:39:07 -0700 | [diff] [blame] | 385 | switch(buff->platform_class) { |
| 386 | case BIOS_SERVER: |
| 387 | len = buff->server.log_max_len; |
| 388 | start = buff->server.log_start_addr; |
| 389 | break; |
| 390 | case BIOS_CLIENT: |
| 391 | default: |
| 392 | len = buff->client.log_max_len; |
| 393 | start = buff->client.log_start_addr; |
| 394 | break; |
| 395 | } |
| 396 | if (!len) { |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 397 | printk(KERN_ERR "%s: ERROR - TCPA log area empty\n", __func__); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 398 | return -EIO; |
| 399 | } |
| 400 | |
| 401 | /* malloc EventLog space */ |
Kylene Jo Hall | 8b006db | 2006-04-22 02:39:07 -0700 | [diff] [blame] | 402 | log->bios_event_log = kmalloc(len, GFP_KERNEL); |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 403 | if (!log->bios_event_log) { |
Kylene Jo Hall | 8b006db | 2006-04-22 02:39:07 -0700 | [diff] [blame] | 404 | printk("%s: ERROR - Not enough Memory for BIOS measurements\n", |
| 405 | __func__); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 406 | return -ENOMEM; |
| 407 | } |
| 408 | |
Kylene Jo Hall | 8b006db | 2006-04-22 02:39:07 -0700 | [diff] [blame] | 409 | log->bios_event_log_end = log->bios_event_log + len; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 410 | |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 411 | virt = acpi_os_map_memory(start, len); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 412 | |
Kylene Jo Hall | 8b006db | 2006-04-22 02:39:07 -0700 | [diff] [blame] | 413 | memcpy(log->bios_event_log, virt, len); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 414 | |
Kylene Jo Hall | 8b006db | 2006-04-22 02:39:07 -0700 | [diff] [blame] | 415 | acpi_os_unmap_memory(virt, len); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | static int tpm_ascii_bios_measurements_open(struct inode *inode, |
| 420 | struct file *file) |
| 421 | { |
| 422 | int err; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 423 | struct tpm_bios_log *log; |
| 424 | struct seq_file *seq; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 425 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 426 | log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL); |
| 427 | if (!log) |
| 428 | return -ENOMEM; |
| 429 | |
| 430 | if ((err = read_log(log))) |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 431 | goto out_free; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 432 | |
| 433 | /* now register seq file */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 434 | err = seq_open(file, &tpm_ascii_b_measurments_seqops); |
| 435 | if (!err) { |
| 436 | seq = file->private_data; |
| 437 | seq->private = log; |
| 438 | } else { |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 439 | goto out_free; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 440 | } |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 441 | |
| 442 | out: |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 443 | return err; |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 444 | out_free: |
| 445 | kfree(log->bios_event_log); |
| 446 | kfree(log); |
| 447 | goto out; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Adrian Bunk | 3bd6046 | 2008-07-25 19:44:58 -0700 | [diff] [blame] | 450 | static const struct file_operations tpm_ascii_bios_measurements_ops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 451 | .open = tpm_ascii_bios_measurements_open, |
| 452 | .read = seq_read, |
| 453 | .llseek = seq_lseek, |
| 454 | .release = tpm_bios_measurements_release, |
| 455 | }; |
| 456 | |
| 457 | static int tpm_binary_bios_measurements_open(struct inode *inode, |
| 458 | struct file *file) |
| 459 | { |
| 460 | int err; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 461 | struct tpm_bios_log *log; |
| 462 | struct seq_file *seq; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 463 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 464 | log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL); |
| 465 | if (!log) |
| 466 | return -ENOMEM; |
| 467 | |
| 468 | if ((err = read_log(log))) |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 469 | goto out_free; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 470 | |
| 471 | /* now register seq file */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 472 | err = seq_open(file, &tpm_binary_b_measurments_seqops); |
| 473 | if (!err) { |
| 474 | seq = file->private_data; |
| 475 | seq->private = log; |
| 476 | } else { |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 477 | goto out_free; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 478 | } |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 479 | |
| 480 | out: |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 481 | return err; |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 482 | out_free: |
| 483 | kfree(log->bios_event_log); |
| 484 | kfree(log); |
| 485 | goto out; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 486 | } |
| 487 | |
Adrian Bunk | 3bd6046 | 2008-07-25 19:44:58 -0700 | [diff] [blame] | 488 | static const struct file_operations tpm_binary_bios_measurements_ops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 489 | .open = tpm_binary_bios_measurements_open, |
| 490 | .read = seq_read, |
| 491 | .llseek = seq_lseek, |
| 492 | .release = tpm_bios_measurements_release, |
| 493 | }; |
| 494 | |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 495 | static int is_bad(void *p) |
| 496 | { |
| 497 | if (!p) |
| 498 | return 1; |
| 499 | if (IS_ERR(p) && (PTR_ERR(p) != -ENODEV)) |
| 500 | return 1; |
| 501 | return 0; |
| 502 | } |
| 503 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 504 | struct dentry **tpm_bios_log_setup(char *name) |
| 505 | { |
| 506 | struct dentry **ret = NULL, *tpm_dir, *bin_file, *ascii_file; |
| 507 | |
| 508 | tpm_dir = securityfs_create_dir(name, NULL); |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 509 | if (is_bad(tpm_dir)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 510 | goto out; |
| 511 | |
| 512 | bin_file = |
| 513 | securityfs_create_file("binary_bios_measurements", |
| 514 | S_IRUSR | S_IRGRP, tpm_dir, NULL, |
| 515 | &tpm_binary_bios_measurements_ops); |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 516 | if (is_bad(bin_file)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 517 | goto out_tpm; |
| 518 | |
| 519 | ascii_file = |
| 520 | securityfs_create_file("ascii_bios_measurements", |
| 521 | S_IRUSR | S_IRGRP, tpm_dir, NULL, |
| 522 | &tpm_ascii_bios_measurements_ops); |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 523 | if (is_bad(ascii_file)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 524 | goto out_bin; |
| 525 | |
| 526 | ret = kmalloc(3 * sizeof(struct dentry *), GFP_KERNEL); |
| 527 | if (!ret) |
| 528 | goto out_ascii; |
| 529 | |
| 530 | ret[0] = ascii_file; |
| 531 | ret[1] = bin_file; |
| 532 | ret[2] = tpm_dir; |
| 533 | |
| 534 | return ret; |
| 535 | |
| 536 | out_ascii: |
| 537 | securityfs_remove(ascii_file); |
| 538 | out_bin: |
| 539 | securityfs_remove(bin_file); |
| 540 | out_tpm: |
| 541 | securityfs_remove(tpm_dir); |
| 542 | out: |
| 543 | return NULL; |
| 544 | } |
| 545 | EXPORT_SYMBOL_GPL(tpm_bios_log_setup); |
| 546 | |
| 547 | void tpm_bios_log_teardown(struct dentry **lst) |
| 548 | { |
| 549 | int i; |
| 550 | |
| 551 | for (i = 0; i < 3; i++) |
| 552 | securityfs_remove(lst[i]); |
| 553 | } |
| 554 | EXPORT_SYMBOL_GPL(tpm_bios_log_teardown); |
Kylene Jo Hall | 7bcee5b | 2006-02-01 03:05:03 -0800 | [diff] [blame] | 555 | MODULE_LICENSE("GPL"); |