hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/char/tpm/eventlog/tpm2.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2016 IBM Corporation
34 *
....@@ -9,11 +10,6 @@
910 * for Family "2.0" and written the event data in little endian.
1011 * With that, it doesn't need any endian conversion for structure
1112 * 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.
1713 */
1814
1915 #include <linux/seq_file.h>
....@@ -37,55 +33,10 @@
3733 *
3834 * Returns size of the event. If it is an invalid event, returns 0.
3935 */
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,
4137 struct tcg_pcr_event *event_header)
4238 {
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);
8940 }
9041
9142 static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos)
....@@ -95,13 +46,12 @@
9546 void *addr = log->bios_event_log;
9647 void *limit = log->bios_event_log_end;
9748 struct tcg_pcr_event *event_header;
98
- struct tcg_pcr_event2 *event;
49
+ struct tcg_pcr_event2_head *event;
9950 size_t size;
10051 int i;
10152
10253 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);
10555
10656 if (*pos == 0) {
10757 if (addr + size < limit) {
....@@ -136,7 +86,7 @@
13686 loff_t *pos)
13787 {
13888 struct tcg_pcr_event *event_header;
139
- struct tcg_pcr_event2 *event;
89
+ struct tcg_pcr_event2_head *event;
14090 struct tpm_chip *chip = m->private;
14191 struct tpm_bios_log *log = &chip->log;
14292 void *limit = log->bios_event_log_end;
....@@ -147,8 +97,8 @@
14797 event_header = log->bios_event_log;
14898
14999 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);
152102 marker = event_header;
153103 } else {
154104 event = v;
....@@ -180,14 +130,13 @@
180130 struct tpm_chip *chip = m->private;
181131 struct tpm_bios_log *log = &chip->log;
182132 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;
184134 void *temp_ptr;
185135 size_t size;
186136
187137 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);
191140 temp_ptr = event_header;
192141
193142 if (size > 0)