All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: ard.biesheuvel@linaro.org, catalin.marinas@arm.com,
	james.morse@arm.com, labbott@redhat.com,
	linux-kernel@vger.kernel.org, luto@amacapital.net,
	mark.rutland@arm.com, matt@codeblueprint.co.uk,
	will.deacon@arm.com, kernel-hardening@lists.openwall.com,
	keescook@chromium.org
Subject: [PATCHv2 08/14] efi/arm64: add EFI_KIMG_ALIGN
Date: Tue, 15 Aug 2017 13:50:43 +0100	[thread overview]
Message-ID: <1502801449-29246-9-git-send-email-mark.rutland@arm.com> (raw)
In-Reply-To: <1502801449-29246-1-git-send-email-mark.rutland@arm.com>

The EFI stub is intimately coupled with the kernel, and takes advantage
of this by relocating the kernel at a weaker alignment than the
documented boot protocol mandates.

However, it does so by assuming it can align the kernel to the segment
alignment, and assumes that this is 64K. In subsequent patches, we'll
have to consider other details to determine this de-facto alignment
constraint.

This patch adds a new EFI_KIMG_ALIGN definition that will track the
kernel's de-facto alignment requirements. Subsequent patches will modify
this as required.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/include/asm/efi.h              | 3 +++
 drivers/firmware/efi/libstub/arm64-stub.c | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index 8f3043a..0e8cc3b 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -4,6 +4,7 @@
 #include <asm/boot.h>
 #include <asm/cpufeature.h>
 #include <asm/io.h>
+#include <asm/memory.h>
 #include <asm/mmu_context.h>
 #include <asm/neon.h>
 #include <asm/ptrace.h>
@@ -48,6 +49,8 @@
  */
 #define EFI_FDT_ALIGN	SZ_2M   /* used by allocate_new_fdt_and_exit_boot() */
 
+#define EFI_KIMG_ALIGN	SEGMENT_ALIGN
+
 /* on arm64, the FDT may be located anywhere in system RAM */
 static inline unsigned long efi_get_max_fdt_addr(unsigned long dram_base)
 {
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index b4c2589..af6ae95 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -11,6 +11,7 @@
  */
 #include <linux/efi.h>
 #include <asm/efi.h>
+#include <asm/memory.h>
 #include <asm/sections.h>
 #include <asm/sysreg.h>
 
@@ -81,9 +82,10 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 		/*
 		 * If CONFIG_DEBUG_ALIGN_RODATA is not set, produce a
 		 * displacement in the interval [0, MIN_KIMG_ALIGN) that
-		 * is a multiple of the minimal segment alignment (SZ_64K)
+		 * doesn't violate this kernel's de-facto alignment
+		 * constraints.
 		 */
-		u32 mask = (MIN_KIMG_ALIGN - 1) & ~(SZ_64K - 1);
+		u32 mask = (MIN_KIMG_ALIGN - 1) & ~(EFI_KIMG_ALIGN - 1);
 		u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ?
 			     (phys_seed >> 32) & mask : TEXT_OFFSET;
 
-- 
1.9.1

WARNING: multiple messages have this Message-ID (diff)
From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv2 08/14] efi/arm64: add EFI_KIMG_ALIGN
Date: Tue, 15 Aug 2017 13:50:43 +0100	[thread overview]
Message-ID: <1502801449-29246-9-git-send-email-mark.rutland@arm.com> (raw)
In-Reply-To: <1502801449-29246-1-git-send-email-mark.rutland@arm.com>

The EFI stub is intimately coupled with the kernel, and takes advantage
of this by relocating the kernel at a weaker alignment than the
documented boot protocol mandates.

However, it does so by assuming it can align the kernel to the segment
alignment, and assumes that this is 64K. In subsequent patches, we'll
have to consider other details to determine this de-facto alignment
constraint.

This patch adds a new EFI_KIMG_ALIGN definition that will track the
kernel's de-facto alignment requirements. Subsequent patches will modify
this as required.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/include/asm/efi.h              | 3 +++
 drivers/firmware/efi/libstub/arm64-stub.c | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index 8f3043a..0e8cc3b 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -4,6 +4,7 @@
 #include <asm/boot.h>
 #include <asm/cpufeature.h>
 #include <asm/io.h>
