Skip to contentSkip to conversation

TCG2 log support build fixes for non-x86_64

PATCH In review Matthew Garrett 5 participants 12 messages Apr 2, 2019 – Apr 15, 2019

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

PATCH 1/1 TCG2 log support build fixes for non-x86_64

Couple of patches to fix ktest reported issues with the crypto-agile log format support.

#1 lore raw

PATCH 1/2 efi: Fix cast to pointer from integer of different size in TPM log code

8bfcff4a6a1d9d7226bb63a7da758b82d9ab4373 introduced a cast from efi_physical_address_t to (void *), which are different sizes on 32-bit. Fix that. Caught by the 0-day test bot.

---
 drivers/firmware/efi/libstub/tpm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/efi/libstub/tpm.c +2 -2
index b6e93e14fcf1..6b3b507a54eb 100644
@@ -114,8 +114,8 @@ void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table_arg)
 			 */
 			last_entry_size =
 				__calc_tpm2_event_size((void *)last_entry_addr,
-						       (void *)log_location,
-						       false);
+						    (void *)(long)log_location,
+						    false);
 		} else {
 			last_entry_size = sizeof(struct tcpa_event) +
 			   ((struct tcpa_event *) last_entry_addr)->event_size;
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
#2 lore raw

RE: [PATCH 1/2] efi: Fix cast to pointer from integer of different size in TPM log code

From: Matthew Garrett

Quoted 5 lines

Sent: 02 April 2019 22:56

8bfcff4a6a1d9d7226bb63a7da758b82d9ab4373 introduced a cast from efi_physical_address_t to (void *), which are different sizes on 32-bit. Fix that. Caught by the 0-day test bot.

Casting a physical address to 'void *' seems completely wrong. Also you'd need a guarantee that the address was below 4G or the result is meaningless.
Looks to me like something is using the wrong types somewhere.

David

Quoted 21 lines
---
 drivers/firmware/efi/libstub/tpm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/efi/libstub/tpm.c +2 -3
index b6e93e14fcf1..6b3b507a54eb 100644
@@ -114,8 +114,8 @@ void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table_arg)
 			 */
 			last_entry_size =
 				__calc_tpm2_event_size((void *)last_entry_addr,
-						       (void *)log_location,
-						       false);
+						    (void *)(long)log_location,
+						    false);
 		} else {
 			last_entry_size = sizeof(struct tcpa_event) +
 			   ((struct tcpa_event *) last_entry_addr)->event_size;
--
Quoted 1 line

2.21.0.392.gf8f6787159e-goog

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

#3 lore raw

Re: [PATCH 1/2] efi: Fix cast to pointer from integer of different size in TPM log code

Quoted 4 lines · David Laight

From: Matthew Garrett

Quoted 2 lines

Sent: 02 April 2019 22:56

Quoted 8 lines
Quoted 3 lines

8bfcff4a6a1d9d7226bb63a7da758b82d9ab4373 introduced a cast from efi_physical_address_t to (void *), which are different sizes on 32-bit. Fix that. Caught by the 0-day test bot.

Casting a physical address to 'void *' seems completely wrong. Also you'd need a guarantee that the address was below 4G or the result is meaningless.
Looks to me like something is using the wrong types somewhere.

We're in UEFI here, not the kernel proper - the firmware functions we call give us back physical addresses, and we're operating with a 1:1 mapping. long is 64 bit on 64 bit systems, and on 32 bit systems we've already asserted that all firmware resources are under 4GB (obviously we're going to have a bad time if they're not, but there's not really anything we can do about that)

Reviewed-by on v1 1/2
#4 lore raw

Re: [PATCH 1/2] efi: Fix cast to pointer from integer of different size in TPM log code

In reply to Matthew Garrett
Quoted 5 lines · Matthew Garrett

8bfcff4a6a1d9d7226bb63a7da758b82d9ab4373 introduced a cast from efi_physical_address_t to (void *), which are different sizes on 32-bit. Fix that. Caught by the 0-day test bot.

/Jarkko

Acked-by on v1 1/2
#5 lore raw

Re: [PATCH 1/2] efi: Fix cast to pointer from integer of different size in TPM log code

In reply to Matthew Garrett
Quoted 2 lines · Matthew Garrett

8bfcff4a6a1d9d7226bb63a7da758b82d9ab4373

Which tree is this commit in?

Quoted 5 lines

introduced a cast from
efi_physical_address_t to (void *), which are different sizes on 32-bit. Fix that. Caught by the 0-day test bot.

I'll pick this up as a fix if we can clean up the commit log so it doesn't refer to a commit that does not exist in mainline.

Quoted 22 lines
---
 drivers/firmware/efi/libstub/tpm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/firmware/efi/libstub/tpm.c +2 -3
