Skip to content

Commit 659d95b

Browse files
jiazhang0uudiin
authored andcommitted
tpm: Simplify the measurements loop
commit bb3b6b0 upstream The responsibility of tpm1_bios_measurements_start() is to walk over the first *pos measurements, ensuring the skipped and to-be-read measurements are not out-of-boundary. This commit simplifies the loop by employing a do-while loop with the necessary sanity check. Signed-off-by: Jia Zhang <zhang.jia@linux.alibaba.com> Reviewd-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com> Reviewed-by: Jia Zhang <zhang.jia@linux.alibaba.com>
1 parent a816f83 commit 659d95b

File tree

1 file changed

+14
-23
lines changed
  • drivers/char/tpm/eventlog

1 file changed

+14
-23
lines changed

drivers/char/tpm/eventlog/tpm1.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static const char* tcpa_pc_event_id_strings[] = {
7474
/* returns pointer to start of pos. entry of tcg log */
7575
static void *tpm1_bios_measurements_start(struct seq_file *m, loff_t *pos)
7676
{
77-
loff_t i;
77+
loff_t i = 0;
7878
struct tpm_chip *chip = m->private;
7979
struct tpm_bios_log *log = &chip->log;
8080
void *addr = log->bios_event_log;
@@ -83,38 +83,29 @@ static void *tpm1_bios_measurements_start(struct seq_file *m, loff_t *pos)
8383
u32 converted_event_size;
8484
u32 converted_event_type;
8585

86-
8786
/* read over *pos measurements */
88-
for (i = 0; i < *pos; i++) {
87+
do {
8988
event = addr;
9089

90+
/* check if current entry is valid */
91+
if (addr + sizeof(struct tcpa_event) >= limit)
92+
return NULL;
93+
9194
converted_event_size =
9295
do_endian_conversion(event->event_size);
9396
converted_event_type =
9497
do_endian_conversion(event->event_type);
9598

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-
}
104-
105-
/* now check if current entry is valid */
106-
if ((addr + sizeof(struct tcpa_event)) >= limit)
107-
return NULL;
108-
109-
event = addr;
99+
if (((converted_event_type == 0) && (converted_event_size == 0))
100+
|| ((addr + sizeof(struct tcpa_event) + converted_event_size)
101+
>= limit))
102+
return NULL;
110103

111-
converted_event_size = do_endian_conversion(event->event_size);
112-
converted_event_type = do_endian_conversion(event->event_type);
104+
if (i++ == *pos)
105+
break;
113106

114-
if (((converted_event_type == 0) && (converted_event_size == 0))
115-
|| ((addr + sizeof(struct tcpa_event) + converted_event_size)
116-
>= limit))
117-
return NULL;
107+
addr += (sizeof(struct tcpa_event) + converted_event_size);
108+
} while (1);
118109

119110
return addr;
120111
}

0 commit comments

Comments
 (0)