Skip to contentSkip to conversation

EFI urgent fixes

GIT PULL New Matt Fleming 3 participants 7 messages May 31, 2016 – Jun 8, 2016 EFI

lore
Share & tools
lore
#0 lore raw

Folks, please pull the following urgent patches which fix a boot crash when using the "noefi" parameter and the debug output on arm.

The following changes since commit 1a695a905c18548062509178b98bc91e67510864:

Linux 4.7-rc1 (2016-05-29 09:29:24 -0700)

are available in the git repository at:

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

for you to fetch changes up to 1f0cf3892caeab20a99c19f5523499be77b533cd:

efi/arm: Fix the format of debug message from efi (2016-05-30 22:51:53 +0100)

----------------------------------------------------------------
* Fix crash when booting with the "noefi" kernel parameter, caused by recent changes to for_each_efi_memory_desc_in_map() - Vitaly Kuznetsov

* Unscramble the debug output on arm when efi=debug and memblock=debug is passed on the kernel cmdline - Dennis Chen

----------------------------------------------------------------
Dennis Chen (1):
efi/arm: Fix the format of debug message from efi

Vitaly Kuznetsov (1):
efi: Fix for_each_efi_memory_desc_in_map() for empty memmaps

 drivers/firmware/efi/arm-init.c | 14 ++++++--------
 include/linux/efi.h             |  2 +-
 2 files changed, 7 insertions(+), 9 deletions(-)
#1 lore raw

PATCH 1/2 efi: Fix for_each_efi_memory_desc_in_map() for empty memmaps

From: Vitaly Kuznetsov <[email protected]>

Commit 78ce248faa3c ("efi: Iterate over efi.memmap in for_each_efi_memory_desc()") introduced a regression for systems booted with 'noefi' kernel option. In particular, I observe early kernel hang in efi_find_mirror() on for_each_efi_memory_desc() call. As we don't have efi memmap we enter this iterator with the following parameters:

efi.memmap.map = 0, efi.memmap.map_end = 0, efi.memmap.desc_size = 28

for_each_efi_memory_desc_in_map() does the following comparison:

(md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size);

where md = 0, (m)->map_end = 0 and (m)->desc_size = 28 but when we subtract something from a NULL pointer wrap around happens and we end up returning invalid pointer.

Fixes 78ce248faa3c ("efi: Iterate over efi.memmap in for_each_efi_memory_desc()")
Cc Mark Salter <[email protected]>
Cc "K. Y. Srinivasan" <[email protected]>
---
 include/linux/efi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/efi.h +1 -1
