Skip to contentSkip to conversation

tpm: fix event_size output in tpm1_binary_bios_measurements_show

PATCH In review Thorsten Blum 2 participants 4 messages May 22 – Jun 15

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tpm: fix event_size output in tpm1_binary_bios_measurements_show

Commit 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements") split the output to write the endian-converted event header first and then the variable-length event data.

However, the split was at sizeof(struct tcpa_event) - 1, even though event_data was a zero-length array, and later a flexible array member, both of which already excluded the event data.

Therefore, the current code writes the first three bytes of event_size from the endian-converted header and then the last byte from the raw header, which can emit a corrupted event_size on PPC64, where do_endian_conversion() maps to be32_to_cpu().

Split one byte later to write the full endian-converted header first, followed by the variable-length event->event_data.

Fixes 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements")

---
Changes in v2:
- Minimal fix without using seq_write()
- v1: https://lore.kernel.org/lkml/[email protected]/

---
 drivers/char/tpm/eventlog/tpm1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/tpm/eventlog/tpm1.c +2 -2
index e7913b2853d5..0397e3361020 100644
@@ -236,12 +236,12 @@ static int tpm1_binary_bios_measurements_show(struct seq_file *m, void *v)
 
 	temp_ptr = (char *) &temp_event;
 
-	for (i = 0; i < (sizeof(struct tcpa_event) - 1) ; i++)
+	for (i = 0; i < sizeof(struct tcpa_event); i++)
 		seq_putc(m, temp_ptr[i]);
 
 	temp_ptr = (char *) v;
 
