All of lore.kernel.org
 help / color / mirror / Atom feed
* [GIT PULL 0/2] EFI fixes for v5.2
@ 2019-05-25 11:25 Ard Biesheuvel
  2019-05-25 11:25 ` [PATCH 1/2] efi/x86: Add missing error handling to old_memmap 1:1 mapping code Ard Biesheuvel
  2019-05-25 11:25 ` [PATCH 2/2] efi: Allow the number of EFI configuration tables entries to be zero Ard Biesheuvel
  0 siblings, 2 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2019-05-25 11:25 UTC (permalink / raw)
  To: linux-efi, Ingo Molnar, Thomas Gleixner
  Cc: Ard Biesheuvel, linux-kernel, Gen Zhang, Rob Bradford

The following changes since commit a188339ca5a396acc588e5851ed7e19f66b0ebd9:

  Linux 5.2-rc1 (2019-05-19 15:47:09 -0700)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git tags/efi-urgent

for you to fetch changes up to a7decd94d514721f8bf5da02e3ae66758b80603a:

  efi: Allow the number of EFI configuration tables entries to be zero (2019-05-25 13:10:50 +0200)

----------------------------------------------------------------
A pair of low priority EFI fixes for v5.2:
- deal with systems where EFI does not expose a single configuration table
- add missing handling for memory allocation failures to x86 old_map code

----------------------------------------------------------------
Gen Zhang (1):
      efi/x86: Add missing error handling to old_memmap 1:1 mapping code

Rob Bradford (1):
      efi: Allow the number of EFI configuration tables entries to be zero

 arch/x86/platform/efi/efi.c    | 2 ++
 arch/x86/platform/efi/efi_64.c | 9 ++++++---
 arch/x86/platform/efi/quirks.c | 3 +++
 drivers/firmware/efi/efi.c     | 3 +++
 4 files changed, 14 insertions(+), 3 deletions(-)

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

* [PATCH 1/2] efi/x86: Add missing error handling to old_memmap 1:1 mapping code
  2019-05-25 11:25 [GIT PULL 0/2] EFI fixes for v5.2 Ard Biesheuvel
@ 2019-05-25 11:25 ` Ard Biesheuvel
  2019-05-25 11:52   ` [tip:efi/urgent] efi/x86/Add " tip-bot for Gen Zhang
  2019-05-25 11:25 ` [PATCH 2/2] efi: Allow the number of EFI configuration tables entries to be zero Ard Biesheuvel
  1 sibling, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2019-05-25 11:25 UTC (permalink / raw)
  To: linux-efi, Ingo Molnar, Thomas Gleixner
  Cc: Ard Biesheuvel, linux-kernel, Gen Zhang, Rob Bradford

From: Gen Zhang <blackgod016574@gmail.com>

The old_memmap flow in efi_call_phys_prolog() performs numerous memory
allocations, and either does not check for failure at all, or it does
but fails to propagate it back to the caller, which may end up calling
into the firmware with an incomplete 1:1 mapping.

So let's fix this by returning NULL from efi_call_phys_prolog() on
memory allocation failures only, and by handling this condition in the
caller. Also, clean up any half baked sets of page tables that we may
have created before returning with a NULL return value.

Note that any failure at this level will trigger a panic() two levels
up, so none of this makes a huge difference, but it is a nice cleanup
nonetheless.

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
[ardb: update commit log, add efi_call_phys_epilog() call on error path]
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/x86/platform/efi/efi.c    | 2 ++
 arch/x86/platform/efi/efi_64.c | 9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index e1cb01a22fa8..a7189a3b4d70 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -85,6 +85,8 @@ static efi_status_t __init phys_efi_set_virtual_address_map(
 	pgd_t *save_pgd;
 
 	save_pgd = efi_call_phys_prolog();
+	if (!save_pgd)
+		return EFI_ABORTED;
 
 	/* Disable interrupts around EFI calls: */
 	local_irq_save(flags);
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index cf0347f61b21..08ce8177c3af 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -84,13 +84,15 @@ pgd_t * __init efi_call_phys_prolog(void)
 
 	if (!efi_enabled(EFI_OLD_MEMMAP)) {
 		efi_switch_mm(&efi_mm);
-		return NULL;
+		return efi_mm.pgd;
 	}
 
 	early_code_mapping_set_exec(1);
 
 	n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE);
 	save_pgd = kmalloc_array(n_pgds, sizeof(*save_pgd), GFP_KERNEL);
+	if (!save_pgd)
+		return NULL;
 
 	/*
 	 * Build 1:1 identity mapping for efi=old_map usage. Note that
@@ -138,10 +140,11 @@ pgd_t * __init efi_call_phys_prolog(void)
 		pgd_offset_k(pgd * PGDIR_SIZE)->pgd &= ~_PAGE_NX;
 	}
 
-out:
 	__flush_tlb_all();
-
 	return save_pgd;
+out:
+	efi_call_phys_epilog(save_pgd);
+	return NULL;
 }
 
 void __init efi_call_phys_epilog(pgd_t *save_pgd)
-- 
2.20.1


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

* [PATCH 2/2] efi: Allow the number of EFI configuration tables entries to be zero
  2019-05-25 11:25 [GIT PULL 0/2] EFI fixes for v5.2 Ard Biesheuvel
  2019-05-25 11:25 ` [PATCH 1/2] efi/x86: Add missing error handling to old_memmap 1:1 mapping code Ard Biesheuvel
