Skip to contentSkip to conversation

efi: mokvar-table: fix some issues in new code

PATCH In review Ard Biesheuvel 4 participants 5 messages Sep 24, 2020 – Sep 29, 2020 EFI

lore
Share & tools
lore

Ard Biesheuvel

author maintainer
#0 lore raw

PATCH 1/1 efi: mokvar-table: fix some issues in new code

Fix a couple of issues in the new mokvar-table handling code, as pointed out by Arvind and Boris:
- don't bother checking the end of the physical region against the start address of the mokvar table,
- ensure that we enter the loop with err = -EINVAL,
- replace size_t with unsigned long to appease pedantic type equality checks.

Cc Lenny Szubowicz <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Arvind Sankar <[email protected]>
---
 drivers/firmware/efi/mokvar-table.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/firmware/efi/mokvar-table.c +11 -14
index b1cd49893d4d..72a9e1736fef 100644
@@ -98,15 +98,14 @@ static struct kobject *mokvar_kobj;
 void __init efi_mokvar_table_init(void)
 {
 	efi_memory_desc_t md;
-	u64 end_pa;
 	void *va = NULL;
-	size_t cur_offset = 0;
-	size_t offset_limit;
-	size_t map_size = 0;
-	size_t map_size_needed = 0;
-	size_t size;
+	unsigned long cur_offset = 0;
+	unsigned long offset_limit;
+	unsigned long map_size = 0;
+	unsigned long map_size_needed = 0;
+	unsigned long size;
 	struct efi_mokvar_table_entry *mokvar_entry;
-	int err = -EINVAL;
+	int err;
 
 	if (!efi_enabled(EFI_MEMMAP))
 		return;
@@ -122,18 +121,16 @@ void __init efi_mokvar_table_init(void)
 		pr_warn("EFI MOKvar config table is not within the EFI memory map\n");
 		return;
 	}
-	end_pa = efi_mem_desc_end(&md);
-	if (efi.mokvar_table >= end_pa) {
-		pr_err("EFI memory descriptor containing MOKvar config table is invalid\n");
-		return;
-	}
-	offset_limit = end_pa - efi.mokvar_table;
+
+	offset_limit = efi_mem_desc_end(&md) - efi.mokvar_table;
+
 	/*
 	 * Validate the MOK config table. Since there is no table header
 	 * from which we could get the total size of the MOK config table,
 	 * we compute the total size as we validate each variably sized
 	 * entry, remapping as necessary.
 	 */
+	err = -EINVAL;
 	while (cur_offset + sizeof(*mokvar_entry) <= offset_limit) {
 		mokvar_entry = va + cur_offset;
 		map_size_needed = cur_offset + sizeof(*mokvar_entry);
@@ -150,7 +147,7 @@ void __init efi_mokvar_table_init(void)
 				       offset_limit);
 			va = early_memremap(efi.mokvar_table, map_size);
 			if (!va) {
-				pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%zu.\n",
+				pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%lu.\n",
 				       efi.mokvar_table, map_size);
 				return;
 			}
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Ard Biesheuvel

Fix a couple of issues in the new mokvar-table handling code, as pointed out by Arvind and Boris:
- don't bother checking the end of the physical region against the start address of the mokvar table,
- ensure that we enter the loop with err = -EINVAL,
- replace size_t with unsigned long to appease pedantic type equality checks.

Quoted 4 lines
Cc Lenny Szubowicz <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Arvind Sankar <[email protected]>
Quoted 65 lines
---
 drivers/firmware/efi/mokvar-table.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
drivers/firmware/efi/mokvar-table.c +11 -14
index b1cd49893d4d..72a9e1736fef 100644
@@ -98,15 +98,14 @@ static struct kobject *mokvar_kobj;
 void __init efi_mokvar_table_init(void)
 {
 	efi_memory_desc_t md;
-	u64 end_pa;
 	void *va = NULL;
-	size_t cur_offset = 0;
-	size_t offset_limit;
-	size_t map_size = 0;
-	size_t map_size_needed = 0;
-	size_t size;
+	unsigned long cur_offset = 0;
+	unsigned long offset_limit;
+	unsigned long map_size = 0;
+	unsigned long map_size_needed = 0;
+	unsigned long size;
 	struct efi_mokvar_table_entry *mokvar_entry;
-	int err = -EINVAL;
+	int err;
 
 	if (!efi_enabled(EFI_MEMMAP))
 		return;
@@ -122,18 +121,16 @@ void __init efi_mokvar_table_init(void)
 		pr_warn("EFI MOKvar config table is not within the EFI memory map\n");
 		return;
 	}
-	end_pa = efi_mem_desc_end(&md);
-	if (efi.mokvar_table >= end_pa) {
-		pr_err("EFI memory descriptor containing MOKvar config table is invalid\n");
-		return;
-	}
-	offset_limit = end_pa - efi.mokvar_table;
+
+	offset_limit = efi_mem_desc_end(&md) - efi.mokvar_table;
+
 	/*
 	 * Validate the MOK config table. Since there is no table header
 	 * from which we could get the total size of the MOK config table,
 	 * we compute the total size as we validate each variably sized
 	 * entry, remapping as necessary.
 	 */