index c2db3ca22217..f196dd0b0f2f 100644
@@ -1005,7 +1005,7 @@ extern int efi_memattr_apply_permissions(struct mm_struct *mm,
 /* Iterate through an efi_memory_map */
 #define for_each_efi_memory_desc_in_map(m, md)				   \
 	for ((md) = (m)->map;						   \
-	     (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); \
+	     ((void *)(md) + (m)->desc_size) <= (m)->map_end;		   \
 	     (md) = (void *)(md) + (m)->desc_size)
 
 /**
Signature · 1 line
2.7.3
#3 lore raw

PATCH 2/2 efi/arm: Fix the format of debug message from efi

In reply to Matt Fleming

From: Dennis Chen <[email protected]>

When enable debug of efi and memblock with 'efi=debug memblock=debug' appended to the kernel command line, the debug message output for earyly_con looks like:

[    0.000000] efi:   0x0000e1050000-0x0000e105ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
[    0.000000] efi:   0x0000e1300000-0x0000e1300fff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
[    0.000000] efi:   0x0000e8200000-0x0000e827ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
[    0.000000] efi:   0x008000000000-0x008001e7ffff [Runtime Data       |RUN|  |  |  |  |  |  |   |WB|WT|WC|UC]
[    0.000000] memblock_add: [0x00008000000000-0x00008001e7ffff] flags 0x0 early_init_dt_add_memory_arch+0x54/0x5c
[    0.000000] *

...

This patch is trying to fix the above output messed up by memblock_add(), so we can get below debug mesg looks more formally after applied:

[    0.000000] efi:   0x0000e1050000-0x0000e105ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
[    0.000000] efi:   0x0000e1300000-0x0000e1300fff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
[    0.000000] efi:   0x0000e8200000-0x0000e827ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
[    0.000000] efi:   0x008000000000-0x008001e7ffff [Runtime Data       |RUN|  |  |  |  |  |  |   |WB|WT|WC|UC]*
[    0.000000] memblock_add: [0x00008000000000-0x00008001e7ffff] flags 0x0 early_init_dt_add_memory_arch+0x54/0x5c

...

---
 drivers/firmware/efi/arm-init.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/firmware/efi/arm-init.c +6 -8
index a850cbc48d8d..c49d50e68aee 100644
@@ -174,6 +174,7 @@ static __init void reserve_regions(void)
 {
 	efi_memory_desc_t *md;
 	u64 paddr, npages, size;
+	int resv;
 
 	if (efi_enabled(EFI_DBG))
 		pr_info("Processing EFI memory map:\n");
@@ -190,12 +191,14 @@ static __init void reserve_regions(void)
 		paddr = md->phys_addr;
 		npages = md->num_pages;
 
+		resv = is_reserve_region(md);
 		if (efi_enabled(EFI_DBG)) {
 			char buf[64];
 
-			pr_info("  0x%012llx-0x%012llx %s",
+			pr_info("  0x%012llx-0x%012llx %s%s\n",
 				paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1,
-				efi_md_typeattr_format(buf, sizeof(buf), md));
+				efi_md_typeattr_format(buf, sizeof(buf), md),
+				resv ? "*" : "");
 		}
 
 		memrange_efi_to_native(&paddr, &npages);
@@ -204,14 +207,9 @@ static __init void reserve_regions(void)
 		if (is_normal_ram(md))
 			early_init_dt_add_memory_arch(paddr, size);
 
-		if (is_reserve_region(md)) {
+		if (resv)
 			memblock_mark_nomap(paddr, size);
-			if (efi_enabled(EFI_DBG))
-				pr_cont("*");
-		}
 
-		if (efi_enabled(EFI_DBG))
-			pr_cont("\n");
 	}
 
 	set_bit(EFI_MEMMAP, &efi.flags);
Signature · 1 line
2.7.3
#2 lore raw

[tip:efi/urgent] efi: Fix for_each_efi_memory_desc_in_map() for empty memmaps

In reply to Matt Fleming
efi: Fix for_each_efi_memory_desc_in_map() for empty memmaps
Commit-ID:  55f1ea15216a5a14c96738bd5284100a00ffa9dc
Gitweb:     http://git.kernel.org/tip/55f1ea15216a5a14c96738bd5284100a00ffa9dc
Author:     Vitaly Kuznetsov <[email protected]>
AuthorDate: Tue, 31 May 2016 11:23:43 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Jun 2016 09:57:35 +0200

efi: Fix for_each_efi_memory_desc_in_map() for empty memmaps

Commit:

78ce248faa3c ("efi: Iterate over efi.memmap in for_each_efi_memory_desc()")

introduced a regression for systems booted with the 'noefi' kernel option.

In particular, I observed an early kernel hang in efi_find_mirror()'s for_each_efi_memory_desc() call. As we don't have efi memmap on this system we enter this iterator with the following parameters:

efi.memmap.map = 0, efi.memmap.map_end = 0, efi.memmap.desc_size = 28

... then for_each_efi_memory_desc_in_map() does the following comparison:

  (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size);

... where md = 0, (m)->map_end = 0 and (m)->desc_size = 28 but when we subtract something from a NULL pointer wrap around happens and we end up returning invalid pointer and crash.

Fix it by using the correct pointer arithmetics.

Cc Ard Biesheuvel <[email protected]>
Cc K. Y. Srinivasan <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Mark Salter <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes 78ce248faa3c ("efi: Iterate over efi.memmap in for_each_efi_memory_desc()")
[ Made the changelog more readable. ]
---
 include/linux/efi.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/efi.h +1 -1
index c2db3ca..f196dd0 100644
@@ -1005,7 +1005,7 @@ extern int efi_memattr_apply_permissions(struct mm_struct *mm,
 /* Iterate through an efi_memory_map */
 #define for_each_efi_memory_desc_in_map(m, md)				   \
 	for ((md) = (m)->map;						   \
-	     (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); \
+	     ((void *)(md) + (m)->desc_size) <= (m)->map_end;		   \
 	     (md) = (void *)(md) + (m)->desc_size)
 
 /**
#4 lore raw

[tip:efi/urgent] efi/arm: Fix the format of EFI debug messages

In reply to Matt Fleming
efi/arm: Fix the format of EFI debug messages
Commit-ID:  c75343972b79ef5bd44c498a63b326e37470bbfc
Gitweb:     http://git.kernel.org/tip/c75343972b79ef5bd44c498a63b326e37470bbfc
Author:     Dennis Chen <[email protected]>
AuthorDate: Tue, 31 May 2016 11:23:44 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Jun 2016 09:57:36 +0200

efi/arm: Fix the format of EFI debug messages

When both EFI and memblock debugging is enabled on the kernel command line:

'efi=debug memblock=debug'

.. the debug messages for early_con look the following way:

 [    0.000000] efi:   0x0000e1050000-0x0000e105ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
 [    0.000000] efi:   0x0000e1300000-0x0000e1300fff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
 [    0.000000] efi:   0x0000e8200000-0x0000e827ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
 [    0.000000] efi:   0x008000000000-0x008001e7ffff [Runtime Data       |RUN|  |  |  |  |  |  |   |WB|WT|WC|UC]
 [    0.000000] memblock_add: [0x00008000000000-0x00008001e7ffff] flags 0x0 early_init_dt_add_memory_arch+0x54/0x5c
 [    0.000000] *
 ...

Note the misplaced '*' line, which happened because the memblock debug message was printed while the EFI debug message was still being constructed..

This patch fixes the output to be the expected:

 [    0.000000] efi:   0x0000e1050000-0x0000e105ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
 [    0.000000] efi:   0x0000e1300000-0x0000e1300fff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
 [    0.000000] efi:   0x0000e8200000-0x0000e827ffff [Memory Mapped I/O  |RUN|  |  |  |  |  |  |   |  |  |  |UC]
 [    0.000000] efi:   0x008000000000-0x008001e7ffff [Runtime Data       |RUN|  |  |  |  |  |  |   |WB|WT|WC|UC]*
 [    0.000000] memblock_add: [0x00008000000000-0x00008001e7ffff] flags 0x0 early_init_dt_add_memory_arch+0x54/0x5c
 ...

Note how the '*' is now in the proper EFI debug message line.

Cc Ard Biesheuvel <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Dan Williams <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Mark Salter <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Steve Capper <[email protected]>
Cc Steve McIntyre <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Will Deacon <[email protected]>
[ Made the changelog more readable. ]
---
 drivers/firmware/efi/arm-init.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/firmware/efi/arm-init.c +6 -8
index a850cbc..c49d50e 100644
@@ -174,6 +174,7 @@ static __init void reserve_regions(void)
 {
 	efi_memory_desc_t *md;
 	u64 paddr, npages, size;
+	int resv;
 
 	if (efi_enabled(EFI_DBG))
 		pr_info("Processing EFI memory map:\n");
@@ -190,12 +191,14 @@ static __init void reserve_regions(void)
 		paddr = md->phys_addr;
 		npages = md->num_pages;
 
+		resv = is_reserve_region(md);
 		if (efi_enabled(EFI_DBG)) {
 			char buf[64];
 
-			pr_info("  0x%012llx-0x%012llx %s",
+			pr_info("  0x%012llx-0x%012llx %s%s\n",
 				paddr, paddr + (npages << EFI_PAGE_SHIFT) - 1,
-				efi_md_typeattr_format(buf, sizeof(buf), md));
+				efi_md_typeattr_format(buf, sizeof(buf), md),
+				resv ? "*" : "");
 		}
 
 		memrange_efi_to_native(&paddr, &npages);
@@ -204,14 +207,9 @@ static __init void reserve_regions(void)
 		if (is_normal_ram(md))
 			early_init_dt_add_memory_arch(paddr, size);
 
-		if (is_reserve_region(md)) {
+		if (resv)
 			memblock_mark_nomap(paddr, size);
-			if (efi_enabled(EFI_DBG))
-				pr_cont("*");
-		}
 
-		if (efi_enabled(EFI_DBG))
-			pr_cont("\n");
 	}
 
 	set_bit(EFI_MEMMAP, &efi.flags);
#5 lore raw
In reply to Matt Fleming
Quoted 26 lines · Matt Fleming

Folks, please pull the following urgent patches which fix a boot crash when using the "noefi" parameter and the debug output on arm.

The following changes since commit 1a695a905c18548062509178b98bc91e67510864:

Linux 4.7-rc1 (2016-05-29 09:29:24 -0700)

are available in the git repository at:

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

for you to fetch changes up to 1f0cf3892caeab20a99c19f5523499be77b533cd:

efi/arm: Fix the format of debug message from efi (2016-05-30 22:51:53 +0100)

----------------------------------------------------------------
* Fix crash when booting with the "noefi" kernel parameter, caused by recent changes to for_each_efi_memory_desc_in_map() - Vitaly Kuznetsov

* Unscramble the debug output on arm when efi=debug and memblock=debug is passed on the kernel cmdline - Dennis Chen

----------------------------------------------------------------
Dennis Chen (1):
efi/arm: Fix the format of debug message from efi

Quoted 6 lines

Vitaly Kuznetsov (1):
efi: Fix for_each_efi_memory_desc_in_map() for empty memmaps

 drivers/firmware/efi/arm-init.c | 14 ++++++--------
 include/linux/efi.h             |  2 +-
 2 files changed, 7 insertions(+), 9 deletions(-)

Ping? I see these patches queued up in tip/efi/urgent but they don't appear to be in Linus' tree yet.

#6 lore raw
Quoted 30 lines · Matt Fleming
Quoted 29 lines · Matt Fleming

Folks, please pull the following urgent patches which fix a boot crash when using the "noefi" parameter and the debug output on arm.

The following changes since commit 1a695a905c18548062509178b98bc91e67510864:

Linux 4.7-rc1 (2016-05-29 09:29:24 -0700)

are available in the git repository at:

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

for you to fetch changes up to 1f0cf3892caeab20a99c19f5523499be77b533cd:

efi/arm: Fix the format of debug message from efi (2016-05-30 22:51:53 +0100)

----------------------------------------------------------------
* Fix crash when booting with the "noefi" kernel parameter, caused by recent changes to for_each_efi_memory_desc_in_map() - Vitaly Kuznetsov

* Unscramble the debug output on arm when efi=debug and memblock=debug is passed on the kernel cmdline - Dennis Chen

----------------------------------------------------------------
Dennis Chen (1):
efi/arm: Fix the format of debug message from efi

Vitaly Kuznetsov (1):
efi: Fix for_each_efi_memory_desc_in_map() for empty memmaps

Quoted 6 lines
Quoted 3 lines
 drivers/firmware/efi/arm-init.c | 14 ++++++--------
 include/linux/efi.h             |  2 +-
 2 files changed, 7 insertions(+), 9 deletions(-)

Ping? I see these patches queued up in tip/efi/urgent but they don't appear to be in Linus' tree yet.

Yeah, will get them to Linus later today.

Thanks,

Ingo