linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [GIT PULL 0/1] EFI fix for v4.17
@ 2018-05-18 14:08 Ard Biesheuvel
  2018-05-18 14:08 ` [PATCH 1/1] efi/libstub/arm64: handle randomized TEXT_OFFSET Ard Biesheuvel
  0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2018-05-18 14:08 UTC (permalink / raw)
  To: linux-efi, Ingo Molnar, Thomas Gleixner
  Cc: Ard Biesheuvel, linux-kernel, Kim Phillips, Mark Rutland

The following changes since commit 6d08b06e67cd117f6992c46611dfb4ce267cd71e:

  Linux 4.17-rc2 (2018-04-22 19:20:09 -0700)

are available in the Git repository at:

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

for you to fetch changes up to bdad6e217f1e4402bd5809f67b1de39720732604:

  efi/libstub/arm64: handle randomized TEXT_OFFSET (2018-05-14 09:53:24 +0200)

----------------------------------------------------------------
EFI fix for v4.17:
- ensure that arm64 kernels built with CONFIG_RANDOMIZE_TEXT_OFFSET=y appear
  correctly aligned in memory when KASLR is in effect.

----------------------------------------------------------------
Mark Rutland (1):
      efi/libstub/arm64: handle randomized TEXT_OFFSET

 drivers/firmware/efi/libstub/arm64-stub.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

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

* [PATCH 1/1] efi/libstub/arm64: handle randomized TEXT_OFFSET
  2018-05-18 14:08 [GIT PULL 0/1] EFI fix for v4.17 Ard Biesheuvel
@ 2018-05-18 14:08 ` Ard Biesheuvel
  2018-05-19  6:12   ` [tip:efi/urgent] efi/libstub/arm64: Handle " tip-bot for Mark Rutland
  0 siblings, 1 reply; 3+ messages in thread
From: Ard Biesheuvel @ 2018-05-18 14:08 UTC (permalink / raw)
  To: linux-efi, Ingo Molnar, Thomas Gleixner
  Cc: Mark Rutland, Ard Biesheuvel, linux-kernel

From: Mark Rutland <mark.rutland@arm.com>

When CONFIG_RANDOMIZE_TEXT_OFFSET=y, TEXT_OFFSET is an arbitrary
multiple of PAGE_SIZE in the interval [0, 2MB).

The EFI stub does not account for the potential misalignment of
TEXT_OFFSET relative to EFI_KIMG_ALIGN, and produces a randomized
physical offset which is always a round multiple of EFI_KIMG_ALIGN.
This may result in statically allocated objects whose alignment exceeds
PAGE_SIZE to appear misaligned in memory. This has been observed to
result in spurious stack overflow reports and failure to make use of
the IRQ stacks, and theoretically could result in a number of other
issues.

We can OR in the low bits of TEXT_OFFSET to ensure that we have the
necessary offset (and hence preserve the misalignment of TEXT_OFFSET
relative to EFI_KIMG_ALIGN), so let's do that.

Fixes: 6f26b3671184c36d ("arm64: kaslr: increase randomization granularity")
Reported-by: Kim Phillips <kim.phillips@arm.com>
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Tested-by: Kim Phillips <kim.phillips@arm.com>
[ardb: clarify comment and commit log, drop unneeded parens]
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 drivers/firmware/efi/libstub/arm64-stub.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index b9bd827caa22..1b4d465cc5d9 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -97,6 +97,16 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 		u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ?
 			     (phys_seed >> 32) & mask : TEXT_OFFSET;
 
+		/*
+		 * With CONFIG_RANDOMIZE_TEXT_OFFSET=y, TEXT_OFFSET may not
+		 * be a multiple of EFI_KIMG_ALIGN, and we must ensure that
+		 * we preserve the misalignment of 'offset' relative to
+		 * EFI_KIMG_ALIGN so that statically allocated objects whose
+		 * alignment exceeds PAGE_SIZE appear correctly aligned in
+		 * memory.
+		 */
+		offset |= TEXT_OFFSET % EFI_KIMG_ALIGN;
+
 		/*
 		 * If KASLR is enabled, and we have some randomness available,
 		 * locate the kernel at a randomized offset in physical memory.
-- 
2.17.0

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

* [tip:efi/urgent] efi/libstub/arm64: Handle randomized TEXT_OFFSET
  2018-05-18 14:08 ` [PATCH 1/1] efi/libstub/arm64: handle randomized TEXT_OFFSET Ard Biesheuvel