+	err = -EINVAL;
 	while (cur_offset + sizeof(*mokvar_entry) <= offset_limit) {
 		mokvar_entry = va + cur_offset;
 		map_size_needed = cur_offset + sizeof(*mokvar_entry);
@@ -150,7 +147,7 @@ void __init efi_mokvar_table_init(void)
 				       offset_limit);
 			va = early_memremap(efi.mokvar_table, map_size);
 			if (!va) {
-				pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%zu.\n",
+				pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%lu.\n",
 				       efi.mokvar_table, map_size);
 				return;
 			}
Signature · 1 line
2.17.1
Reviewed-by
#2 lore raw
Quoted 9 lines · Arvind Sankar
Quoted 8 lines · Ard Biesheuvel

Fix a couple of issues in the new mokvar-table handling code, as pointed out by Arvind and Boris:
- don't bother checking the end of the physical region against the start address of the mokvar table,
- ensure that we enter the loop with err = -EINVAL,
- replace size_t with unsigned long to appease pedantic type equality checks.

Quoted 6 lines
Quoted 4 lines
Cc Lenny Szubowicz <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Arvind Sankar <[email protected]>
Quoted 67 lines
Quoted 66 lines
---
  drivers/firmware/efi/mokvar-table.c | 25 +++++++++++--------------
  1 file changed, 11 insertions(+), 14 deletions(-)
drivers/firmware/efi/mokvar-table.c +11 -14
index b1cd49893d4d..72a9e1736fef 100644
@@ -98,15 +98,14 @@ static struct kobject *mokvar_kobj;
  void __init efi_mokvar_table_init(void)
  {
  	efi_memory_desc_t md;
-	u64 end_pa;
  	void *va = NULL;
-	size_t cur_offset = 0;
-	size_t offset_limit;
-	size_t map_size = 0;
-	size_t map_size_needed = 0;
-	size_t size;
+	unsigned long cur_offset = 0;
+	unsigned long offset_limit;
+	unsigned long map_size = 0;
+	unsigned long map_size_needed = 0;
+	unsigned long size;
  	struct efi_mokvar_table_entry *mokvar_entry;
-	int err = -EINVAL;
+	int err;
 
  	if (!efi_enabled(EFI_MEMMAP))
  		return;
@@ -122,18 +121,16 @@ void __init efi_mokvar_table_init(void)
  		pr_warn("EFI MOKvar config table is not within the EFI memory map\n");
  		return;
  	}
-	end_pa = efi_mem_desc_end(&md);
-	if (efi.mokvar_table >= end_pa) {
-		pr_err("EFI memory descriptor containing MOKvar config table is invalid\n");
-		return;
-	}
-	offset_limit = end_pa - efi.mokvar_table;
+
+	offset_limit = efi_mem_desc_end(&md) - efi.mokvar_table;
+
  	/*
  	 * Validate the MOK config table. Since there is no table header
  	 * from which we could get the total size of the MOK config table,
  	 * we compute the total size as we validate each variably sized
  	 * entry, remapping as necessary.
  	 */
+	err = -EINVAL;
  	while (cur_offset + sizeof(*mokvar_entry) <= offset_limit) {
  		mokvar_entry = va + cur_offset;
  		map_size_needed = cur_offset + sizeof(*mokvar_entry);
@@ -150,7 +147,7 @@ void __init efi_mokvar_table_init(void)
  				       offset_limit);
  			va = early_memremap(efi.mokvar_table, map_size);
  			if (!va) {
-				pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%zu.\n",
+				pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%lu.\n",
  				       efi.mokvar_table, map_size);
  				return;
  			}
Signature · 1 line
2.17.1
Tested-by on v1 1/1
#3 lore raw
In reply to Ard Biesheuvel
Quoted 8 lines · Ard Biesheuvel

Fix a couple of issues in the new mokvar-table handling code, as pointed out by Arvind and Boris:
- don't bother checking the end of the physical region against the start address of the mokvar table,
- ensure that we enter the loop with err = -EINVAL,
- replace size_t with unsigned long to appease pedantic type equality checks.

Quoted 7 lines
Cc Lenny Szubowicz <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Arvind Sankar <[email protected]>
---
 drivers/firmware/efi/mokvar-table.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

i386 allmodconfig looks good.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#4 lore raw
Quoted 18 lines · Borislav Petkov
Quoted 8 lines · Ard Biesheuvel

Fix a couple of issues in the new mokvar-table handling code, as pointed out by Arvind and Boris:
- don't bother checking the end of the physical region against the start address of the mokvar table,
- ensure that we enter the loop with err = -EINVAL,
- replace size_t with unsigned long to appease pedantic type equality checks.

Quoted 7 lines
Cc Lenny Szubowicz <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Arvind Sankar <[email protected]>
---
 drivers/firmware/efi/mokvar-table.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)
Quoted 4 lines

i386 allmodconfig looks good.

Thanks Boris. I'll have a PR out shortly.