linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] efi: Remove __efistub_global annotation
@ 2020-04-15 22:15 Arvind Sankar
  2020-04-15 22:15 ` [PATCH 1/5] efi/arm: " Arvind Sankar
                   ` (8 more replies)
  0 siblings, 9 replies; 16+ messages in thread
From: Arvind Sankar @ 2020-04-15 22:15 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, linux-arm-kernel, x86, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, linux-kernel

This patch series removes the need for annotating global data in the EFI
stub with __efistub_global for ARM32 and X86.

This is done by renaming the .data and .bss sections in the object files
linked into the EFI stub to .data.efistub and .bss.efistub respectively,
and including those sections into the compressed kernel's .data section
using its linker script.

The series is based on efi/next, rebased onto v5.7-rc1, plus two earlier
fixes for x86 EFI that are queued for v5.7.

Patches on top of v5.7-rc1:
In efi/next:

Ard Biesheuvel (2):
      efi: clean up config table description arrays
      efi: move arch_tables check to caller

Arvind Sankar (19):
      efi/gop: Remove redundant current_fb_base
      efi/gop: Move check for framebuffer before con_out
      efi/gop: Get mode information outside the loop
      efi/gop: Factor out locating the gop into a function
      efi/gop: Slightly re-arrange logic of find_gop
      efi/gop: Move variable declarations into loop block
      efi/gop: Use helper macros for populating lfb_base
      efi/gop: Use helper macros for find_bits
      efi/gop: Remove unreachable code from setup_pixel_info
      efi/gop: Add prototypes for query_mode and set_mode
      efi/gop: Allow specifying mode number on command line
      efi/gop: Allow specifying mode by <xres>x<yres>
      efi/gop: Allow specifying depth as well as resolution
      efi/gop: Allow automatically choosing the best mode

Additional:
Arvind Sankar (2):
      efi/x86: Move efi stub globals from .bss to .data
      efi/x86: Always relocate the kernel for EFI handover entry

Arvind Sankar (5):
  efi/arm: Remove __efistub_global annotation
  efi/libstub: Factor out relocation checking
  efi/x86: Remove __efistub_global annotation
  efi: Kill __efistub_global
  efi/x86: Check for bad relocations

 arch/arm/boot/compressed/vmlinux.lds.S        |  2 +-
 arch/x86/boot/compressed/vmlinux.lds.S        |  1 +
 drivers/firmware/efi/libstub/Makefile         | 43 +++++++++++++------
 drivers/firmware/efi/libstub/arm-stub.c       |  4 +-
 .../firmware/efi/libstub/efi-stub-helper.c    | 15 +++----
 drivers/firmware/efi/libstub/efistub.h        |  6 ---
 drivers/firmware/efi/libstub/gop.c            |  2 +-
 drivers/firmware/efi/libstub/x86-stub.c       |  2 +-
 8 files changed, 42 insertions(+), 33 deletions(-)

-- 
2.24.1


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

* [PATCH 1/5] efi/arm: Remove __efistub_global annotation
  2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
@ 2020-04-15 22:15 ` Arvind Sankar
  2020-04-16  7:50   ` Ard Biesheuvel
  2020-04-15 22:15 ` [PATCH 2/5] efi/libstub: Factor out relocation checking Arvind Sankar
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Arvind Sankar @ 2020-04-15 22:15 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, linux-arm-kernel, x86, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, linux-kernel

Instead of using __efistub_global to force variables into the .data
section, leave them in the .bss but pull the EFI stub's .bss section
into .data in the linker script for the compressed kernel.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 arch/arm/boot/compressed/vmlinux.lds.S | 2 +-
 drivers/firmware/efi/libstub/Makefile  | 7 ++++---
 drivers/firmware/efi/libstub/efistub.h | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boot/compressed/vmlinux.lds.S b/arch/arm/boot/compressed/vmlinux.lds.S
index b247f399de71..b6793c7932a9 100644
--- a/arch/arm/boot/compressed/vmlinux.lds.S
+++ b/arch/arm/boot/compressed/vmlinux.lds.S
@@ -78,7 +78,7 @@ SECTIONS
      * The EFI stub always executes from RAM, and runs strictly before the
      * decompressor, so we can make an exception for its r/w data, and keep it
      */
-    *(.data.efistub)
+    *(.data.efistub .bss.efistub)
     __pecoff_data_end = .;
 
     /*
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index 094eabdecfe6..45ffe0822df1 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -100,8 +100,9 @@ quiet_cmd_stubcopy = STUBCPY $@
 
 #
 # ARM discards the .data section because it disallows r/w data in the
-# decompressor. So move our .data to .data.efistub, which is preserved
-# explicitly by the decompressor linker script.
+# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
+# which are preserved explicitly by the decompressor linker script.
 #
-STUBCOPY_FLAGS-$(CONFIG_ARM)	+= --rename-section .data=.data.efistub
+STUBCOPY_FLAGS-$(CONFIG_ARM)	+= --rename-section .data=.data.efistub	\
+				   --rename-section .bss=.bss.efistub,load,alloc
 STUBCOPY_RELOC-$(CONFIG_ARM)	:= R_ARM_ABS
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index bd0b86b63936..a92d42ffd9f7 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -25,7 +25,7 @@
 #define EFI_ALLOC_ALIGN		EFI_PAGE_SIZE
 #endif
 
-#if defined(CONFIG_ARM) || defined(CONFIG_X86)
+#if defined(CONFIG_X86)
 #define __efistub_global	__section(.data)
 #else
 #define __efistub_global
-- 
2.24.1


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

* [PATCH 2/5] efi/libstub: Factor out relocation checking
  2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
  2020-04-15 22:15 ` [PATCH 1/5] efi/arm: " Arvind Sankar
@ 2020-04-15 22:15 ` Arvind Sankar
  2020-04-15 22:15 ` [PATCH 3/5] efi/x86: Remove __efistub_global annotation Arvind Sankar
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 16+ messages in thread
From: Arvind Sankar @ 2020-04-15 22:15 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, linux-arm-kernel, x86, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, linux-kernel

In preparation for using STUBCOPY for x86 as well, which doesn't require
relocation checking, move the checking code into its own variable so it
can be left out for x86.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 drivers/firmware/efi/libstub/Makefile | 30 ++++++++++++++++-----------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index 45ffe0822df1..e5e76677f2da 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -80,6 +80,15 @@ STUBCOPY_FLAGS-$(CONFIG_ARM64)	+= --prefix-alloc-sections=.init \
 				   --prefix-symbols=__efistub_
 STUBCOPY_RELOC-$(CONFIG_ARM64)	:= R_AARCH64_ABS
 
