^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2005, 2012 IBM Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Kent Yoder <key@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Seiji Munetoh <munetoh@jp.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Stefan Berger <stefanb@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Reiner Sailer <sailer@watson.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Kylene Hall <kjhall@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Nayna Jain <nayna@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Maintained by: <tpmdd-devel@lists.sourceforge.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Access to the event log created by a system's firmware / BIOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/security.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/tpm_eventlog.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "../tpm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static const char* tcpa_event_type_strings[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) "PREBOOT",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) "POST CODE",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) "NO ACTION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) "SEPARATOR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) "ACTION",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) "EVENT TAG",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) "S-CRTM Contents",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) "S-CRTM Version",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) "CPU Microcode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) "Platform Config Flags",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) "Table of Devices",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) "Compact Hash",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) "IPL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) "IPL Partition Data",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) "Non-Host Code",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) "Non-Host Config",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) "Non-Host Info"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static const char* tcpa_pc_event_id_strings[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) "SMBIOS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) "BIS Certificate",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) "POST BIOS ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) "ESCD ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) "CMOS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) "NVRAM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) "Option ROM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) "Option ROM config",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) "Option ROM microcode ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) "S-CRTM Version",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) "S-CRTM Contents ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) "POST Contents ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) "Table of Devices",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* returns pointer to start of pos. entry of tcg log */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static void *tpm1_bios_measurements_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) loff_t i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct tpm_chip *chip = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct tpm_bios_log *log = &chip->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) void *addr = log->bios_event_log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) void *limit = log->bios_event_log_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct tcpa_event *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) u32 converted_event_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u32 converted_event_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* read over *pos measurements */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) event = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* check if current entry is valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (addr + sizeof(struct tcpa_event) > limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) converted_event_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) do_endian_conversion(event->event_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) converted_event_type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) do_endian_conversion(event->event_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (((converted_event_type == 0) && (converted_event_size == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) || ((addr + sizeof(struct tcpa_event) + converted_event_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) > limit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (i++ == *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) addr += (sizeof(struct tcpa_event) + converted_event_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) } while (1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static void *tpm1_bios_measurements_next(struct seq_file *m, void *v,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct tcpa_event *event = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct tpm_chip *chip = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct tpm_bios_log *log = &chip->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) void *limit = log->bios_event_log_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) u32 converted_event_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u32 converted_event_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) (*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) converted_event_size = do_endian_conversion(event->event_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) v += sizeof(struct tcpa_event) + converted_event_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* now check if current entry is valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if ((v + sizeof(struct tcpa_event)) > limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) event = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) converted_event_size = do_endian_conversion(event->event_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) converted_event_type = do_endian_conversion(event->event_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (((converted_event_type == 0) && (converted_event_size == 0)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) ((v + sizeof(struct tcpa_event) + converted_event_size) > limit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static void tpm1_bios_measurements_stop(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int get_event_name(char *dest, struct tcpa_event *event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsigned char * event_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) const char *name = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* 41 so there is room for 40 data and 1 nul */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) char data[41] = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int i, n_len = 0, d_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct tcpa_pc_event *pc_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) switch (do_endian_conversion(event->event_type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) case PREBOOT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) case POST_CODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) case UNUSED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) case NO_ACTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) case SCRTM_CONTENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) case SCRTM_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) case CPU_MICROCODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) case PLATFORM_CONFIG_FLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) case TABLE_OF_DEVICES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) case COMPACT_HASH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) case IPL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) case IPL_PARTITION_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) case NONHOST_CODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) case NONHOST_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) case NONHOST_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) name = tcpa_event_type_strings[do_endian_conversion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) (event->event_type)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) n_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) case SEPARATOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) case ACTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (MAX_TEXT_EVENT >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) do_endian_conversion(event->event_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) name = event_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) n_len = do_endian_conversion(event->event_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) case EVENT_TAG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) pc_event = (struct tcpa_pc_event *)event_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* ToDo Row data -> Base64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) switch (do_endian_conversion(pc_event->event_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) case SMBIOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case BIS_CERT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) case CMOS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) case NVRAM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) case OPTION_ROM_EXEC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) case OPTION_ROM_CONFIG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) case S_CRTM_VERSION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) name = tcpa_pc_event_id_strings[do_endian_conversion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) (pc_event->event_id)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) n_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /* hash data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) case POST_BIOS_ROM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) case ESCD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) case OPTION_ROM_MICROCODE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) case S_CRTM_CONTENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) case POST_CONTENTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) name = tcpa_pc_event_id_strings[do_endian_conversion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) (pc_event->event_id)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) n_len = strlen(name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) for (i = 0; i < 20; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) d_len += sprintf(&data[2*i], "%02x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pc_event->event_data[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return snprintf(dest, MAX_TEXT_EVENT, "[%.*s%.*s]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) n_len, name, d_len, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static int tpm1_binary_bios_measurements_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct tcpa_event *event = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct tcpa_event temp_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) char *temp_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) memcpy(&temp_event, event, sizeof(struct tcpa_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* convert raw integers for endianness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) temp_event.pcr_index = do_endian_conversion(event->pcr_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) temp_event.event_type = do_endian_conversion(event->event_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) temp_event.event_size = do_endian_conversion(event->event_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) temp_ptr = (char *) &temp_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) for (i = 0; i < (sizeof(struct tcpa_event) - 1) ; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) seq_putc(m, temp_ptr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) temp_ptr = (char *) v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) for (i = (sizeof(struct tcpa_event) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) i < (sizeof(struct tcpa_event) + temp_event.event_size); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) seq_putc(m, temp_ptr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int tpm1_ascii_bios_measurements_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) char *eventname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct tcpa_event *event = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) unsigned char *event_entry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) (unsigned char *)(v + sizeof(struct tcpa_event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) eventname = kmalloc(MAX_TEXT_EVENT, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (!eventname) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) printk(KERN_ERR "%s: ERROR - No Memory for event name\n ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* 1st: PCR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) seq_printf(m, "%2d ", do_endian_conversion(event->pcr_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /* 2nd: SHA1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) seq_printf(m, "%20phN", event->pcr_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /* 3rd: event type identifier */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) seq_printf(m, " %02x", do_endian_conversion(event->event_type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) len += get_event_name(eventname, event, event_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /* 4th: eventname <= max + \'0' delimiter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) seq_printf(m, " %s\n", eventname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) kfree(eventname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) const struct seq_operations tpm1_ascii_b_measurements_seqops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) .start = tpm1_bios_measurements_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) .next = tpm1_bios_measurements_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .stop = tpm1_bios_measurements_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .show = tpm1_ascii_bios_measurements_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) const struct seq_operations tpm1_binary_b_measurements_seqops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .start = tpm1_bios_measurements_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .next = tpm1_bios_measurements_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .stop = tpm1_bios_measurements_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .show = tpm1_binary_bios_measurements_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) };