index b6e93e14fcf1..6b3b507a54eb 100644
@@ -114,8 +114,8 @@ void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table_arg)
                         */
                        last_entry_size =
                                __calc_tpm2_event_size((void *)last_entry_addr,
-                                                      (void *)log_location,
-                                                      false);
+                                                   (void *)(long)log_location,
+                                                   false);
                } else {
                        last_entry_size = sizeof(struct tcpa_event) +
                           ((struct tcpa_event *) last_entry_addr)->event_size;
--

2.21.0.392.gf8f6787159e-goog

#6 lore raw

Re: [PATCH 1/2] efi: Fix cast to pointer from integer of different size in TPM log code

Quoted 6 lines · Ard Biesheuvel
Quoted 2 lines · Matthew Garrett

8bfcff4a6a1d9d7226bb63a7da758b82d9ab4373

Which tree is this commit in?

Sorry, these are in the tpmdd-next tree.

#7 lore raw

PATCH 2/2 tpm: Fix builds on platforms that lack early_memremap()

In reply to Matthew Garrett

On EFI systems, __calc_tpm2_event_size() needs to be able to map tables at early boot time in order to extract information from them. Unfortunately this interacts badly with other architectures that don't provide the early_memremap() interface but which may still have other mechanisms for obtaining crypto-agile logs. Abstract this away so we can avoid the need for two implementations while still avoiding breakage on architectures that don't require remapping of the table.

---
 drivers/firmware/efi/tpm.c   |  3 +++
 include/linux/tpm_eventlog.h | 32 ++++++++++++++++++++------------
 2 files changed, 23 insertions(+), 12 deletions(-)
drivers/firmware/efi/tpm.c +3 -0
index f2a13cbb8688..fe48150f06d1 100644
@@ -4,6 +4,9 @@
  *     Thiebaud Weksteen <[email protected]>
  */
 
+#define TPM_MEMREMAP(start, size) early_memremap(start, size)
+#define TPM_MEMUNMAP(start, size) early_memunmap(start, size)
+
 #include <linux/efi.h>
 #include <linux/init.h>
 #include <linux/memblock.h>
include/linux/tpm_eventlog.h +20 -12
index d889e12047d9..0ca27bc053af 100644
@@ -128,6 +128,14 @@ struct tcg_algorithm_info {
 	struct tcg_algorithm_size digest_sizes[];
 };
 
+#ifndef TPM_MEMREMAP
+#define TPM_MEMREMAP(start, size) NULL
+#endif
+
+#ifndef TPM_MEMUNMAP
+#define TPM_MEMUNMAP(start, size) do{} while(0)
+#endif
+
 /**
  * __calc_tpm2_event_size - calculate the size of a TPM2 event log entry
  * @event:        Pointer to the event whose size should be calculated
@@ -171,8 +179,8 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 	/* Map the event header */
 	if (do_mapping) {
 		mapping_size = marker - marker_start;
-		mapping = early_memremap((unsigned long)marker_start,
-					 mapping_size);
+		mapping = TPM_MEMREMAP((unsigned long)marker_start,
+				       mapping_size);
 		if (!mapping) {
 			size = 0;
 			goto out;
@@ -192,10 +200,10 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 
 		/* Map the digest's algorithm identifier */
 		if (do_mapping) {
-			early_memunmap(mapping, mapping_size);
+			TPM_MEMUNMAP(mapping, mapping_size);
 			mapping_size = marker - marker_start + halg_size;
-			mapping = early_memremap((unsigned long)marker_start,
-						 mapping_size);
+			mapping = TPM_MEMREMAP((unsigned long)marker_start,
+					       mapping_size);
 			if (!mapping) {
 				size = 0;
 				goto out;
@@ -212,10 +220,10 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 
 				/* Map the digest content itself */
 				if (do_mapping) {
-					early_memunmap(mapping, mapping_size);
+					TPM_MEMUNMAP(mapping, mapping_size);
 					mapping_size = marker - marker_start;
-					mapping = early_memremap((unsigned long)marker_start,
-						      mapping_size);
+					mapping = TPM_MEMREMAP((unsigned long)marker_start,
+							       mapping_size);
 					if (!mapping) {
 						size = 0;
 						goto out;
@@ -238,10 +246,10 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 	 * we don't need to map it
 	 */
 	if (do_mapping) {
-		early_memunmap(marker_start, mapping_size);
+		TPM_MEMUNMAP(marker_start, mapping_size);
 		mapping_size += sizeof(event_field->event_size);
-		mapping = early_memremap((unsigned long)marker_start,
-					 mapping_size);
+		mapping = TPM_MEMREMAP((unsigned long)marker_start,
+				       mapping_size);
 		if (!mapping) {
 			size = 0;
 			goto out;
@@ -256,7 +264,7 @@ static inline int __calc_tpm2_event_size(struct tcg_pcr_event2_head *event,
 		size = 0;
 out:
 	if (do_mapping)
-		early_memunmap(mapping, mapping_size);
+		TPM_MEMUNMAP(mapping, mapping_size);
 	return size;
 }
 
Signature · 1 line
2.21.0.392.gf8f6787159e-goog
Reviewed-by on v1 2/2
#8 lore raw

Re: [PATCH 2/2] tpm: Fix builds on platforms that lack early_memremap()

Quoted 9 lines · Matthew Garrett

On EFI systems, __calc_tpm2_event_size() needs to be able to map tables at early boot time in order to extract information from them. Unfortunately this interacts badly with other architectures that don't provide the early_memremap() interface but which may still have other mechanisms for obtaining crypto-agile logs. Abstract this away so we can avoid the need for two implementations while still avoiding breakage on architectures that don't require remapping of the table.

/Jarkko

#9 lore raw
In reply to Matthew Garrett
Quoted 2 lines · Matthew Garrett

Couple of patches to fix ktest reported issues with the crypto-agile log format support.

I guess I squash these to your earlier commits?

/Jarkko

#10 lore raw
Quoted 6 lines · Jarkko Sakkinen
Quoted 2 lines · Matthew Garrett

Couple of patches to fix ktest reported issues with the crypto-agile log format support.

I guess I squash these to your earlier commits?

Works for me.

#11 lore raw
In reply to Matthew Garrett
Quoted 2 lines · Matthew Garrett

Couple of patches to fix ktest reported issues with the crypto-agile log format support.

Applied and squashed. Should be soon in linux-next.

/Jarkko