hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/char/tpm/eventlog/tpm1.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2005, 2012 IBM Corporation
34 *
....@@ -12,12 +13,6 @@
1213 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
1314 *
1415 * Access to the event log created by a system's firmware / BIOS
15
- *
16
- * This program is free software; you can redistribute it and/or
17
- * modify it under the terms of the GNU General Public License
18
- * as published by the Free Software Foundation; either version
19
- * 2 of the License, or (at your option) any later version.
20
- *
2116 */
2217
2318 #include <linux/seq_file.h>
....@@ -74,7 +69,7 @@
7469 /* returns pointer to start of pos. entry of tcg log */
7570 static void *tpm1_bios_measurements_start(struct seq_file *m, loff_t *pos)
7671 {
77
- loff_t i;
72
+ loff_t i = 0;
7873 struct tpm_chip *chip = m->private;
7974 struct tpm_bios_log *log = &chip->log;
8075 void *addr = log->bios_event_log;
....@@ -83,38 +78,29 @@
8378 u32 converted_event_size;
8479 u32 converted_event_type;
8580
86
-
8781 /* read over *pos measurements */
88
- for (i = 0; i < *pos; i++) {
82
+ do {
8983 event = addr;
84
+
85
+ /* check if current entry is valid */
86
+ if (addr + sizeof(struct tcpa_event) > limit)
87
+ return NULL;
9088
9189 converted_event_size =
9290 do_endian_conversion(event->event_size);
9391 converted_event_type =
9492 do_endian_conversion(event->event_type);
9593
96
- if ((addr + sizeof(struct tcpa_event)) < limit) {
97
- if ((converted_event_type == 0) &&
98
- (converted_event_size == 0))
99
- return NULL;
100
- addr += (sizeof(struct tcpa_event) +
101
- converted_event_size);
102
- }
103
- }
94
+ if (((converted_event_type == 0) && (converted_event_size == 0))
95
+ || ((addr + sizeof(struct tcpa_event) + converted_event_size)
96
+ > limit))
97
+ return NULL;
10498
105
- /* now check if current entry is valid */
106
- if ((addr + sizeof(struct tcpa_event)) >= limit)
107
- return NULL;
99
+ if (i++ == *pos)
100
+ break;
108101
109
- event = addr;
110
-
111
- converted_event_size = do_endian_conversion(event->event_size);
112
- converted_event_type = do_endian_conversion(event->event_type);
113
-
114
- if (((converted_event_type == 0) && (converted_event_size == 0))
115
- || ((addr + sizeof(struct tcpa_event) + converted_event_size)
116
- >= limit))
117
- return NULL;
102
+ addr += (sizeof(struct tcpa_event) + converted_event_size);
103
+ } while (1);
118104
119105 return addr;
120106 }
....@@ -135,7 +121,7 @@
135121 v += sizeof(struct tcpa_event) + converted_event_size;
136122
137123 /* now check if current entry is valid */
138
- if ((v + sizeof(struct tcpa_event)) >= limit)
124
+ if ((v + sizeof(struct tcpa_event)) > limit)
139125 return NULL;
140126
141127 event = v;
....@@ -144,7 +130,7 @@
144130 converted_event_type = do_endian_conversion(event->event_type);
145131
146132 if (((converted_event_type == 0) && (converted_event_size == 0)) ||
147
- ((v + sizeof(struct tcpa_event) + converted_event_size) >= limit))
133
+ ((v + sizeof(struct tcpa_event) + converted_event_size) > limit))
148134 return NULL;
149135
150136 return v;