@ 2018-05-19  6:12   ` tip-bot for Mark Rutland
  0 siblings, 0 replies; 3+ messages in thread
From: tip-bot for Mark Rutland @ 2018-05-19  6:12 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, mark.rutland, kim.phillips, torvalds, linux-kernel,
	peterz, ard.biesheuvel, tglx, hpa

Commit-ID:  4f74d72aa7067e75af92fbab077e6d7d0210be66
Gitweb:     https://git.kernel.org/tip/4f74d72aa7067e75af92fbab077e6d7d0210be66
Author:     Mark Rutland <mark.rutland@arm.com>
AuthorDate: Fri, 18 May 2018 16:08:41 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 19 May 2018 08:07:56 +0200

efi/libstub/arm64: Handle randomized TEXT_OFFSET

When CONFIG_RANDOMIZE_TEXT_OFFSET=y, TEXT_OFFSET is an arbitrary
multiple of PAGE_SIZE in the interval [0, 2MB).

The EFI stub does not account for the potential misalignment of
TEXT_OFFSET relative to EFI_KIMG_ALIGN, and produces a randomized
physical offset which is always a round multiple of EFI_KIMG_ALIGN.
This may result in statically allocated objects whose alignment exceeds
PAGE_SIZE to appear misaligned in memory. This has been observed to
result in spurious stack overflow reports and failure to make use of
the IRQ stacks, and theoretically could result in a number of other
issues.

We can OR in the low bits of TEXT_OFFSET to ensure that we have the
necessary offset (and hence preserve the misalignment of TEXT_OFFSET
relative to EFI_KIMG_ALIGN), so let's do that.

Reported-by: Kim Phillips <kim.phillips@arm.com>
Tested-by: Kim Phillips <kim.phillips@arm.com>
[ardb: clarify comment and commit log, drop unneeded parens]
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
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
Fixes: 6f26b3671184c36d ("arm64: kaslr: increase randomization granularity")
Link: http://lkml.kernel.org/r/20180518140841.9731-2-ard.biesheuvel@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 drivers/firmware/efi/libstub/arm64-stub.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index b9bd827caa22..1b4d465cc5d9 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -97,6 +97,16 @@ efi_status_t handle_kernel_image(efi_system_table_t *sys_table_arg,
 		u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ?
 			     (phys_seed >> 32) & mask : TEXT_OFFSET;
 
+		/*
+		 * With CONFIG_RANDOMIZE_TEXT_OFFSET=y, TEXT_OFFSET may not
+		 * be a multiple of EFI_KIMG_ALIGN, and we must ensure that
+		 * we preserve the misalignment of 'offset' relative to
+		 * EFI_KIMG_ALIGN so that statically allocated objects whose
+		 * alignment exceeds PAGE_SIZE appear correctly aligned in
+		 * memory.
+		 */
+		offset |= TEXT_OFFSET % EFI_KIMG_ALIGN;
+
 		/*
 		 * If KASLR is enabled, and we have some randomness available,
 		 * locate the kernel at a randomized offset in physical memory.

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

end of thread, other threads:[~2018-05-19  6:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-18 14:08 [GIT PULL 0/1] EFI fix for v4.17 Ard Biesheuvel
2018-05-18 14:08 ` [PATCH 1/1] efi/libstub/arm64: handle randomized TEXT_OFFSET Ard Biesheuvel
2018-05-19  6:12   ` [tip:efi/urgent] efi/libstub/arm64: Handle " tip-bot for Mark Rutland

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).