| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2016 IBM Corporation |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 9 | 10 | * for Family "2.0" and written the event data in little endian. |
|---|
| 10 | 11 | * With that, it doesn't need any endian conversion for structure |
|---|
| 11 | 12 | * content. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is free software; you can redistribute it and/or |
|---|
| 14 | | - * modify it under the terms of the GNU General Public License |
|---|
| 15 | | - * as published by the Free Software Foundation; either version |
|---|
| 16 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 17 | 13 | */ |
|---|
| 18 | 14 | |
|---|
| 19 | 15 | #include <linux/seq_file.h> |
|---|
| .. | .. |
|---|
| 37 | 33 | * |
|---|
| 38 | 34 | * Returns size of the event. If it is an invalid event, returns 0. |
|---|
| 39 | 35 | */ |
|---|
| 40 | | -static size_t calc_tpm2_event_size(struct tcg_pcr_event2 *event, |
|---|
| 36 | +static size_t calc_tpm2_event_size(struct tcg_pcr_event2_head *event, |
|---|
| 41 | 37 | struct tcg_pcr_event *event_header) |
|---|
| 42 | 38 | { |
|---|
| 43 | | - struct tcg_efi_specid_event *efispecid; |
|---|
| 44 | | - struct tcg_event_field *event_field; |
|---|
| 45 | | - void *marker; |
|---|
| 46 | | - void *marker_start; |
|---|
| 47 | | - u32 halg_size; |
|---|
| 48 | | - size_t size; |
|---|
| 49 | | - u16 halg; |
|---|
| 50 | | - int i; |
|---|
| 51 | | - int j; |
|---|
| 52 | | - |
|---|
| 53 | | - marker = event; |
|---|
| 54 | | - marker_start = marker; |
|---|
| 55 | | - marker = marker + sizeof(event->pcr_idx) + sizeof(event->event_type) |
|---|
| 56 | | - + sizeof(event->count); |
|---|
| 57 | | - |
|---|
| 58 | | - efispecid = (struct tcg_efi_specid_event *)event_header->event; |
|---|
| 59 | | - |
|---|
| 60 | | - /* Check if event is malformed. */ |
|---|
| 61 | | - if (event->count > efispecid->num_algs) |
|---|
| 62 | | - return 0; |
|---|
| 63 | | - |
|---|
| 64 | | - for (i = 0; i < event->count; i++) { |
|---|
| 65 | | - halg_size = sizeof(event->digests[i].alg_id); |
|---|
| 66 | | - memcpy(&halg, marker, halg_size); |
|---|
| 67 | | - marker = marker + halg_size; |
|---|
| 68 | | - for (j = 0; j < efispecid->num_algs; j++) { |
|---|
| 69 | | - if (halg == efispecid->digest_sizes[j].alg_id) { |
|---|
| 70 | | - marker += |
|---|
| 71 | | - efispecid->digest_sizes[j].digest_size; |
|---|
| 72 | | - break; |
|---|
| 73 | | - } |
|---|
| 74 | | - } |
|---|
| 75 | | - /* Algorithm without known length. Such event is unparseable. */ |
|---|
| 76 | | - if (j == efispecid->num_algs) |
|---|
| 77 | | - return 0; |
|---|
| 78 | | - } |
|---|
| 79 | | - |
|---|
| 80 | | - event_field = (struct tcg_event_field *)marker; |
|---|
| 81 | | - marker = marker + sizeof(event_field->event_size) |
|---|
| 82 | | - + event_field->event_size; |
|---|
| 83 | | - size = marker - marker_start; |
|---|
| 84 | | - |
|---|
| 85 | | - if ((event->event_type == 0) && (event_field->event_size == 0)) |
|---|
| 86 | | - return 0; |
|---|
| 87 | | - |
|---|
| 88 | | - return size; |
|---|
| 39 | + return __calc_tpm2_event_size(event, event_header, false); |
|---|
| 89 | 40 | } |
|---|
| 90 | 41 | |
|---|
| 91 | 42 | static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos) |
|---|
| .. | .. |
|---|
| 95 | 46 | void *addr = log->bios_event_log; |
|---|
| 96 | 47 | void *limit = log->bios_event_log_end; |
|---|
| 97 | 48 | struct tcg_pcr_event *event_header; |
|---|
| 98 | | - struct tcg_pcr_event2 *event; |
|---|
| 49 | + struct tcg_pcr_event2_head *event; |
|---|
| 99 | 50 | size_t size; |
|---|
| 100 | 51 | int i; |
|---|
| 101 | 52 | |
|---|
| 102 | 53 | event_header = addr; |
|---|
| 103 | | - size = sizeof(struct tcg_pcr_event) - sizeof(event_header->event) |
|---|
| 104 | | - + event_header->event_size; |
|---|
| 54 | + size = struct_size(event_header, event, event_header->event_size); |
|---|
| 105 | 55 | |
|---|
| 106 | 56 | if (*pos == 0) { |
|---|
| 107 | 57 | if (addr + size < limit) { |
|---|
| .. | .. |
|---|
| 136 | 86 | loff_t *pos) |
|---|
| 137 | 87 | { |
|---|
| 138 | 88 | struct tcg_pcr_event *event_header; |
|---|
| 139 | | - struct tcg_pcr_event2 *event; |
|---|
| 89 | + struct tcg_pcr_event2_head *event; |
|---|
| 140 | 90 | struct tpm_chip *chip = m->private; |
|---|
| 141 | 91 | struct tpm_bios_log *log = &chip->log; |
|---|
| 142 | 92 | void *limit = log->bios_event_log_end; |
|---|
| .. | .. |
|---|
| 147 | 97 | event_header = log->bios_event_log; |
|---|
| 148 | 98 | |
|---|
| 149 | 99 | if (v == SEQ_START_TOKEN) { |
|---|
| 150 | | - event_size = sizeof(struct tcg_pcr_event) - |
|---|
| 151 | | - sizeof(event_header->event) + event_header->event_size; |
|---|
| 100 | + event_size = struct_size(event_header, event, |
|---|
| 101 | + event_header->event_size); |
|---|
| 152 | 102 | marker = event_header; |
|---|
| 153 | 103 | } else { |
|---|
| 154 | 104 | event = v; |
|---|
| .. | .. |
|---|
| 180 | 130 | struct tpm_chip *chip = m->private; |
|---|
| 181 | 131 | struct tpm_bios_log *log = &chip->log; |
|---|
| 182 | 132 | struct tcg_pcr_event *event_header = log->bios_event_log; |
|---|
| 183 | | - struct tcg_pcr_event2 *event = v; |
|---|
| 133 | + struct tcg_pcr_event2_head *event = v; |
|---|
| 184 | 134 | void *temp_ptr; |
|---|
| 185 | 135 | size_t size; |
|---|
| 186 | 136 | |
|---|
| 187 | 137 | if (v == SEQ_START_TOKEN) { |
|---|
| 188 | | - size = sizeof(struct tcg_pcr_event) - |
|---|
| 189 | | - sizeof(event_header->event) + event_header->event_size; |
|---|
| 190 | | - |
|---|
| 138 | + size = struct_size(event_header, event, |
|---|
| 139 | + event_header->event_size); |
|---|
| 191 | 140 | temp_ptr = event_header; |
|---|
| 192 | 141 | |
|---|
| 193 | 142 | if (size > 0) |
|---|