All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] efi: runtime: avoid EFIv2 runtime services on Apple x86 machines
@ 2022-01-12 10:14 Ard Biesheuvel
  2022-01-12 11:01 ` Aditya Garg
  2022-01-18  7:44 ` Aditya Garg
  0 siblings, 2 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2022-01-12 10:14 UTC (permalink / raw)
  To: linux-efi
  Cc: torvalds, Ard Biesheuvel, stable, Jeremy Kerr, Matthew Garrett,
	Aditya Garg, Orlando Chamberlain

Aditya reports [0] that his recent MacbookPro crashes in the firmware
when using the variable services at runtime. The culprit appears to be a
call to QueryVariableInfo(), which we did not use to call on Apple x86
machines in the past as they only upgraded from EFI v1.10 to EFI v2.40
firmware fairly recently, and QueryVariableInfo() (along with
UpdateCapsule() et al) was added in EFI v2.00.

The only runtime service introduced in EFI v2.00 that we actually use in
Linux is QueryVariableInfo(), as the capsule based ones are optional,
generally not used at runtime (all the LVFS/fwupd firmware update
infrastructure uses helper EFI programs that invoke capsule update at
boot time, not runtime), and not implemented by Apple machines in the
first place. QueryVariableInfo() is used to 'safely' set variables,
i.e., only when there is enough space. This prevents machines with buggy
firmwares from corrupting their NVRAMs when they run out of space.

Given that Apple machines have been using EFI v1.10 services only for
the longest time (the EFI v2.0 spec was released in 2006, and Linux
support for the newly introduced runtime services was added in 2011, but
the MacbookPro12,1 released in 2015 still claims to be EFI v1.10 only),
let's avoid the EFI v2.0 ones on all Apple x86 machines.

[0] https://lore.kernel.org/all/6D757C75-65B1-468B-842D-10410081A8E4@live.com/

Cc: <stable@vger.kernel.org>
Cc: Jeremy Kerr <jk@ozlabs.org>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>
Reported-by: Aditya Garg <gargaditya08@live.com>
Tested-by: Orlando Chamberlain <redecorating@protonmail.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/efi.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index ae79c3300129..7de3f5b6e8d0 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -722,6 +722,13 @@ void __init efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
 		systab_hdr->revision >> 16,
 		systab_hdr->revision & 0xffff,
 		vendor);
+
+	if (IS_ENABLED(CONFIG_X86_64) &&
+	    systab_hdr->revision > EFI_1_10_SYSTEM_TABLE_REVISION &&
+	    !strcmp(vendor, "Apple")) {
+		pr_info("Apple Mac detected, using EFI v1.10 runtime services only\n");
+		efi.runtime_version = EFI_1_10_SYSTEM_TABLE_REVISION;
+	}
 }
 
 static __initdata char memory_type_name[][13] = {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] efi: runtime: avoid EFIv2 runtime services on Apple x86 machines
  2022-01-12 10:14 [PATCH] efi: runtime: avoid EFIv2 runtime services on Apple x86 machines Ard Biesheuvel
@ 2022-01-12 11:01 ` Aditya Garg
  2022-01-18  7:44 ` Aditya Garg
  1 sibling, 0 replies; 3+ messages in thread
From: Aditya Garg @ 2022-01-12 11:01 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, Linus Torvalds, stable, Jeremy Kerr, Matthew Garrett,
	Orlando Chamberlain, Aun-Ali Zaidi