+#
+# ARM discards the .data section because it disallows r/w data in the
+# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
+# which are preserved explicitly by the decompressor linker script.
+#
+STUBCOPY_FLAGS-$(CONFIG_ARM)	+= --rename-section .data=.data.efistub	\
+				   --rename-section .bss=.bss.efistub,load,alloc
+STUBCOPY_RELOC-$(CONFIG_ARM)	:= R_ARM_ABS
+
 $(obj)/%.stub.o: $(obj)/%.o FORCE
 	$(call if_changed,stubcopy)
 
@@ -89,20 +98,17 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 # such relocations. If none are found, regenerate the output object, but
 # this time, use objcopy and leave all sections in place.
 #
-quiet_cmd_stubcopy = STUBCPY $@
-      cmd_stubcopy =							\
+
+cmd_stubrelocs_check-y = /bin/true
+
+cmd_stubrelocs_check-$(CONFIG_EFI_ARMSTUB) =				\
 	$(STRIP) --strip-debug -o $@ $<;				\
 	if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then		\
 		echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \
 		/bin/false;						\
-	fi;								\
-	$(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@
+	fi
 
-#
-# ARM discards the .data section because it disallows r/w data in the
-# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
-# which are preserved explicitly by the decompressor linker script.
-#
-STUBCOPY_FLAGS-$(CONFIG_ARM)	+= --rename-section .data=.data.efistub	\
-				   --rename-section .bss=.bss.efistub,load,alloc
-STUBCOPY_RELOC-$(CONFIG_ARM)	:= R_ARM_ABS
+quiet_cmd_stubcopy = STUBCPY $@
+      cmd_stubcopy =							\
+	$(cmd_stubrelocs_check-y);					\
+	$(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@
-- 
2.24.1


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

* [PATCH 3/5] efi/x86: Remove __efistub_global annotation
  2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
  2020-04-15 22:15 ` [PATCH 1/5] efi/arm: " Arvind Sankar
  2020-04-15 22:15 ` [PATCH 2/5] efi/libstub: Factor out relocation checking Arvind Sankar
@ 2020-04-15 22:15 ` Arvind Sankar
  2020-04-16  7:51   ` Ard Biesheuvel
  2020-04-15 22:15 ` [PATCH 4/5] efi: Kill __efistub_global Arvind Sankar
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Arvind Sankar @ 2020-04-15 22:15 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, linux-arm-kernel, x86, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, linux-kernel

Instead of using __efistub_global to force variables into the .data
section, leave them in the .bss but pull the EFI stub's .bss section
into .data in the linker script for the compressed kernel.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 arch/x86/boot/compressed/vmlinux.lds.S |  1 +
 drivers/firmware/efi/libstub/Makefile  | 12 ++++++++++--
 drivers/firmware/efi/libstub/efistub.h |  4 ----
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S
index 508cfa6828c5..0dc5c2b9614b 100644
--- a/arch/x86/boot/compressed/vmlinux.lds.S
+++ b/arch/x86/boot/compressed/vmlinux.lds.S
@@ -52,6 +52,7 @@ SECTIONS
 		_data = . ;
 		*(.data)
 		*(.data.*)
+		*(.bss.efistub)
 		_edata = . ;
 	}
 	. = ALIGN(L1_CACHE_BYTES);
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index e5e76677f2da..0bb2916eb12b 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -73,8 +73,8 @@ CFLAGS_arm64-stub.o		:= -DTEXT_OFFSET=$(TEXT_OFFSET)
 # a verification pass to see if any absolute relocations exist in any of the
 # object files.
 #
-extra-$(CONFIG_EFI_ARMSTUB)	:= $(lib-y)
-lib-$(CONFIG_EFI_ARMSTUB)	:= $(patsubst %.o,%.stub.o,$(lib-y))
+extra-y	:= $(lib-y)
+lib-y	:= $(patsubst %.o,%.stub.o,$(lib-y))
 
 STUBCOPY_FLAGS-$(CONFIG_ARM64)	+= --prefix-alloc-sections=.init \
 				   --prefix-symbols=__efistub_
@@ -89,6 +89,14 @@ STUBCOPY_FLAGS-$(CONFIG_ARM)	+= --rename-section .data=.data.efistub	\
 				   --rename-section .bss=.bss.efistub,load,alloc
 STUBCOPY_RELOC-$(CONFIG_ARM)	:= R_ARM_ABS
 
+#
+# For x86, bootloaders like systemd-boot or grub-efi do not zero-initialize the
+# .bss section, so the .bss section of the EFI stub needs to be included in the
+# .data section of the compressed kernel to ensure initialization. Rename the
+# .bss section here so it's easy to pick out in the linker script.
+#
+STUBCOPY_FLAGS-$(CONFIG_X86)	+= --rename-section .bss=.bss.efistub,load,alloc
+
 $(obj)/%.stub.o: $(obj)/%.o FORCE
 	$(call if_changed,stubcopy)
 
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index a92d42ffd9f7..49651e20bb9f 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -25,11 +25,7 @@
 #define EFI_ALLOC_ALIGN		EFI_PAGE_SIZE
 #endif
 
-#if defined(CONFIG_X86)
-#define __efistub_global	__section(.data)
-#else
 #define __efistub_global
-#endif
 
 extern bool __pure nochunk(void);
 extern bool __pure nokaslr(void);
-- 
2.24.1


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

* [PATCH 4/5] efi: Kill __efistub_global
  2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
                   ` (2 preceding siblings ...)
  2020-04-15 22:15 ` [PATCH 3/5] efi/x86: Remove __efistub_global annotation Arvind Sankar
@ 2020-04-15 22:15 ` Arvind Sankar
  2020-04-16  7:51   ` Ard Biesheuvel
  2020-04-15 22:15 ` [PATCH 5/5] efi/x86: Check for bad relocations Arvind Sankar
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Arvind Sankar @ 2020-04-15 22:15 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, linux-arm-kernel, x86, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, linux-kernel

Now that both arm and x86 are using the linker script to place the EFI
stub's global variables in the correct section, remove __efistub_global.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 drivers/firmware/efi/libstub/arm-stub.c        |  4 ++--
 drivers/firmware/efi/libstub/efi-stub-helper.c | 15 +++++++--------
 drivers/firmware/efi/libstub/efistub.h         |  2 --
 drivers/firmware/efi/libstub/gop.c             |  2 +-
 drivers/firmware/efi/libstub/x86-stub.c        |  2 +-
 5 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
index 99a5cde7c2d8..bf42d6c742a8 100644
--- a/drivers/firmware/efi/libstub/arm-stub.c
+++ b/drivers/firmware/efi/libstub/arm-stub.c
@@ -36,9 +36,9 @@
 #endif
 
 static u64 virtmap_base = EFI_RT_VIRTUAL_BASE;
-static bool __efistub_global flat_va_mapping;
+static bool flat_va_mapping;
 
-static efi_system_table_t *__efistub_global sys_table;
+static efi_system_table_t *sys_table;
 
 __pure efi_system_table_t *efi_system_table(void)
 {
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index c6092b6038cf..14e56a64f208 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -12,14 +12,13 @@
 
 #include "efistub.h"
 
-static bool __efistub_global efi_nochunk;
-static bool __efistub_global efi_nokaslr;
-static bool __efistub_global efi_noinitrd;
-static bool __efistub_global efi_quiet;
-static bool __efistub_global efi_novamap;
-static bool __efistub_global efi_nosoftreserve;
-static bool __efistub_global efi_disable_pci_dma =
-					IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA);
+static bool efi_nochunk;
+static bool efi_nokaslr;
+static bool efi_noinitrd;
+static bool efi_quiet;
+static bool efi_novamap;
+static bool efi_nosoftreserve;
+static bool efi_disable_pci_dma = IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA);
 
 bool __pure nochunk(void)
 {
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 49651e20bb9f..f96c56596034 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -25,8 +25,6 @@
 #define EFI_ALLOC_ALIGN		EFI_PAGE_SIZE
 #endif
 
-#define __efistub_global
-
 extern bool __pure nochunk(void);
 extern bool __pure nokaslr(void);
 extern bool __pure noinitrd(void);
diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c
index fa05a0b0adfd..216327d0b034 100644
--- a/drivers/firmware/efi/libstub/gop.c
+++ b/drivers/firmware/efi/libstub/gop.c
@@ -32,7 +32,7 @@ static struct {
 			u8 depth;
 		} res;
 	};
-} cmdline __efistub_global = { .option = EFI_CMDLINE_NONE };
+} cmdline = { .option = EFI_CMDLINE_NONE };
 
 static bool parse_modenum(char *option, char **next)
 {
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 7583e908852f..aedac3af4b5c 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -20,7 +20,7 @@
 /* Maximum physical address for 64-bit kernel with 4-level paging */
 #define MAXMEM_X86_64_4LEVEL (1ull << 46)
 
-static efi_system_table_t *sys_table __efistub_global;
+static efi_system_table_t *sys_table;
 extern const bool efi_is64;
 extern u32 image_offset;
 
-- 
2.24.1


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

* [PATCH 5/5] efi/x86: Check for bad relocations
  2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
                   ` (3 preceding siblings ...)
  2020-04-15 22:15 ` [PATCH 4/5] efi: Kill __efistub_global Arvind Sankar
@ 2020-04-15 22:15 ` Arvind Sankar
  2020-04-16  7:38   ` Ard Biesheuvel
  2020-04-16 15:12 ` [PATCH v2 0/3] efi: Remove __efistub_global annotation Arvind Sankar
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Arvind Sankar @ 2020-04-15 22:15 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: linux-efi, linux-arm-kernel, x86, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, linux-kernel

Add relocation checking for x86 as well to catch non-PC-relative
relocations that require runtime processing, since the EFI stub does not
do any runtime relocation processing.

This will catch, for example, data relocations created by static
initializers of pointers.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 drivers/firmware/efi/libstub/Makefile | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index 0bb2916eb12b..2aff59812a54 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -96,6 +96,8 @@ STUBCOPY_RELOC-$(CONFIG_ARM)	:= R_ARM_ABS
 # .bss section here so it's easy to pick out in the linker script.
 #
 STUBCOPY_FLAGS-$(CONFIG_X86)	+= --rename-section .bss=.bss.efistub,load,alloc
+STUBCOPY_RELOC-$(CONFIG_X86_32) := 'R_X86_32_(8|16|32)'
+STUBCOPY_RELOC-$(CONFIG_X86_64) := 'R_X86_64_(8|16|32|32S|64)'
 
 $(obj)/%.stub.o: $(obj)/%.o FORCE
 	$(call if_changed,stubcopy)
@@ -107,16 +109,14 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
 # this time, use objcopy and leave all sections in place.
 #
 
-cmd_stubrelocs_check-y = /bin/true
-
-cmd_stubrelocs_check-$(CONFIG_EFI_ARMSTUB) =				\
+cmd_stubrelocs_check =							\
 	$(STRIP) --strip-debug -o $@ $<;				\
-	if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then		\
+	if $(OBJDUMP) -r $@ | grep -E $(STUBCOPY_RELOC-y); then		\
 		echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \
 		/bin/false;						\
 	fi
 
 quiet_cmd_stubcopy = STUBCPY $@
       cmd_stubcopy =							\
-	$(cmd_stubrelocs_check-y);					\
+	$(cmd_stubrelocs_check);					\
 	$(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@
-- 
2.24.1


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

* Re: [PATCH 5/5] efi/x86: Check for bad relocations
  2020-04-15 22:15 ` [PATCH 5/5] efi/x86: Check for bad relocations Arvind Sankar
@ 2020-04-16  7:38   ` Ard Biesheuvel
  2020-04-16 14:48     ` Arvind Sankar
  0 siblings, 1 reply; 16+ messages in thread
From: Ard Biesheuvel @ 2020-04-16  7:38 UTC (permalink / raw)
  To: Arvind Sankar
  Cc: linux-efi, Linux ARM, X86 ML, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Linux Kernel Mailing List

On Thu, 16 Apr 2020 at 00:15, Arvind Sankar <nivedita@alum.mit.edu> wrote:
>
> Add relocation checking for x86 as well to catch non-PC-relative
> relocations that require runtime processing, since the EFI stub does not
> do any runtime relocation processing.
>
> This will catch, for example, data relocations created by static
> initializers of pointers.
>
> Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
> ---
>  drivers/firmware/efi/libstub/Makefile | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
> index 0bb2916eb12b..2aff59812a54 100644
> --- a/drivers/firmware/efi/libstub/Makefile
> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -96,6 +96,8 @@ STUBCOPY_RELOC-$(CONFIG_ARM)  := R_ARM_ABS
>  # .bss section here so it's easy to pick out in the linker script.
>  #
>  STUBCOPY_FLAGS-$(CONFIG_X86)   += --rename-section .bss=.bss.efistub,load,alloc
> +STUBCOPY_RELOC-$(CONFIG_X86_32) := 'R_X86_32_(8|16|32)'

This should be R_386_xxx

> +STUBCOPY_RELOC-$(CONFIG_X86_64) := 'R_X86_64_(8|16|32|32S|64)'
>

... and in general, I think we only need the native pointer sized ones, so

R_386_32
R_X86_64_64

>  $(obj)/%.stub.o: $(obj)/%.o FORCE
>         $(call if_changed,stubcopy)
> @@ -107,16 +109,14 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
>  # this time, use objcopy and leave all sections in place.
>  #
>
> -cmd_stubrelocs_check-y = /bin/true
> -
> -cmd_stubrelocs_check-$(CONFIG_EFI_ARMSTUB) =                           \
> +cmd_stubrelocs_check =                                                 \
>         $(STRIP) --strip-debug -o $@ $<;                                \
> -       if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then            \
> +       if $(OBJDUMP) -r $@ | grep -E $(STUBCOPY_RELOC-y); then         \

... which means we don't need to -E either

>                 echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \
>                 /bin/false;                                             \
>         fi
>
>  quiet_cmd_stubcopy = STUBCPY $@
>        cmd_stubcopy =                                                   \
> -       $(cmd_stubrelocs_check-y);                                      \
> +       $(cmd_stubrelocs_check);                                        \
>         $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@
> --
> 2.24.1
>

Could we fold this into the previous x86 patch, and drop the one that
splits off the relocation check from stubcpy?

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

* Re: [PATCH 1/5] efi/arm: Remove __efistub_global annotation
  2020-04-15 22:15 ` [PATCH 1/5] efi/arm: " Arvind Sankar
@ 2020-04-16  7:50   ` Ard Biesheuvel
  0 siblings, 0 replies; 16+ messages in thread
From: Ard Biesheuvel @ 2020-04-16  7:50 UTC (permalink / raw)
  To: Arvind Sankar
  Cc: linux-efi, Linux ARM, X86 ML, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Linux Kernel Mailing List

On Thu, 16 Apr 2020 at 00:15, Arvind Sankar <nivedita@alum.mit.edu> wrote:
>
> Instead of using __efistub_global to force variables into the .data
> section, leave them in the .bss but pull the EFI stub's .bss section
> into .data in the linker script for the compressed kernel.
>
> Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  arch/arm/boot/compressed/vmlinux.lds.S | 2 +-
>  drivers/firmware/efi/libstub/Makefile  | 7 ++++---
>  drivers/firmware/efi/libstub/efistub.h | 2 +-
>  3 files changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/arch/arm/boot/compressed/vmlinux.lds.S b/arch/arm/boot/compressed/vmlinux.lds.S
> index b247f399de71..b6793c7932a9 100644
> --- a/arch/arm/boot/compressed/vmlinux.lds.S
> +++ b/arch/arm/boot/compressed/vmlinux.lds.S
> @@ -78,7 +78,7 @@ SECTIONS
>       * The EFI stub always executes from RAM, and runs strictly before the
>       * decompressor, so we can make an exception for its r/w data, and keep it
>       */
> -    *(.data.efistub)
> +    *(.data.efistub .bss.efistub)
>      __pecoff_data_end = .;
>
>      /*
> diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
> index 094eabdecfe6..45ffe0822df1 100644
> --- a/drivers/firmware/efi/libstub/Makefile
> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -100,8 +100,9 @@ quiet_cmd_stubcopy = STUBCPY $@
>
>  #
>  # ARM discards the .data section because it disallows r/w data in the
> -# decompressor. So move our .data to .data.efistub, which is preserved
> -# explicitly by the decompressor linker script.
> +# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
> +# which are preserved explicitly by the decompressor linker script.
>  #
> -STUBCOPY_FLAGS-$(CONFIG_ARM)   += --rename-section .data=.data.efistub
> +STUBCOPY_FLAGS-$(CONFIG_ARM)   += --rename-section .data=.data.efistub \
> +                                  --rename-section .bss=.bss.efistub,load,alloc
>  STUBCOPY_RELOC-$(CONFIG_ARM)   := R_ARM_ABS
> diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
> index bd0b86b63936..a92d42ffd9f7 100644
> --- a/drivers/firmware/efi/libstub/efistub.h
> +++ b/drivers/firmware/efi/libstub/efistub.h
> @@ -25,7 +25,7 @@
>  #define EFI_ALLOC_ALIGN                EFI_PAGE_SIZE
>  #endif
>
> -#if defined(CONFIG_ARM) || defined(CONFIG_X86)
> +#if defined(CONFIG_X86)
>  #define __efistub_global       __section(.data)
>  #else
>  #define __efistub_global
> --
> 2.24.1
>

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

* Re: [PATCH 3/5] efi/x86: Remove __efistub_global annotation
  2020-04-15 22:15 ` [PATCH 3/5] efi/x86: Remove __efistub_global annotation Arvind Sankar
@ 2020-04-16  7:51   ` Ard Biesheuvel
  0 siblings, 0 replies; 16+ messages in thread
From: Ard Biesheuvel @ 2020-04-16  7:51 UTC (permalink / raw)
  To: Arvind Sankar
  Cc: linux-efi, Linux ARM, X86 ML, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Linux Kernel Mailing List

On Thu, 16 Apr 2020 at 00:15, Arvind Sankar <nivedita@alum.mit.edu> wrote:
>
> Instead of using __efistub_global to force variables into the .data
> section, leave them in the .bss but pull the EFI stub's .bss section
> into .data in the linker script for the compressed kernel.
>
> Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>

With the R_386_32/R_X86_64_64 check folded in:

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  arch/x86/boot/compressed/vmlinux.lds.S |  1 +
>  drivers/firmware/efi/libstub/Makefile  | 12 ++++++++++--
>  drivers/firmware/efi/libstub/efistub.h |  4 ----
>  3 files changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S
> index 508cfa6828c5..0dc5c2b9614b 100644
> --- a/arch/x86/boot/compressed/vmlinux.lds.S
> +++ b/arch/x86/boot/compressed/vmlinux.lds.S
> @@ -52,6 +52,7 @@ SECTIONS
>                 _data = . ;
>                 *(.data)
>                 *(.data.*)
> +               *(.bss.efistub)
>                 _edata = . ;
>         }
>         . = ALIGN(L1_CACHE_BYTES);
> diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
> index e5e76677f2da..0bb2916eb12b 100644
> --- a/drivers/firmware/efi/libstub/Makefile
> +++ b/drivers/firmware/efi/libstub/Makefile
> @@ -73,8 +73,8 @@ CFLAGS_arm64-stub.o           := -DTEXT_OFFSET=$(TEXT_OFFSET)
>  # a verification pass to see if any absolute relocations exist in any of the
>  # object files.
>  #
> -extra-$(CONFIG_EFI_ARMSTUB)    := $(lib-y)
> -lib-$(CONFIG_EFI_ARMSTUB)      := $(patsubst %.o,%.stub.o,$(lib-y))
> +extra-y        := $(lib-y)
> +lib-y  := $(patsubst %.o,%.stub.o,$(lib-y))
>
>  STUBCOPY_FLAGS-$(CONFIG_ARM64) += --prefix-alloc-sections=.init \
>                                    --prefix-symbols=__efistub_
> @@ -89,6 +89,14 @@ STUBCOPY_FLAGS-$(CONFIG_ARM) += --rename-section .data=.data.efistub \
>                                    --rename-section .bss=.bss.efistub,load,alloc
>  STUBCOPY_RELOC-$(CONFIG_ARM)   := R_ARM_ABS
>
> +#
> +# For x86, bootloaders like systemd-boot or grub-efi do not zero-initialize the
> +# .bss section, so the .bss section of the EFI stub needs to be included in the
> +# .data section of the compressed kernel to ensure initialization. Rename the
> +# .bss section here so it's easy to pick out in the linker script.
> +#
> +STUBCOPY_FLAGS-$(CONFIG_X86)   += --rename-section .bss=.bss.efistub,load,alloc
> +
>  $(obj)/%.stub.o: $(obj)/%.o FORCE
>         $(call if_changed,stubcopy)
>
> diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
> index a92d42ffd9f7..49651e20bb9f 100644
> --- a/drivers/firmware/efi/libstub/efistub.h
> +++ b/drivers/firmware/efi/libstub/efistub.h
> @@ -25,11 +25,7 @@
>  #define EFI_ALLOC_ALIGN                EFI_PAGE_SIZE
>  #endif
>
> -#if defined(CONFIG_X86)
> -#define __efistub_global       __section(.data)
> -#else
>  #define __efistub_global
> -#endif
>
>  extern bool __pure nochunk(void);
>  extern bool __pure nokaslr(void);
> --
> 2.24.1
>

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

* Re: [PATCH 4/5] efi: Kill __efistub_global
  2020-04-15 22:15 ` [PATCH 4/5] efi: Kill __efistub_global Arvind Sankar
@ 2020-04-16  7:51   ` Ard Biesheuvel
  0 siblings, 0 replies; 16+ messages in thread
From: Ard Biesheuvel @ 2020-04-16  7:51 UTC (permalink / raw)
  To: Arvind Sankar
  Cc: linux-efi, Linux ARM, X86 ML, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Linux Kernel Mailing List

On Thu, 16 Apr 2020 at 00:15, Arvind Sankar <nivedita@alum.mit.edu> wrote:
>
> Now that both arm and x86 are using the linker script to place the EFI
> stub's global variables in the correct section, remove __efistub_global.
>
> Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  drivers/firmware/efi/libstub/arm-stub.c        |  4 ++--
>  drivers/firmware/efi/libstub/efi-stub-helper.c | 15 +++++++--------
>  drivers/firmware/efi/libstub/efistub.h         |  2 --
>  drivers/firmware/efi/libstub/gop.c             |  2 +-
>  drivers/firmware/efi/libstub/x86-stub.c        |  2 +-
>  5 files changed, 11 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
> index 99a5cde7c2d8..bf42d6c742a8 100644
> --- a/drivers/firmware/efi/libstub/arm-stub.c
> +++ b/drivers/firmware/efi/libstub/arm-stub.c
> @@ -36,9 +36,9 @@
>  #endif
>
>  static u64 virtmap_base = EFI_RT_VIRTUAL_BASE;
> -static bool __efistub_global flat_va_mapping;
> +static bool flat_va_mapping;
>
> -static efi_system_table_t *__efistub_global sys_table;
> +static efi_system_table_t *sys_table;
>
>  __pure efi_system_table_t *efi_system_table(void)
>  {
> diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
> index c6092b6038cf..14e56a64f208 100644
> --- a/drivers/firmware/efi/libstub/efi-stub-helper.c
> +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
> @@ -12,14 +12,13 @@
>
>  #include "efistub.h"
>
> -static bool __efistub_global efi_nochunk;
> -static bool __efistub_global efi_nokaslr;
> -static bool __efistub_global efi_noinitrd;
> -static bool __efistub_global efi_quiet;
> -static bool __efistub_global efi_novamap;
> -static bool __efistub_global efi_nosoftreserve;
> -static bool __efistub_global efi_disable_pci_dma =
> -                                       IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA);
> +static bool efi_nochunk;
> +static bool efi_nokaslr;
> +static bool efi_noinitrd;
> +static bool efi_quiet;
> +static bool efi_novamap;
> +static bool efi_nosoftreserve;
> +static bool efi_disable_pci_dma = IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA);
>
>  bool __pure nochunk(void)
>  {
> diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
> index 49651e20bb9f..f96c56596034 100644
> --- a/drivers/firmware/efi/libstub/efistub.h
> +++ b/drivers/firmware/efi/libstub/efistub.h
> @@ -25,8 +25,6 @@
>  #define EFI_ALLOC_ALIGN                EFI_PAGE_SIZE
>  #endif
>
> -#define __efistub_global
> -
>  extern bool __pure nochunk(void);
>  extern bool __pure nokaslr(void);
>  extern bool __pure noinitrd(void);
> diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c
> index fa05a0b0adfd..216327d0b034 100644
> --- a/drivers/firmware/efi/libstub/gop.c
> +++ b/drivers/firmware/efi/libstub/gop.c
> @@ -32,7 +32,7 @@ static struct {
>                         u8 depth;
>                 } res;
>         };
> -} cmdline __efistub_global = { .option = EFI_CMDLINE_NONE };
> +} cmdline = { .option = EFI_CMDLINE_NONE };
>
>  static bool parse_modenum(char *option, char **next)
>  {
> diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
> index 7583e908852f..aedac3af4b5c 100644
> --- a/drivers/firmware/efi/libstub/x86-stub.c
> +++ b/drivers/firmware/efi/libstub/x86-stub.c
> @@ -20,7 +20,7 @@
>  /* Maximum physical address for 64-bit kernel with 4-level paging */
>  #define MAXMEM_X86_64_4LEVEL (1ull << 46)
>
> -static efi_system_table_t *sys_table __efistub_global;
> +static efi_system_table_t *sys_table;
>  extern const bool efi_is64;
>  extern u32 image_offset;
>
> --
> 2.24.1
>

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

* Re: [PATCH 5/5] efi/x86: Check for bad relocations
  2020-04-16  7:38   ` Ard Biesheuvel
@ 2020-04-16 14:48     ` Arvind Sankar
  0 siblings, 0 replies; 16+ messages in thread
From: Arvind Sankar @ 2020-04-16 14:48 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Arvind Sankar, linux-efi, Linux ARM, X86 ML, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, Linux Kernel Mailing List

On Thu, Apr 16, 2020 at 09:38:36AM +0200, Ard Biesheuvel wrote:
> On Thu, 16 Apr 2020 at 00:15, Arvind Sankar <nivedita@alum.mit.edu> wrote:
> >
> > Add relocation checking for x86 as well to catch non-PC-relative
> > relocations that require runtime processing, since the EFI stub does not
> > do any runtime relocation processing.
> >
> > This will catch, for example, data relocations created by static
> > initializers of pointers.
> >
> > Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
> > ---
> >  drivers/firmware/efi/libstub/Makefile | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
> > index 0bb2916eb12b..2aff59812a54 100644
> > --- a/drivers/firmware/efi/libstub/Makefile
> > +++ b/drivers/firmware/efi/libstub/Makefile
> > @@ -96,6 +96,8 @@ STUBCOPY_RELOC-$(CONFIG_ARM)  := R_ARM_ABS
> >  # .bss section here so it's easy to pick out in the linker script.
> >  #
> >  STUBCOPY_FLAGS-$(CONFIG_X86)   += --rename-section .bss=.bss.efistub,load,alloc
> > +STUBCOPY_RELOC-$(CONFIG_X86_32) := 'R_X86_32_(8|16|32)'
> 
> This should be R_386_xxx

Oops. I tested 64-bit but not 32-bit. I'll fix.

> 
> > +STUBCOPY_RELOC-$(CONFIG_X86_64) := 'R_X86_64_(8|16|32|32S|64)'
> >
> 
> ... and in general, I think we only need the native pointer sized ones, so
> 
> R_386_32
> R_X86_64_64

Ok.

> 
> >  $(obj)/%.stub.o: $(obj)/%.o FORCE
> >         $(call if_changed,stubcopy)
> > @@ -107,16 +109,14 @@ $(obj)/%.stub.o: $(obj)/%.o FORCE
> >  # this time, use objcopy and leave all sections in place.
> >  #
> >
> > -cmd_stubrelocs_check-y = /bin/true
> > -
> > -cmd_stubrelocs_check-$(CONFIG_EFI_ARMSTUB) =                           \
> > +cmd_stubrelocs_check =                                                 \
> >         $(STRIP) --strip-debug -o $@ $<;                                \
> > -       if $(OBJDUMP) -r $@ | grep $(STUBCOPY_RELOC-y); then            \
> > +       if $(OBJDUMP) -r $@ | grep -E $(STUBCOPY_RELOC-y); then         \
> 
> ... which means we don't need to -E either
> 
> >                 echo "$@: absolute symbol references not allowed in the EFI stub" >&2; \
> >                 /bin/false;                                             \
> >         fi
> >
> >  quiet_cmd_stubcopy = STUBCPY $@
> >        cmd_stubcopy =                                                   \
> > -       $(cmd_stubrelocs_check-y);                                      \
> > +       $(cmd_stubrelocs_check);                                        \
> >         $(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@
> > --
> > 2.24.1
> >
> 
> Could we fold this into the previous x86 patch, and drop the one that
> splits off the relocation check from stubcpy?

Will do.

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

* [PATCH v2 0/3] efi: Remove __efistub_global annotation
  2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
                   ` (4 preceding siblings ...)
  2020-04-15 22:15 ` [PATCH 5/5] efi/x86: Check for bad relocations Arvind Sankar
@ 2020-04-16 15:12 ` Arvind Sankar
  2020-04-16 16:01   ` Ard Biesheuvel
  2020-04-16 15:12 ` [PATCH v2 1/3] efi/arm: " Arvind Sankar
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 16+ messages in thread
From: Arvind Sankar @ 2020-04-16 15:12 UTC (permalink / raw)
  To: Arvind Sankar
  Cc: Ard Biesheuvel, linux-efi, linux-arm-kernel, x86,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, linux-kernel

This patch series removes the need for annotating global data in the EFI
stub with __efistub_global for ARM32 and X86.

This is done by renaming the .data and .bss sections in the object files
linked into the EFI stub to .data.efistub and .bss.efistub respectively,
and including those sections into the compressed kernel's .data section
using its linker script.

Changes from v1:
- drop patch 2 and squash patches 3 and 5 for x86
- fix R_X86 -> R_386
- only check native relocation size (32-bit for R386 and 64-bit for
  RX86_64)

The series is based on efi/next, rebased onto v5.7-rc1, plus two earlier
fixes for x86 EFI that are queued for v5.7.

Patches on top of v5.7-rc1:
In efi/next:

Ard Biesheuvel (2):
      efi: clean up config table description arrays
      efi: move arch_tables check to caller

Arvind Sankar (19):
      efi/gop: Remove redundant current_fb_base
      efi/gop: Move check for framebuffer before con_out
      efi/gop: Get mode information outside the loop
      efi/gop: Factor out locating the gop into a function
      efi/gop: Slightly re-arrange logic of find_gop
      efi/gop: Move variable declarations into loop block
      efi/gop: Use helper macros for populating lfb_base
      efi/gop: Use helper macros for find_bits
      efi/gop: Remove unreachable code from setup_pixel_info
      efi/gop: Add prototypes for query_mode and set_mode
      efi/gop: Allow specifying mode number on command line
      efi/gop: Allow specifying mode by <xres>x<yres>
      efi/gop: Allow specifying depth as well as resolution
      efi/gop: Allow automatically choosing the best mode

Additional:
Arvind Sankar (2):
      efi/x86: Move efi stub globals from .bss to .data
      efi/x86: Always relocate the kernel for EFI handover entry

Arvind Sankar (3):
  efi/arm: Remove __efistub_global annotation
  efi/x86: Remove __efistub_global and add relocation check
  efi: Kill __efistub_global

 arch/arm/boot/compressed/vmlinux.lds.S        |  2 +-
 arch/x86/boot/compressed/vmlinux.lds.S        |  1 +
 drivers/firmware/efi/libstub/Makefile         | 31 +++++++++++++------
 drivers/firmware/efi/libstub/arm-stub.c       |  4 +--
 .../firmware/efi/libstub/efi-stub-helper.c    | 15 +++++----
 drivers/firmware/efi/libstub/efistub.h        |  6 ----
 drivers/firmware/efi/libstub/gop.c            |  2 +-
 drivers/firmware/efi/libstub/x86-stub.c       |  2 +-
 8 files changed, 34 insertions(+), 29 deletions(-)

-- 
2.25.3


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

* [PATCH v2 1/3] efi/arm: Remove __efistub_global annotation
  2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
                   ` (5 preceding siblings ...)
  2020-04-16 15:12 ` [PATCH v2 0/3] efi: Remove __efistub_global annotation Arvind Sankar
@ 2020-04-16 15:12 ` Arvind Sankar
  2020-04-16 15:12 ` [PATCH v2 2/3] efi/x86: Remove __efistub_global and add relocation check Arvind Sankar
  2020-04-16 15:12 ` [PATCH v2 3/3] efi: Kill __efistub_global Arvind Sankar
  8 siblings, 0 replies; 16+ messages in thread
From: Arvind Sankar @ 2020-04-16 15:12 UTC (permalink / raw)
  To: Arvind Sankar
  Cc: Ard Biesheuvel, linux-efi, linux-arm-kernel, x86,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, linux-kernel

Instead of using __efistub_global to force variables into the .data
section, leave them in the .bss but pull the EFI stub's .bss section
into .data in the linker script for the compressed kernel.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm/boot/compressed/vmlinux.lds.S | 2 +-
 drivers/firmware/efi/libstub/Makefile  | 7 ++++---
 drivers/firmware/efi/libstub/efistub.h | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boot/compressed/vmlinux.lds.S b/arch/arm/boot/compressed/vmlinux.lds.S
index b247f399de71..b6793c7932a9 100644
--- a/arch/arm/boot/compressed/vmlinux.lds.S
+++ b/arch/arm/boot/compressed/vmlinux.lds.S
@@ -78,7 +78,7 @@ SECTIONS
      * The EFI stub always executes from RAM, and runs strictly before the
      * decompressor, so we can make an exception for its r/w data, and keep it
      */
-    *(.data.efistub)
+    *(.data.efistub .bss.efistub)
     __pecoff_data_end = .;
 
     /*
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index 094eabdecfe6..45ffe0822df1 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -100,8 +100,9 @@ quiet_cmd_stubcopy = STUBCPY $@
 
 #
 # ARM discards the .data section because it disallows r/w data in the
-# decompressor. So move our .data to .data.efistub, which is preserved
-# explicitly by the decompressor linker script.
+# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
+# which are preserved explicitly by the decompressor linker script.
 #
-STUBCOPY_FLAGS-$(CONFIG_ARM)	+= --rename-section .data=.data.efistub
+STUBCOPY_FLAGS-$(CONFIG_ARM)	+= --rename-section .data=.data.efistub	\
+				   --rename-section .bss=.bss.efistub,load,alloc
 STUBCOPY_RELOC-$(CONFIG_ARM)	:= R_ARM_ABS
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index bd0b86b63936..a92d42ffd9f7 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -25,7 +25,7 @@
 #define EFI_ALLOC_ALIGN		EFI_PAGE_SIZE
 #endif
 
-#if defined(CONFIG_ARM) || defined(CONFIG_X86)
+#if defined(CONFIG_X86)
 #define __efistub_global	__section(.data)
 #else
 #define __efistub_global
-- 
2.25.3


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

* [PATCH v2 2/3] efi/x86: Remove __efistub_global and add relocation check
  2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
                   ` (6 preceding siblings ...)
  2020-04-16 15:12 ` [PATCH v2 1/3] efi/arm: " Arvind Sankar
@ 2020-04-16 15:12 ` Arvind Sankar
  2020-04-16 15:12 ` [PATCH v2 3/3] efi: Kill __efistub_global Arvind Sankar
  8 siblings, 0 replies; 16+ messages in thread
From: Arvind Sankar @ 2020-04-16 15:12 UTC (permalink / raw)
  To: Arvind Sankar
  Cc: Ard Biesheuvel, linux-efi, linux-arm-kernel, x86,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, linux-kernel

Instead of using __efistub_global to force variables into the .data
section, leave them in the .bss but pull the EFI stub's .bss section
into .data in the linker script for the compressed kernel.

Add relocation checking for x86 as well to catch non-PC-relative
relocations that require runtime processing, since the EFI stub does not
do any runtime relocation processing.

This will catch, for example, data relocations created by static
initializers of pointers.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
---
 arch/x86/boot/compressed/vmlinux.lds.S |  1 +
 drivers/firmware/efi/libstub/Makefile  | 32 +++++++++++++++++---------
 drivers/firmware/efi/libstub/efistub.h |  4 ----
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/arch/x86/boot/compressed/vmlinux.lds.S b/arch/x86/boot/compressed/vmlinux.lds.S
index 508cfa6828c5..0dc5c2b9614b 100644
--- a/arch/x86/boot/compressed/vmlinux.lds.S
+++ b/arch/x86/boot/compressed/vmlinux.lds.S
@@ -52,6 +52,7 @@ SECTIONS
 		_data = . ;
 		*(.data)
 		*(.data.*)
+		*(.bss.efistub)
 		_edata = . ;
 	}
 	. = ALIGN(L1_CACHE_BYTES);
diff --git a/drivers/firmware/efi/libstub/Makefile b/drivers/firmware/efi/libstub/Makefile
index 45ffe0822df1..069d117d5451 100644
--- a/drivers/firmware/efi/libstub/Makefile
+++ b/drivers/firmware/efi/libstub/Makefile
@@ -73,13 +73,32 @@ CFLAGS_arm64-stub.o		:= -DTEXT_OFFSET=$(TEXT_OFFSET)
 # a verification pass to see if any absolute relocations exist in any of the
 # object files.
 #
-extra-$(CONFIG_EFI_ARMSTUB)	:= $(lib-y)
-lib-$(CONFIG_EFI_ARMSTUB)	:= $(patsubst %.o,%.stub.o,$(lib-y))
+extra-y	:= $(lib-y)
+lib-y	:= $(patsubst %.o,%.stub.o,$(lib-y))
 
 STUBCOPY_FLAGS-$(CONFIG_ARM64)	+= --prefix-alloc-sections=.init \
 				   --prefix-symbols=__efistub_
 STUBCOPY_RELOC-$(CONFIG_ARM64)	:= R_AARCH64_ABS
 
+#
+# ARM discards the .data section because it disallows r/w data in the
+# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
+# which are preserved explicitly by the decompressor linker script.
+#
+STUBCOPY_FLAGS-$(CONFIG_ARM)	+= --rename-section .data=.data.efistub	\
+				   --rename-section .bss=.bss.efistub,load,alloc
+STUBCOPY_RELOC-$(CONFIG_ARM)	:= R_ARM_ABS
+
+#
+# For x86, bootloaders like systemd-boot or grub-efi do not zero-initialize the
+# .bss section, so the .bss section of the EFI stub needs to be included in the
+# .data section of the compressed kernel to ensure initialization. Rename the
+# .bss section here so it's easy to pick out in the linker script.
+#
+STUBCOPY_FLAGS-$(CONFIG_X86)	+= --rename-section .bss=.bss.efistub,load,alloc
+STUBCOPY_RELOC-$(CONFIG_X86_32) := R_386_32
+STUBCOPY_RELOC-$(CONFIG_X86_64) := R_X86_64_64
+
 $(obj)/%.stub.o: $(obj)/%.o FORCE
 	$(call if_changed,stubcopy)
 
@@ -97,12 +116,3 @@ quiet_cmd_stubcopy = STUBCPY $@
 		/bin/false;						\
 	fi;								\
 	$(OBJCOPY) $(STUBCOPY_FLAGS-y) $< $@
-
-#
-# ARM discards the .data section because it disallows r/w data in the
-# decompressor. So move our .data to .data.efistub and .bss to .bss.efistub,
-# which are preserved explicitly by the decompressor linker script.
-#
-STUBCOPY_FLAGS-$(CONFIG_ARM)	+= --rename-section .data=.data.efistub	\
-				   --rename-section .bss=.bss.efistub,load,alloc
-STUBCOPY_RELOC-$(CONFIG_ARM)	:= R_ARM_ABS
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index a92d42ffd9f7..49651e20bb9f 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -25,11 +25,7 @@
 #define EFI_ALLOC_ALIGN		EFI_PAGE_SIZE
 #endif
 
-#if defined(CONFIG_X86)
-#define __efistub_global	__section(.data)
-#else
 #define __efistub_global
-#endif
 
 extern bool __pure nochunk(void);
 extern bool __pure nokaslr(void);
-- 
2.25.3


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

* [PATCH v2 3/3] efi: Kill __efistub_global
  2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
                   ` (7 preceding siblings ...)
  2020-04-16 15:12 ` [PATCH v2 2/3] efi/x86: Remove __efistub_global and add relocation check Arvind Sankar
@ 2020-04-16 15:12 ` Arvind Sankar
  8 siblings, 0 replies; 16+ messages in thread
From: Arvind Sankar @ 2020-04-16 15:12 UTC (permalink / raw)
  To: Arvind Sankar
  Cc: Ard Biesheuvel, linux-efi, linux-arm-kernel, x86,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov, linux-kernel

Now that both arm and x86 are using the linker script to place the EFI
stub's global variables in the correct section, remove __efistub_global.

Signed-off-by: Arvind Sankar <nivedita@alum.mit.edu>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/libstub/arm-stub.c        |  4 ++--
 drivers/firmware/efi/libstub/efi-stub-helper.c | 15 +++++++--------
 drivers/firmware/efi/libstub/efistub.h         |  2 --
 drivers/firmware/efi/libstub/gop.c             |  2 +-
 drivers/firmware/efi/libstub/x86-stub.c        |  2 +-
 5 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
index 99a5cde7c2d8..bf42d6c742a8 100644
--- a/drivers/firmware/efi/libstub/arm-stub.c
+++ b/drivers/firmware/efi/libstub/arm-stub.c
@@ -36,9 +36,9 @@
 #endif
 
 static u64 virtmap_base = EFI_RT_VIRTUAL_BASE;
-static bool __efistub_global flat_va_mapping;
+static bool flat_va_mapping;
 
-static efi_system_table_t *__efistub_global sys_table;
+static efi_system_table_t *sys_table;
 
 __pure efi_system_table_t *efi_system_table(void)
 {
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index c6092b6038cf..14e56a64f208 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -12,14 +12,13 @@
 
 #include "efistub.h"
 
-static bool __efistub_global efi_nochunk;
-static bool __efistub_global efi_nokaslr;
-static bool __efistub_global efi_noinitrd;
-static bool __efistub_global efi_quiet;
-static bool __efistub_global efi_novamap;
-static bool __efistub_global efi_nosoftreserve;
-static bool __efistub_global efi_disable_pci_dma =
-					IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA);
+static bool efi_nochunk;
+static bool efi_nokaslr;
+static bool efi_noinitrd;
+static bool efi_quiet;
+static bool efi_novamap;
+static bool efi_nosoftreserve;
+static bool efi_disable_pci_dma = IS_ENABLED(CONFIG_EFI_DISABLE_PCI_DMA);
 
 bool __pure nochunk(void)
 {
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 49651e20bb9f..f96c56596034 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -25,8 +25,6 @@
 #define EFI_ALLOC_ALIGN		EFI_PAGE_SIZE
 #endif
 
-#define __efistub_global
-
 extern bool __pure nochunk(void);
 extern bool __pure nokaslr(void);
 extern bool __pure noinitrd(void);
diff --git a/drivers/firmware/efi/libstub/gop.c b/drivers/firmware/efi/libstub/gop.c
index fa05a0b0adfd..216327d0b034 100644
--- a/drivers/firmware/efi/libstub/gop.c
+++ b/drivers/firmware/efi/libstub/gop.c
@@ -32,7 +32,7 @@ static struct {
 			u8 depth;
 		} res;
 	};
-} cmdline __efistub_global = { .option = EFI_CMDLINE_NONE };
+} cmdline = { .option = EFI_CMDLINE_NONE };
 
 static bool parse_modenum(char *option, char **next)
 {
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 7583e908852f..aedac3af4b5c 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -20,7 +20,7 @@
 /* Maximum physical address for 64-bit kernel with 4-level paging */
 #define MAXMEM_X86_64_4LEVEL (1ull << 46)
 
-static efi_system_table_t *sys_table __efistub_global;
+static efi_system_table_t *sys_table;
 extern const bool efi_is64;
 extern u32 image_offset;
 
-- 
2.25.3


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

* Re: [PATCH v2 0/3] efi: Remove __efistub_global annotation
  2020-04-16 15:12 ` [PATCH v2 0/3] efi: Remove __efistub_global annotation Arvind Sankar
@ 2020-04-16 16:01   ` Ard Biesheuvel
  0 siblings, 0 replies; 16+ messages in thread
From: Ard Biesheuvel @ 2020-04-16 16:01 UTC (permalink / raw)
  To: Arvind Sankar, Atish Patra
  Cc: linux-efi, Linux ARM, X86 ML, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Linux Kernel Mailing List

On Thu, 16 Apr 2020 at 17:12, Arvind Sankar <nivedita@alum.mit.edu> wrote:
>
> This patch series removes the need for annotating global data in the EFI
> stub with __efistub_global for ARM32 and X86.
>
> This is done by renaming the .data and .bss sections in the object files
> linked into the EFI stub to .data.efistub and .bss.efistub respectively,
> and including those sections into the compressed kernel's .data section
> using its linker script.
>
> Changes from v1:
> - drop patch 2 and squash patches 3 and 5 for x86
> - fix R_X86 -> R_386
> - only check native relocation size (32-bit for R386 and 64-bit for
>   RX86_64)
>

Thanks Arvind. I have queued these up now.

Atish, I have queued up the first 2 patches of your RISC-V EFI stbu
series as well. Please base your next version on

https://git.kernel.org/pub/scm/linux/kernel/git/efi/efi.git/log/?h=next

Thanks,
Ard.

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

end of thread, other threads:[~2020-04-16 16:01 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-15 22:15 [PATCH 0/5] efi: Remove __efistub_global annotation Arvind Sankar
2020-04-15 22:15 ` [PATCH 1/5] efi/arm: " Arvind Sankar
2020-04-16  7:50   ` Ard Biesheuvel
2020-04-15 22:15 ` [PATCH 2/5] efi/libstub: Factor out relocation checking Arvind Sankar
2020-04-15 22:15 ` [PATCH 3/5] efi/x86: Remove __efistub_global annotation Arvind Sankar
2020-04-16  7:51   ` Ard Biesheuvel
2020-04-15 22:15 ` [PATCH 4/5] efi: Kill __efistub_global Arvind Sankar
2020-04-16  7:51   ` Ard Biesheuvel
2020-04-15 22:15 ` [PATCH 5/5] efi/x86: Check for bad relocations Arvind Sankar
2020-04-16  7:38   ` Ard Biesheuvel
2020-04-16 14:48     ` Arvind Sankar
2020-04-16 15:12 ` [PATCH v2 0/3] efi: Remove __efistub_global annotation Arvind Sankar
2020-04-16 16:01   ` Ard Biesheuvel
2020-04-16 15:12 ` [PATCH v2 1/3] efi/arm: " Arvind Sankar
2020-04-16 15:12 ` [PATCH v2 2/3] efi/x86: Remove __efistub_global and add relocation check Arvind Sankar
2020-04-16 15:12 ` [PATCH v2 3/3] efi: Kill __efistub_global Arvind Sankar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).