| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2005, 2012 IBM Corporation |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 12 | 13 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
|---|
| 13 | 14 | * |
|---|
| 14 | 15 | * 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 | | - * |
|---|
| 21 | 16 | */ |
|---|
| 22 | 17 | |
|---|
| 23 | 18 | #include <linux/seq_file.h> |
|---|
| .. | .. |
|---|
| 74 | 69 | /* returns pointer to start of pos. entry of tcg log */ |
|---|
| 75 | 70 | static void *tpm1_bios_measurements_start(struct seq_file *m, loff_t *pos) |
|---|
| 76 | 71 | { |
|---|
| 77 | | - loff_t i; |
|---|
| 72 | + loff_t i = 0; |
|---|
| 78 | 73 | struct tpm_chip *chip = m->private; |
|---|
| 79 | 74 | struct tpm_bios_log *log = &chip->log; |
|---|
| 80 | 75 | void *addr = log->bios_event_log; |
|---|
| .. | .. |
|---|
| 83 | 78 | u32 converted_event_size; |
|---|
| 84 | 79 | u32 converted_event_type; |
|---|
| 85 | 80 | |
|---|
| 86 | | - |
|---|
| 87 | 81 | /* read over *pos measurements */ |
|---|
| 88 | | - for (i = 0; i < *pos; i++) { |
|---|
| 82 | + do { |
|---|
| 89 | 83 | event = addr; |
|---|
| 84 | + |
|---|
| 85 | + /* check if current entry is valid */ |
|---|
| 86 | + if (addr + sizeof(struct tcpa_event) > limit) |
|---|
| 87 | + return NULL; |
|---|
| 90 | 88 | |
|---|
| 91 | 89 | converted_event_size = |
|---|
| 92 | 90 | do_endian_conversion(event->event_size); |
|---|
| 93 | 91 | converted_event_type = |
|---|
| 94 | 92 | do_endian_conversion(event->event_type); |
|---|
| 95 | 93 | |
|---|
| 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; |
|---|
| 104 | 98 | |
|---|
| 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; |
|---|
| 108 | 101 | |
|---|
| 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); |
|---|
| 118 | 104 | |
|---|
| 119 | 105 | return addr; |
|---|
| 120 | 106 | } |
|---|
| .. | .. |
|---|
| 135 | 121 | v += sizeof(struct tcpa_event) + converted_event_size; |
|---|
| 136 | 122 | |
|---|
| 137 | 123 | /* now check if current entry is valid */ |
|---|
| 138 | | - if ((v + sizeof(struct tcpa_event)) >= limit) |
|---|
| 124 | + if ((v + sizeof(struct tcpa_event)) > limit) |
|---|
| 139 | 125 | return NULL; |
|---|
| 140 | 126 | |
|---|
| 141 | 127 | event = v; |
|---|
| .. | .. |
|---|
| 144 | 130 | converted_event_type = do_endian_conversion(event->event_type); |
|---|
| 145 | 131 | |
|---|
| 146 | 132 | 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)) |
|---|
| 148 | 134 | return NULL; |
|---|
| 149 | 135 | |
|---|
| 150 | 136 | return v; |
|---|