> On 12-Jan-2022, at 3:44 PM, Ard Biesheuvel <ardb@kernel.org> wrote:
> 
> Aditya reports [0] that his recent MacbookPro crashes in the firmware
> when using the variable services at runtime. The culprit appears to be a
> call to QueryVariableInfo(), which we did not use to call on Apple x86
> machines in the past as they only upgraded from EFI v1.10 to EFI v2.40
> firmware fairly recently, and QueryVariableInfo() (along with
> UpdateCapsule() et al) was added in EFI v2.00.
> 
> The only runtime service introduced in EFI v2.00 that we actually use in
> Linux is QueryVariableInfo(), as the capsule based ones are optional,
> generally not used at runtime (all the LVFS/fwupd firmware update
> infrastructure uses helper EFI programs that invoke capsule update at
> boot time, not runtime), and not implemented by Apple machines in the
> first place. QueryVariableInfo() is used to 'safely' set variables,
> i.e., only when there is enough space. This prevents machines with buggy
> firmwares from corrupting their NVRAMs when they run out of space.
> 
> Given that Apple machines have been using EFI v1.10 services only for
> the longest time (the EFI v2.0 spec was released in 2006, and Linux
> support for the newly introduced runtime services was added in 2011, but
> the MacbookPro12,1 released in 2015 still claims to be EFI v1.10 only),
> let's avoid the EFI v2.0 ones on all Apple x86 machines.
> 
> [0] https://lore.kernel.org/all/6D757C75-65B1-468B-842D-10410081A8E4@live.com/
> 
> Cc: <stable@vger.kernel.org>
> Cc: Jeremy Kerr <jk@ozlabs.org>
> Cc: Matthew Garrett <mjg59@srcf.ucam.org>
> Reported-by: Aditya Garg <gargaditya08@live.com>
> Tested-by: Orlando Chamberlain <redecorating@protonmail.com>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> drivers/firmware/efi/efi.c | 7 +++++++
> 1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
> index ae79c3300129..7de3f5b6e8d0 100644
> --- a/drivers/firmware/efi/efi.c
> +++ b/drivers/firmware/efi/efi.c
> @@ -722,6 +722,13 @@ void __init efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
> 		systab_hdr->revision >> 16,
> 		systab_hdr->revision & 0xffff,
> 		vendor);
> +
> +	if (IS_ENABLED(CONFIG_X86_64) &&
> +	    systab_hdr->revision > EFI_1_10_SYSTEM_TABLE_REVISION &&
> +	    !strcmp(vendor, "Apple")) {
> +		pr_info("Apple Mac detected, using EFI v1.10 runtime services only\n");
> +		efi.runtime_version = EFI_1_10_SYSTEM_TABLE_REVISION;
> +	}
> }
> 
> static __initdata char memory_type_name[][13] = {
> -- 
> 2.30.2
> 
Hi Ard

Patch works for me. Thanks for investing time to fix the issue :)

Tested-by: Aditya Garg <gargaditya08@live.com>

You may also add the link of the Bug report

Link: https://bugzilla.kernel.org/show_bug.cgi?id=215277

Regards
Aditya

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] efi: runtime: avoid EFIv2 runtime services on Apple x86 machines
  2022-01-12 10:14 [PATCH] efi: runtime: avoid EFIv2 runtime services on Apple x86 machines Ard Biesheuvel
  2022-01-12 11:01 ` Aditya Garg
@ 2022-01-18  7:44 ` Aditya Garg
  1 sibling, 0 replies; 3+ messages in thread
From: Aditya Garg @ 2022-01-18  7:44 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, Linus Torvalds, stable, Jeremy Kerr, Matthew Garrett,
	Orlando Chamberlain

Hi Ard

> drivers/firmware/efi/efi.c | 7 +++++++
> 1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
> index ae79c3300129..7de3f5b6e8d0 100644
> --- a/drivers/firmware/efi/efi.c
> +++ b/drivers/firmware/efi/efi.c
> @@ -722,6 +722,13 @@ void __init efi_systab_report_header(const efi_table_hdr_t *systab_hdr,
> 		systab_hdr->revision >> 16,
> 		systab_hdr->revision & 0xffff,
> 		vendor);
> +
> +	if (IS_ENABLED(CONFIG_X86_64) &&
> +	    systab_hdr->revision > EFI_1_10_SYSTEM_TABLE_REVISION &&
> +	    !strcmp(vendor, "Apple")) {
> +		pr_info("Apple Mac detected, using EFI v1.10 runtime services only\n");
> +		efi.runtime_version = EFI_1_10_SYSTEM_TABLE_REVISION;
> +	}
> }
> 
> static __initdata char memory_type_name[][13] = {
> -- 
> 2.30.2
> 

Just a friendly reminder to upstream this patch.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-01-18  7:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12 10:14 [PATCH] efi: runtime: avoid EFIv2 runtime services on Apple x86 machines Ard Biesheuvel
2022-01-12 11:01 ` Aditya Garg
2022-01-18  7:44 ` Aditya Garg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.