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; |
Harald Hoyer | 186d124 | 2016-02-06 15:44:42 +0100 | [diff] [blame] | 235 | char *temp_ptr; |
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 | |
Harald Hoyer | 186d124 | 2016-02-06 15:44:42 +0100 | [diff] [blame] | 245 | temp_ptr = (char *) &temp_event; |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 246 | |
Harald Hoyer | 186d124 | 2016-02-06 15:44:42 +0100 | [diff] [blame] | 247 | for (i = 0; i < (sizeof(struct tcpa_event) - 1) ; i++) |
| 248 | seq_putc(m, temp_ptr[i]); |
| 249 | |
| 250 | temp_ptr = (char *) v; |
| 251 | |
| 252 | for (i = (sizeof(struct tcpa_event) - 1); |
| 253 | i < (sizeof(struct tcpa_event) + temp_event.event_size); i++) |
| 254 | seq_putc(m, temp_ptr[i]); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 255 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 256 | return 0; |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 257 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static int tpm_bios_measurements_release(struct inode *inode, |
| 261 | struct file *file) |
| 262 | { |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 263 | struct seq_file *seq = file->private_data; |
| 264 | struct tpm_bios_log *log = seq->private; |
| 265 | |
| 266 | if (log) { |
| 267 | kfree(log->bios_event_log); |
| 268 | kfree(log); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 269 | } |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 270 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 271 | return seq_release(inode, file); |
| 272 | } |
| 273 | |
| 274 | static int tpm_ascii_bios_measurements_show(struct seq_file *m, void *v) |
| 275 | { |
| 276 | int len = 0; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 277 | char *eventname; |
| 278 | struct tcpa_event *event = v; |
| 279 | unsigned char *event_entry = |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 280 | (unsigned char *)(v + sizeof(struct tcpa_event)); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 281 | |
| 282 | eventname = kmalloc(MAX_TEXT_EVENT, GFP_KERNEL); |
| 283 | if (!eventname) { |
| 284 | printk(KERN_ERR "%s: ERROR - No Memory for event name\n ", |
| 285 | __func__); |
| 286 | return -EFAULT; |
| 287 | } |
| 288 | |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 289 | /* 1st: PCR */ |
| 290 | seq_printf(m, "%2d ", do_endian_conversion(event->pcr_index)); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 291 | |
| 292 | /* 2nd: SHA1 */ |
Andy Shevchenko | a3d64df | 2014-07-09 15:34:41 +0300 | [diff] [blame] | 293 | seq_printf(m, "%20phN", event->pcr_value); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 294 | |
| 295 | /* 3rd: event type identifier */ |
Hon Ching \(Vicky\) Lo | 0cc698a | 2015-06-17 18:17:08 -0400 | [diff] [blame] | 296 | seq_printf(m, " %02x", do_endian_conversion(event->event_type)); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 297 | |
| 298 | len += get_event_name(eventname, event, event_entry); |
| 299 | |
| 300 | /* 4th: eventname <= max + \'0' delimiter */ |
| 301 | seq_printf(m, " %s\n", eventname); |
| 302 | |
Kylene Jo Hall | 59e89f3 | 2006-04-22 02:36:35 -0700 | [diff] [blame] | 303 | kfree(eventname); |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 307 | static const struct seq_operations tpm_ascii_b_measurments_seqops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 308 | .start = tpm_bios_measurements_start, |
| 309 | .next = tpm_bios_measurements_next, |
| 310 | .stop = tpm_bios_measurements_stop, |
| 311 | .show = tpm_ascii_bios_measurements_show, |
| 312 | }; |
| 313 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 314 | static const struct seq_operations tpm_binary_b_measurments_seqops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 315 | .start = tpm_bios_measurements_start, |
| 316 | .next = tpm_bios_measurements_next, |
| 317 | .stop = tpm_bios_measurements_stop, |
| 318 | .show = tpm_binary_bios_measurements_show, |
| 319 | }; |
| 320 | |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 321 | static int tpm_ascii_bios_measurements_open(struct inode *inode, |
| 322 | struct file *file) |
| 323 | { |
| 324 | int err; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 325 | struct tpm_bios_log *log; |
| 326 | struct seq_file *seq; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 327 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 328 | log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL); |
| 329 | if (!log) |
| 330 | return -ENOMEM; |
| 331 | |
| 332 | if ((err = read_log(log))) |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 333 | goto out_free; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 334 | |
| 335 | /* now register seq file */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 336 | err = seq_open(file, &tpm_ascii_b_measurments_seqops); |
| 337 | if (!err) { |
| 338 | seq = file->private_data; |
| 339 | seq->private = log; |
| 340 | } else { |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 341 | goto out_free; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 342 | } |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 343 | |
| 344 | out: |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 345 | return err; |
Jesper Juhl | 178554a | 2007-07-20 00:31:48 -0700 | [diff] [blame] | 346 | out_free: |
| 347 | kfree(log->bios_event_log); |
| 348 | kfree(log); |
| 349 | goto out; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Adrian Bunk | 3bd6046 | 2008-07-25 19:44:58 -0700 | [diff] [blame] | 352 | static const struct file_operations tpm_ascii_bios_measurements_ops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 353 | .open = tpm_ascii_bios_measurements_open, |
| 354 | .read = seq_read, |
| 355 | .llseek = seq_lseek, |
| 356 | .release = tpm_bios_measurements_release, |
| 357 | }; |
| 358 | |
| 359 | static int tpm_binary_bios_measurements_open(struct inode *inode, |
| 360 | struct file *file) |
| 361 | { |
| 362 | int err; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 363 | struct tpm_bios_log *log; |
| 364 | struct seq_file *seq; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 365 | |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 366 | log = kzalloc(sizeof(struct tpm_bios_log), GFP_KERNEL); |
| 367 | if (!log) |
| 368 | return -ENOMEM; |
| 369 | |
| 370 | if ((err = read_log(log))) |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 371 | goto out_free; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 372 | |
| 373 | /* now register seq file */ |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 374 | err = seq_open(file, &tpm_binary_b_measurments_seqops); |
| 375 | if (!err) { |
| 376 | seq = file->private_data; |
| 377 | seq->private = log; |
| 378 | } else { |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 379 | goto out_free; |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 380 | } |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 381 | |
| 382 | out: |
Kylene Jo Hall | d09cf7d | 2006-01-08 01:03:48 -0800 | [diff] [blame] | 383 | return err; |
Reiner Sailer | 03ce110 | 2007-07-20 10:03:02 -0400 | [diff] [blame] | 384 | out_free: |
| 385 | kfree(log->bios_event_log); |
| 386 | kfree(log); |
| 387 | goto out; |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Adrian Bunk | 3bd6046 | 2008-07-25 19:44:58 -0700 | [diff] [blame] | 390 | static const struct file_operations tpm_binary_bios_measurements_ops = { |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 391 | .open = tpm_binary_bios_measurements_open, |
| 392 | .read = seq_read, |
| 393 | .llseek = seq_lseek, |
| 394 | .release = tpm_bios_measurements_release, |
| 395 | }; |
| 396 | |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 397 | static int is_bad(void *p) |
| 398 | { |
| 399 | if (!p) |
| 400 | return 1; |
| 401 | if (IS_ERR(p) && (PTR_ERR(p) != -ENODEV)) |
| 402 | return 1; |
| 403 | return 0; |
| 404 | } |
| 405 | |
Jason Gunthorpe | 3635e2e | 2016-02-29 12:29:48 -0500 | [diff] [blame] | 406 | struct dentry **tpm_bios_log_setup(const char *name) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 407 | { |
| 408 | struct dentry **ret = NULL, *tpm_dir, *bin_file, *ascii_file; |
| 409 | |
| 410 | tpm_dir = securityfs_create_dir(name, NULL); |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 411 | if (is_bad(tpm_dir)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 412 | goto out; |
| 413 | |
| 414 | bin_file = |
| 415 | securityfs_create_file("binary_bios_measurements", |
| 416 | S_IRUSR | S_IRGRP, tpm_dir, NULL, |
| 417 | &tpm_binary_bios_measurements_ops); |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 418 | if (is_bad(bin_file)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 419 | goto out_tpm; |
| 420 | |
| 421 | ascii_file = |
| 422 | securityfs_create_file("ascii_bios_measurements", |
| 423 | S_IRUSR | S_IRGRP, tpm_dir, NULL, |
| 424 | &tpm_ascii_bios_measurements_ops); |
Andrew Morton | ca4a031f | 2006-02-01 03:05:01 -0800 | [diff] [blame] | 425 | if (is_bad(ascii_file)) |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 426 | goto out_bin; |
| 427 | |
| 428 | ret = kmalloc(3 * sizeof(struct dentry *), GFP_KERNEL); |
| 429 | if (!ret) |
| 430 | goto out_ascii; |
| 431 | |
| 432 | ret[0] = ascii_file; |
| 433 | ret[1] = bin_file; |
| 434 | ret[2] = tpm_dir; |
| 435 | |
| 436 | return ret; |
| 437 | |
| 438 | out_ascii: |
| 439 | securityfs_remove(ascii_file); |
| 440 | out_bin: |
| 441 | securityfs_remove(bin_file); |
| 442 | out_tpm: |
| 443 | securityfs_remove(tpm_dir); |
| 444 | out: |
| 445 | return NULL; |
| 446 | } |
Kylene Jo Hall | 55a82ab | 2006-01-08 01:03:15 -0800 | [diff] [blame] | 447 | |
| 448 | void tpm_bios_log_teardown(struct dentry **lst) |
| 449 | { |
| 450 | int i; |
| 451 | |
| 452 | for (i = 0; i < 3; i++) |
| 453 | securityfs_remove(lst[i]); |
| 454 | } |