Skip to content

Commit 047d50a

Browse files
vathpelaIngo Molnar
authored andcommitted
efi/tpm: Don't access event->count when it isn't mapped
Some machines generate a lot of event log entries. When we're iterating over them, the code removes the old mapping and adds a new one, so once we cross the page boundary we're unmapping the page with the count on it. Hilarity ensues. This patch keeps the info from the header in local variables so we don't need to access that page again or keep track of if it's mapped. Tested-by: Lyude Paul <[email protected]> Signed-off-by: Peter Jones <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Acked-by: Matthew Garrett <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Cc: Ben Dooks <[email protected]> Cc: Dave Young <[email protected]> Cc: Jerry Snitselaar <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Lukas Wunner <[email protected]> Cc: Octavian Purdila <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Scott Talbert <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Fixes: 44038bc ("tpm: Abstract crypto agile event size calculations") Link: https://lkml.kernel.org/r/[email protected] [ Minor edits. ] Signed-off-by: Ingo Molnar <[email protected]>
1 parent c05f8f9 commit 047d50a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

include/linux/tpm_eventlog.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
170170
u16 halg;
171171
int i;
172172
int j;
173+
u32 count, event_type;
173174

174175
marker = event;
175176
marker_start = marker;
@@ -190,16 +191,22 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
190191
}
191192

192193
event = (struct tcg_pcr_event2_head *)mapping;
194+
/*
195+
* The loop below will unmap these fields if the log is larger than
196+
* one page, so save them here for reference:
197+
*/
198+
count = READ_ONCE(event->count);
199+
event_type = READ_ONCE(event->event_type);
193200

194201
efispecid = (struct tcg_efi_specid_event_head *)event_header->event;
195202

196203
/* Check if event is malformed. */
197-
if (event->count > efispecid->num_algs) {
204+
if (count > efispecid->num_algs) {
198205
size = 0;
199206
goto out;
200207
}
201208

202-
for (i = 0; i < event->count; i++) {
209+
for (i = 0; i < count; i++) {
203210
halg_size = sizeof(event->digests[i].alg_id);
204211

205212
/* Map the digest's algorithm identifier */
@@ -256,8 +263,9 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
256263
+ event_field->event_size;
257264
size = marker - marker_start;
258265

259-
if ((event->event_type == 0) && (event_field->event_size == 0))
266+
if (event_type == 0 && event_field->event_size == 0)
260267
size = 0;
268+
261269
out:
262270
if (do_mapping)
263271
TPM_MEMUNMAP(mapping, mapping_size);

0 commit comments

Comments
 (0)