-	for (i = (sizeof(struct tcpa_event) - 1);
+	for (i = sizeof(struct tcpa_event);
 	     i < (sizeof(struct tcpa_event) + temp_event.event_size); i++)
 		seq_putc(m, temp_ptr[i]);
 
maintainer
#1 lore raw
Quoted 36 lines · Thorsten Blum

Commit 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements") split the output to write the endian-converted event header first and then the variable-length event data.

However, the split was at sizeof(struct tcpa_event) - 1, even though event_data was a zero-length array, and later a flexible array member, both of which already excluded the event data.

Therefore, the current code writes the first three bytes of event_size from the endian-converted header and then the last byte from the raw header, which can emit a corrupted event_size on PPC64, where do_endian_conversion() maps to be32_to_cpu().

Split one byte later to write the full endian-converted header first, followed by the variable-length event->event_data.

Fixes 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements")

---
Changes in v2:
- Minimal fix without using seq_write()
- v1: https://lore.kernel.org/lkml/[email protected]/

---
 drivers/char/tpm/eventlog/tpm1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/tpm/eventlog/tpm1.c +0 -1
index e7913b2853d5..0397e3361020 100644
@@ -236,12 +236,12 @@ static int tpm1_binary_bios_measurements_show(struct seq_file *m, void *v)
 
 	temp_ptr = (char *) &temp_event;
 
-	for (i = 0; i < (sizeof(struct tcpa_event) - 1) ; i++)

drivers/char/tpm/eventlog/tpm1.c static int tpm1_binary_bios_measurements_show(struct seq_file *m, void *v) · line 247

Quoted 10 lines
drivers/char/tpm/eventlog/tpm1.c +2 -1
+	for (i = 0; i < sizeof(struct tcpa_event); i++)
 		seq_putc(m, temp_ptr[i]);
 
 	temp_ptr = (char *) v;
 
-	for (i = (sizeof(struct tcpa_event) - 1);
+	for (i = sizeof(struct tcpa_event);
 	     i < (sizeof(struct tcpa_event) + temp_event.event_size); i++)
 		seq_putc(m, temp_ptr[i]);
 

This was really good catch, thank you. I'll apply in a minute.

BR, Jarkko

#2 lore raw
Quoted 42 lines · Jarkko Sakkinen
Quoted 41 lines · Thorsten Blum

Commit 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements") split the output to write the endian-converted event header first and then the variable-length event data.

However, the split was at sizeof(struct tcpa_event) - 1, even though event_data was a zero-length array, and later a flexible array member, both of which already excluded the event data.

Therefore, the current code writes the first three bytes of event_size from the endian-converted header and then the last byte from the raw header, which can emit a corrupted event_size on PPC64, where do_endian_conversion() maps to be32_to_cpu().

Split one byte later to write the full endian-converted header first, followed by the variable-length event->event_data.

Fixes 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements")

---
Changes in v2:
- Minimal fix without using seq_write()
- v1: https://lore.kernel.org/lkml/[email protected]/

---
 drivers/char/tpm/eventlog/tpm1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/tpm/eventlog/tpm1.c +1 -1
index e7913b2853d5..0397e3361020 100644
@@ -236,12 +236,12 @@ static int tpm1_binary_bios_measurements_show(struct seq_file *m, void *v)
 
 	temp_ptr = (char *) &temp_event;
 
-	for (i = 0; i < (sizeof(struct tcpa_event) - 1) ; i++)
+	for (i = 0; i < sizeof(struct tcpa_event); i++)
 		seq_putc(m, temp_ptr[i]);
 
 	temp_ptr = (char *) v;
 
Quoted 7 lines

drivers/char/tpm/eventlog/tpm1.c static int tpm1_binary_bios_measurements_show(struct seq_file *m, void *v) · line 247

Quoted 5 lines
drivers/char/tpm/eventlog/tpm1.c +1 -1
-	for (i = (sizeof(struct tcpa_event) - 1);
+	for (i = sizeof(struct tcpa_event);
 	     i < (sizeof(struct tcpa_event) + temp_event.event_size); i++)
 		seq_putc(m, temp_ptr[i]);
 

This was really good catch, thank you. I'll apply in a minute.

Has this already been applied somewhere?

Thanks,
Thorsten

maintainer
#3 lore raw
Quoted 51 lines · Thorsten Blum
Quoted 42 lines · Jarkko Sakkinen
Quoted 41 lines · Thorsten Blum

Commit 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements") split the output to write the endian-converted event header first and then the variable-length event data.

However, the split was at sizeof(struct tcpa_event) - 1, even though event_data was a zero-length array, and later a flexible array member, both of which already excluded the event data.

Therefore, the current code writes the first three bytes of event_size from the endian-converted header and then the last byte from the raw header, which can emit a corrupted event_size on PPC64, where do_endian_conversion() maps to be32_to_cpu().

Split one byte later to write the full endian-converted header first, followed by the variable-length event->event_data.

Fixes 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements")

---
Changes in v2:
- Minimal fix without using seq_write()
- v1: https://lore.kernel.org/lkml/[email protected]/

---
 drivers/char/tpm/eventlog/tpm1.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/char/tpm/eventlog/tpm1.c +1 -1
index e7913b2853d5..0397e3361020 100644
@@ -236,12 +236,12 @@ static int tpm1_binary_bios_measurements_show(struct seq_file *m, void *v)
 
 	temp_ptr = (char *) &temp_event;
 
-	for (i = 0; i < (sizeof(struct tcpa_event) - 1) ; i++)
+	for (i = 0; i < sizeof(struct tcpa_event); i++)
 		seq_putc(m, temp_ptr[i]);
 
 	temp_ptr = (char *) v;
 
Quoted 7 lines

drivers/char/tpm/eventlog/tpm1.c static int tpm1_binary_bios_measurements_show(struct seq_file *m, void *v) · line 247

Quoted 5 lines
drivers/char/tpm/eventlog/tpm1.c +1 -1
-	for (i = (sizeof(struct tcpa_event) - 1);
+	for (i = sizeof(struct tcpa_event);
 	     i < (sizeof(struct tcpa_event) + temp_event.event_size); i++)
 		seq_putc(m, temp_ptr[i]);
 

This was really good catch, thank you. I'll apply in a minute.

Quoted 1 line

Has this already been applied somewhere?

My bad, and thanks for pingin! queued

Quoted 3 lines

Thanks,
Thorsten

BR, Jarkko