Skip to contentSkip to conversation

x86,efi: Check max_size only if it is non-zero.

PATCH Applied Richard Weinberger 2 participants 4 messages Apr 10, 2013 – Apr 11, 2013

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

PATCH 1/2 x86,efi: Check max_size only if it is non-zero.

Some EFI implementations return always a MaximumVariableSize of 0, check against max_size only if it is non-zero.
My Intel DQ67SW desktop board has such an implementation.

---
 arch/x86/platform/efi/efi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/platform/efi/efi.c +6 -1
index c89c245..3f96a48 100644
@@ -1018,7 +1018,12 @@ efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)
 	if (status != EFI_SUCCESS)
 		return status;
 
-	if (!storage_size || size > remaining_size || size > max_size ||
+	if (!max_size && remaining_size > size)
+		printk_once(KERN_ERR FW_BUG "Broken EFI implementation"
+			    " is returning MaxVariableSize=0\n");
+
+	if (!storage_size || size > remaining_size ||
+	    (max_size && size > max_size) ||
 	    (remaining_size - size) < (storage_size / 2))
 		return EFI_OUT_OF_RESOURCES;
 
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 2/2 x86,efi: Implement no_storage_paranoia parameter

Using this parameter one can disable the storage_size/2 check if he is really sure that the UEFI does sane gc and fulfills the spec.

This parameter is useful if a devices uses more than 50% of the storage by default.
The Intel DQSW67 desktop board is such an sucker for exmaple.

---
 arch/x86/platform/efi/efi.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
arch/x86/platform/efi/efi.c +12 -1
index 3f96a48..1b0efb6 100644
@@ -41,6 +41,7 @@
 #include <linux/io.h>
 #include <linux/reboot.h>
 #include <linux/bcd.h>
+#include <linux/module.h>
 
 #include <asm/setup.h>
 #include <asm/efi.h>
@@ -71,6 +72,13 @@ static efi_system_table_t efi_systab __initdata;
 
 unsigned long x86_efi_facility;
 
+static bool efivars_no_storage_paranoia;
+module_param_named(no_storage_paranoia, efivars_no_storage_paranoia, bool, 0644);
+MODULE_PARM_DESC(no_storage_paranoia, "Use this parameter only if you are very"
+		 " sure that your EFI implemenation does sane garbage"
+		 " collection and fulfills the UEFI spec."
+		 " Otherwise your board may brick."
+		 " See: http://mjg59.dreamwidth.org/#entry-22855");
 /*
  * Returns 1 if 'facility' is enabled, 0 otherwise.
  */
@@ -1023,7 +1031,10 @@ efi_status_t efi_query_variable_store(u32 attributes, unsigned long size)
 			    " is returning MaxVariableSize=0\n");
 
 	if (!storage_size || size > remaining_size ||
-	    (max_size && size > max_size) ||
+	    (max_size && size > max_size))
+		return EFI_OUT_OF_RESOURCES;
+
+	if (!efivars_no_storage_paranoia &&
 	    (remaining_size - size) < (storage_size / 2))
 		return EFI_OUT_OF_RESOURCES;
 
Signature · 1 line
1.8.1.4
#2 lore raw

Re: [PATCH 2/2] x86,efi: Implement no_storage_paranoia parameter

Quoted 25 lines · Richard Weinberger

Using this parameter one can disable the storage_size/2 check if he is really sure that the UEFI does sane gc and fulfills the spec.

This parameter is useful if a devices uses more than 50% of the storage by default.
The Intel DQSW67 desktop board is such an sucker for exmaple.

---
 arch/x86/platform/efi/efi.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
arch/x86/platform/efi/efi.c +1 -0
index 3f96a48..1b0efb6 100644
@@ -41,6 +41,7 @@
 #include <linux/io.h>
 #include <linux/reboot.h>
 #include <linux/bcd.h>
+#include <linux/module.h>
 
 #include <asm/setup.h>
 #include <asm/efi.h>

arch/x86/platform/efi/efi.c static efi_system_table_t efi_systab __initdata; · line 76

Quoted 5 lines
arch/x86/platform/efi/efi.c +2 -0
@@ -71,6 +72,13 @@ static efi_system_table_t efi_systab __initdata;
 
 unsigned long x86_efi_facility;
 
+static bool efivars_no_storage_paranoia;
+module_param_named(no_storage_paranoia, efivars_no_storage_paranoia, bool, 0644);

Could you rename this to 'efi_no_storage_paranoia' so that it isn't confused with drivers/firmware/efivars.c? Also, it would be a good idea to document this new kernel parameter in Documentation/kernel-parameters.

arch/x86/platform/efi/efi.c static efi_system_table_t efi_systab __initdata; · line 81

Quoted 5 lines
arch/x86/platform/efi/efi.c +5 -0
+MODULE_PARM_DESC(no_storage_paranoia, "Use this parameter only if you are very"
+		 " sure that your EFI implemenation does sane garbage"
+		 " collection and fulfills the UEFI spec."
+		 " Otherwise your board may brick."
+		 " See: http://mjg59.dreamwidth.org/#entry-22855");

I think we should avoid including urls in the kernel source. The rest of the description is fine.

Applied
#3 lore raw
In reply to Richard Weinberger
Quoted 8 lines · Richard Weinberger

Some EFI implementations return always a MaximumVariableSize of 0, check against max_size only if it is non-zero.
My Intel DQ67SW desktop board has such an implementation.

---
 arch/x86/platform/efi/efi.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Applied, thanks!