@ 2019-05-25 11:25 ` Ard Biesheuvel
  2019-05-25 11:53   ` [tip:efi/urgent] " tip-bot for Rob Bradford
  1 sibling, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2019-05-25 11:25 UTC (permalink / raw)
  To: linux-efi, Ingo Molnar, Thomas Gleixner
  Cc: Ard Biesheuvel, linux-kernel, Gen Zhang, Rob Bradford

From: Rob Bradford <robert.bradford@intel.com>

Only try and access the EFI configuration tables if there there are any
reported. This allows EFI to be continued to used on systems where there
are no configuration table entries.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/x86/platform/efi/quirks.c | 3 +++
 drivers/firmware/efi/efi.c     | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index a25a9fd987a9..e92ab8002dc5 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -512,6 +512,9 @@ int __init efi_reuse_config(u64 tables, int nr_tables)
 	void *p, *tablep;
 	struct efi_setup_data *data;
 
+	if (nr_tables == 0)
+		return 0;
+
 	if (!efi_setup)
 		return 0;
 
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 55b77c576c42..521a541d02ad 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -636,6 +636,9 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables)
 	void *config_tables;
 	int sz, ret;
 
+	if (efi.systab->nr_tables == 0)
+		return 0;
+
 	if (efi_enabled(EFI_64BIT))
 		sz = sizeof(efi_config_table_64_t);
 	else
-- 
2.20.1


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

* [tip:efi/urgent] efi/x86/Add missing error handling to old_memmap 1:1 mapping code
  2019-05-25 11:25 ` [PATCH 1/2] efi/x86: Add missing error handling to old_memmap 1:1 mapping code Ard Biesheuvel
@ 2019-05-25 11:52   ` tip-bot for Gen Zhang
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Gen Zhang @ 2019-05-25 11:52 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, mingo, torvalds, hpa, ard.biesheuvel, robert.bradford,
	blackgod016574, tglx, linux-kernel

Commit-ID:  4e78921ba4dd0aca1cc89168f45039add4183f8e
Gitweb:     https://git.kernel.org/tip/4e78921ba4dd0aca1cc89168f45039add4183f8e
Author:     Gen Zhang <blackgod016574@gmail.com>
AuthorDate: Sat, 25 May 2019 13:25:58 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 25 May 2019 13:48:17 +0200

efi/x86/Add missing error handling to old_memmap 1:1 mapping code

The old_memmap flow in efi_call_phys_prolog() performs numerous memory
allocations, and either does not check for failure at all, or it does
but fails to propagate it back to the caller, which may end up calling
into the firmware with an incomplete 1:1 mapping.

So let's fix this by returning NULL from efi_call_phys_prolog() on
memory allocation failures only, and by handling this condition in the
caller. Also, clean up any half baked sets of page tables that we may
have created before returning with a NULL return value.

Note that any failure at this level will trigger a panic() two levels
up, so none of this makes a huge difference, but it is a nice cleanup
nonetheless.