+#include <asm/memory.h>
 #include <asm/mmu_context.h>
 #include <asm/neon.h>
 #include <asm/ptrace.h>
@@ -48,6 +49,8 @@
  */
 #define EFI_FDT_ALIGN	SZ_2M   /* used by allocate_new_fdt_and_exit_boot() */
 
+#define EFI_KIMG_ALIGN	SEGMENT_ALIGN
+
 /* on arm64, the FDT may be located anywhere in system RAM */
 static inline unsigned long efi_get_max_fdt_addr(unsigned long dram_base)
 {
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index b4c2589..af6ae95 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -11,6 +11,7 @@
  */
 #include <linux/efi.h>
 #include <asm/efi.h>
+#include <asm/memory.h>
 #include <asm/sections.h>
 #include <asm/sysreg.h>
 
@@ -81,9 +82,10 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 		/*
 		 * If CONFIG_DEBUG_ALIGN_RODATA is not set, produce a
 		 * displacement in the interval [0, MIN_KIMG_ALIGN) that
-		 * is a multiple of the minimal segment alignment (SZ_64K)
+		 * doesn't violate this kernel's de-facto alignment
+		 * constraints.
 		 */
-		u32 mask = (MIN_KIMG_ALIGN - 1) & ~(SZ_64K - 1);
+		u32 mask = (MIN_KIMG_ALIGN - 1) & ~(EFI_KIMG_ALIGN - 1);
 		u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ?
 			     (phys_seed >> 32) & mask : TEXT_OFFSET;
 
-- 
1.9.1

WARNING: multiple messages have this Message-ID (diff)
From: Mark Rutland <mark.rutland@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: ard.biesheuvel@linaro.org, catalin.marinas@arm.com,
	james.morse@arm.com, labbott@redhat.com,
	linux-kernel@vger.kernel.org, luto@amacapital.net,
	mark.rutland@arm.com, matt@codeblueprint.co.uk,
	will.deacon@arm.com, kernel-hardening@lists.openwall.com,
	keescook@chromium.org
Subject: [kernel-hardening] [PATCHv2 08/14] efi/arm64: add EFI_KIMG_ALIGN
Date: Tue, 15 Aug 2017 13:50:43 +0100	[thread overview]
Message-ID: <1502801449-29246-9-git-send-email-mark.rutland@arm.com> (raw)
In-Reply-To: <1502801449-29246-1-git-send-email-mark.rutland@arm.com>

The EFI stub is intimately coupled with the kernel, and takes advantage
of this by relocating the kernel at a weaker alignment than the
documented boot protocol mandates.

However, it does so by assuming it can align the kernel to the segment
alignment, and assumes that this is 64K. In subsequent patches, we'll
have to consider other details to determine this de-facto alignment
constraint.

This patch adds a new EFI_KIMG_ALIGN definition that will track the
kernel's de-facto alignment requirements. Subsequent patches will modify
this as required.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: James Morse <james.morse@arm.com>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/include/asm/efi.h              | 3 +++
 drivers/firmware/efi/libstub/arm64-stub.c | 6 ++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h
index 8f3043a..0e8cc3b 100644
--- a/arch/arm64/include/asm/efi.h
+++ b/arch/arm64/include/asm/efi.h
@@ -4,6 +4,7 @@
 #include <asm/boot.h>
 #include <asm/cpufeature.h>
 #include <asm/io.h>
+#include <asm/memory.h>
 #include <asm/mmu_context.h>
 #include <asm/neon.h>
 #include <asm/ptrace.h>
@@ -48,6 +49,8 @@
  */
 #define EFI_FDT_ALIGN	SZ_2M   /* used by allocate_new_fdt_and_exit_boot() */
 
+#define EFI_KIMG_ALIGN	SEGMENT_ALIGN
+
 /* on arm64, the FDT may be located anywhere in system RAM */
 static inline unsigned long efi_get_max_fdt_addr(unsigned long dram_base)
 {
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index b4c2589..af6ae95 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -11,6 +11,7 @@
  */
 #include <linux/efi.h>
 #include <asm/efi.h>
+#include <asm/memory.h>
 #include <asm/sections.h>
 #include <asm/sysreg.h>
 
@@ -81,9 +82,10 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 		/*
 		 * If CONFIG_DEBUG_ALIGN_RODATA is not set, produce a
 		 * displacement in the interval [0, MIN_KIMG_ALIGN) that
-		 * is a multiple of the minimal segment alignment (SZ_64K)
+		 * doesn't violate this kernel's de-facto alignment
+		 * constraints.
 		 */
-		u32 mask = (MIN_KIMG_ALIGN - 1) & ~(SZ_64K - 1);
+		u32 mask = (MIN_KIMG_ALIGN - 1) & ~(EFI_KIMG_ALIGN - 1);
 		u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ?
 			     (phys_seed >> 32) & mask : TEXT_OFFSET;
 
-- 
1.9.1

  parent reply	other threads:[~2017-08-15 12:52 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-15 12:50 [PATCHv2 00/14] arm64: VMAP_STACK support Mark Rutland
2017-08-15 12:50 ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50 ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 01/14] arm64: remove __die()'s stack dump Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 02/14] fork: allow arch-override of VMAP stack alignment Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 16:09   ` Andy Lutomirski
2017-08-15 16:09     ` [kernel-hardening] " Andy Lutomirski
2017-08-15 16:09     ` Andy Lutomirski
2017-08-15 16:30     ` Mark Rutland
2017-08-15 16:30       ` [kernel-hardening] " Mark Rutland
2017-08-15 16:30       ` Mark Rutland
2017-08-15 16:33       ` Andy Lutomirski
2017-08-15 16:33         ` [kernel-hardening] " Andy Lutomirski
2017-08-15 16:33         ` Andy Lutomirski
2017-08-15 16:39         ` Mark Rutland
2017-08-15 16:39           ` [kernel-hardening] " Mark Rutland
2017-08-15 16:39           ` Mark Rutland
2017-08-15 17:02           ` Catalin Marinas
2017-08-15 17:02             ` [kernel-hardening] " Catalin Marinas
2017-08-15 17:02             ` Catalin Marinas
2017-08-15 12:50 ` [PATCHv2 03/14] arm64: kernel: remove {THREAD,IRQ_STACK}_START_SP Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 04/14] arm64: factor out PAGE_* and CONT_* definitions Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 05/14] arm64: clean up THREAD_* definitions Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 06/14] arm64: clean up irq stack definitions Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 07/14] arm64: move SEGMENT_ALIGN to <asm/memory.h> Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` Mark Rutland [this message]
2017-08-15 12:50   ` [kernel-hardening] [PATCHv2 08/14] efi/arm64: add EFI_KIMG_ALIGN Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 09/14] arm64: factor out entry stack manipulation Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 10/14] arm64: assembler: allow adr_this_cpu to use the stack pointer Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 11/14] arm64: use an irq " Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 12/14] arm64: add basic VMAP_STACK support Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 13/14] arm64: add on_accessible_stack() Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 12:50 ` [PATCHv2 14/14] arm64: add VMAP_STACK overflow detection Mark Rutland
2017-08-15 12:50   ` [kernel-hardening] " Mark Rutland
2017-08-15 12:50   ` Mark Rutland
2017-08-15 14:00 ` [PATCHv2 00/14] arm64: VMAP_STACK support Will Deacon
2017-08-15 14:00   ` [kernel-hardening] " Will Deacon
2017-08-15 14:00   ` Will Deacon
2017-08-15 17:18 ` Laura Abbott
2017-08-15 17:18   ` [kernel-hardening] " Laura Abbott
2017-08-15 17:18   ` Laura Abbott
2017-08-15 17:39   ` Mark Rutland
2017-08-15 17:39     ` [kernel-hardening] " Mark Rutland
2017-08-15 17:39     ` Mark Rutland
2017-08-15 17:44     ` Catalin Marinas
2017-08-15 17:44       ` [kernel-hardening] " Catalin Marinas
2017-08-15 17:44       ` Catalin Marinas
2017-08-15 18:15       ` Kees Cook
2017-08-15 18:15         ` [kernel-hardening] " Kees Cook
2017-08-15 18:15         ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1502801449-29246-9-git-send-email-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=labbott@redhat.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=matt@codeblueprint.co.uk \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.