[ardb: update commit log, add efi_call_phys_epilog() call on error path]

Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rob Bradford <robert.bradford@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20190525112559.7917-2-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/platform/efi/efi.c    | 2 ++
 arch/x86/platform/efi/efi_64.c | 9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index e1cb01a22fa8..a7189a3b4d70 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -85,6 +85,8 @@ static efi_status_t __init phys_efi_set_virtual_address_map(
 	pgd_t *save_pgd;
 
 	save_pgd = efi_call_phys_prolog();
+	if (!save_pgd)
+		return EFI_ABORTED;
 
 	/* Disable interrupts around EFI calls: */
 	local_irq_save(flags);
diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
index cf0347f61b21..08ce8177c3af 100644
--- a/arch/x86/platform/efi/efi_64.c
+++ b/arch/x86/platform/efi/efi_64.c
@@ -84,13 +84,15 @@ pgd_t * __init efi_call_phys_prolog(void)
 
 	if (!efi_enabled(EFI_OLD_MEMMAP)) {
 		efi_switch_mm(&efi_mm);
-		return NULL;
+		return efi_mm.pgd;
 	}
 
 	early_code_mapping_set_exec(1);
 
 	n_pgds = DIV_ROUND_UP((max_pfn << PAGE_SHIFT), PGDIR_SIZE);
 	save_pgd = kmalloc_array(n_pgds, sizeof(*save_pgd), GFP_KERNEL);
+	if (!save_pgd)
+		return NULL;
 
 	/*
 	 * Build 1:1 identity mapping for efi=old_map usage. Note that
@@ -138,10 +140,11 @@ pgd_t * __init efi_call_phys_prolog(void)
 		pgd_offset_k(pgd * PGDIR_SIZE)->pgd &= ~_PAGE_NX;
 	}
 
-out:
 	__flush_tlb_all();
-
 	return save_pgd;
+out:
+	efi_call_phys_epilog(save_pgd);
+	return NULL;
 }
 
 void __init efi_call_phys_epilog(pgd_t *save_pgd)

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

* [tip:efi/urgent] efi: Allow the number of EFI configuration tables entries to be zero
  2019-05-25 11:25 ` [PATCH 2/2] efi: Allow the number of EFI configuration tables entries to be zero Ard Biesheuvel
@ 2019-05-25 11:53   ` tip-bot for Rob Bradford
  0 siblings, 0 replies; 5+ messages in thread
From: tip-bot for Rob Bradford @ 2019-05-25 11:53 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, linux-kernel, blackgod016574, peterz, mingo, ard.biesheuvel,
	torvalds, robert.bradford, tglx

Commit-ID:  88447c5b93d98be847f428c39ba589779a59eb83
Gitweb:     https://git.kernel.org/tip/88447c5b93d98be847f428c39ba589779a59eb83
Author:     Rob Bradford <robert.bradford@intel.com>
AuthorDate: Sat, 25 May 2019 13:25:59 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 25 May 2019 13:48:17 +0200

efi: Allow the number of EFI configuration tables entries to be zero

Only try and access the EFI configuration tables if there there are any
reported. This allows EFI to be continued to used on systems where there
are no configuration table entries.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Gen Zhang <blackgod016574@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20190525112559.7917-3-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 arch/x86/platform/efi/quirks.c | 3 +++
 drivers/firmware/efi/efi.c     | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
index feb77777c8b8..632b83885867 100644
--- a/arch/x86/platform/efi/quirks.c
+++ b/arch/x86/platform/efi/quirks.c
@@ -513,6 +513,9 @@ int __init efi_reuse_config(u64 tables, int nr_tables)
 	void *p, *tablep;
 	struct efi_setup_data *data;
 
+	if (nr_tables == 0)
+		return 0;
+
 	if (!efi_setup)
 		return 0;
 
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 55b77c576c42..521a541d02ad 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -636,6 +636,9 @@ int __init efi_config_init(efi_config_table_type_t *arch_tables)
 	void *config_tables;
 	int sz, ret;
 
+	if (efi.systab->nr_tables == 0)
+		return 0;
+
 	if (efi_enabled(EFI_64BIT))
 		sz = sizeof(efi_config_table_64_t);
 	else

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

end of thread, other threads:[~2019-05-25 11:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-25 11:25 [GIT PULL 0/2] EFI fixes for v5.2 Ard Biesheuvel
2019-05-25 11:25 ` [PATCH 1/2] efi/x86: Add missing error handling to old_memmap 1:1 mapping code Ard Biesheuvel
2019-05-25 11:52   ` [tip:efi/urgent] efi/x86/Add " tip-bot for Gen Zhang
2019-05-25 11:25 ` [PATCH 2/2] efi: Allow the number of EFI configuration tables entries to be zero Ard Biesheuvel
2019-05-25 11:53   ` [tip:efi/urgent] " tip-bot for Rob Bradford

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.