All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64: remove TEXT_OFFSET randomization
@ 2020-06-15 10:19 Ard Biesheuvel
  2020-06-15 10:27 ` Mark Rutland
  2020-06-15 16:34 ` Will Deacon
  0 siblings, 2 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2020-06-15 10:19 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: mark.rutland, will, Ard Biesheuvel

TEXT_OFFSET was recently changed to 0x0, in preparation for its removal
at a later stage, and a warning is emitted into the kernel log when the
bootloader appears to have failed to take the TEXT_OFFSET image header
value into account.

Ironically, this warning itself fails to take TEXT_OFFSET into account,
and compares the kernel image's alignment modulo 2M against a hardcoded
value of 0x0, and so the warning will trigger spuriously when TEXT_OFFSET
randomization is enabled.

Given the intent to get rid of TEXT_OFFSET entirely, let's fix this
oversight by just removing support for TEXT_OFFSET randomization.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/Kconfig.debug | 15 ---------------
 arch/arm64/Makefile      |  6 ------
 2 files changed, 21 deletions(-)

diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
index cdf7ec0b975e..265c4461031f 100644
--- a/arch/arm64/Kconfig.debug
+++ b/arch/arm64/Kconfig.debug
@@ -8,21 +8,6 @@ config PID_IN_CONTEXTIDR
 	  instructions during context switch. Say Y here only if you are
 	  planning to use hardware trace tools with this kernel.
 
-config ARM64_RANDOMIZE_TEXT_OFFSET
-	bool "Randomize TEXT_OFFSET at build time"
-	help
-	  Say Y here if you want the image load offset (AKA TEXT_OFFSET)
-	  of the kernel to be randomized at build-time. When selected,
-	  this option will cause TEXT_OFFSET to be randomized upon any
-	  build of the kernel, and the offset will be reflected in the
-	  text_offset field of the resulting Image. This can be used to
-	  fuzz-test bootloaders which respect text_offset.
-
-	  This option is intended for bootloader and/or kernel testing
-	  only. Bootloaders must make no assumptions regarding the value
-	  of TEXT_OFFSET and platforms must not require a specific
-	  value.
-
 config DEBUG_EFI
 	depends on EFI && DEBUG_INFO
 	bool "UEFI debugging"
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 76359cfb328a..a0d94d063fa8 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -121,13 +121,7 @@ endif
 head-y		:= arch/arm64/kernel/head.o
 
 # The byte offset of the kernel image in RAM from the start of RAM.
-ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
-TEXT_OFFSET := $(shell awk "BEGIN {srand(); printf \"0x%06x\n\", \
-		 int(2 * 1024 * 1024 / (2 ^ $(CONFIG_ARM64_PAGE_SHIFT)) * \
-		 rand()) * (2 ^ $(CONFIG_ARM64_PAGE_SHIFT))}")
-else
 TEXT_OFFSET := 0x0
-endif
 
 ifeq ($(CONFIG_KASAN_SW_TAGS), y)
 KASAN_SHADOW_SCALE_SHIFT := 4
-- 
2.27.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: remove TEXT_OFFSET randomization
  2020-06-15 10:19 [PATCH] arm64: remove TEXT_OFFSET randomization Ard Biesheuvel
@ 2020-06-15 10:27 ` Mark Rutland
  2020-06-15 16:34 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Rutland @ 2020-06-15 10:27 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: will, linux-arm-kernel

On Mon, Jun 15, 2020 at 12:19:39PM +0200, Ard Biesheuvel wrote:
> TEXT_OFFSET was recently changed to 0x0, in preparation for its removal
> at a later stage, and a warning is emitted into the kernel log when the
> bootloader appears to have failed to take the TEXT_OFFSET image header
> value into account.
> 
> Ironically, this warning itself fails to take TEXT_OFFSET into account,
> and compares the kernel image's alignment modulo 2M against a hardcoded
> value of 0x0, and so the warning will trigger spuriously when TEXT_OFFSET
> randomization is enabled.
> 
> Given the intent to get rid of TEXT_OFFSET entirely, let's fix this
> oversight by just removing support for TEXT_OFFSET randomization.
> 
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

If nothing else, it's nice to see the scary awk go, so:

Acked-by: Mark Rutland <mark.rutland@arm.com>

Mark.

> ---
>  arch/arm64/Kconfig.debug | 15 ---------------
>  arch/arm64/Makefile      |  6 ------
>  2 files changed, 21 deletions(-)
> 
> diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
> index cdf7ec0b975e..265c4461031f 100644
> --- a/arch/arm64/Kconfig.debug
> +++ b/arch/arm64/Kconfig.debug
> @@ -8,21 +8,6 @@ config PID_IN_CONTEXTIDR
>  	  instructions during context switch. Say Y here only if you are
>  	  planning to use hardware trace tools with this kernel.
>  
> -config ARM64_RANDOMIZE_TEXT_OFFSET
> -	bool "Randomize TEXT_OFFSET at build time"
> -	help
> -	  Say Y here if you want the image load offset (AKA TEXT_OFFSET)
> -	  of the kernel to be randomized at build-time. When selected,
> -	  this option will cause TEXT_OFFSET to be randomized upon any
> -	  build of the kernel, and the offset will be reflected in the
> -	  text_offset field of the resulting Image. This can be used to
> -	  fuzz-test bootloaders which respect text_offset.
> -
> -	  This option is intended for bootloader and/or kernel testing
> -	  only. Bootloaders must make no assumptions regarding the value
> -	  of TEXT_OFFSET and platforms must not require a specific
> -	  value.
> -
>  config DEBUG_EFI
>  	depends on EFI && DEBUG_INFO
>  	bool "UEFI debugging"
> diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
> index 76359cfb328a..a0d94d063fa8 100644
> --- a/arch/arm64/Makefile
> +++ b/arch/arm64/Makefile
> @@ -121,13 +121,7 @@ endif
>  head-y		:= arch/arm64/kernel/head.o
>  
>  # The byte offset of the kernel image in RAM from the start of RAM.
> -ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
> -TEXT_OFFSET := $(shell awk "BEGIN {srand(); printf \"0x%06x\n\", \
> -		 int(2 * 1024 * 1024 / (2 ^ $(CONFIG_ARM64_PAGE_SHIFT)) * \
> -		 rand()) * (2 ^ $(CONFIG_ARM64_PAGE_SHIFT))}")
> -else
>  TEXT_OFFSET := 0x0
> -endif
>  
>  ifeq ($(CONFIG_KASAN_SW_TAGS), y)
>  KASAN_SHADOW_SCALE_SHIFT := 4
> -- 
> 2.27.0
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] arm64: remove TEXT_OFFSET randomization
  2020-06-15 10:19 [PATCH] arm64: remove TEXT_OFFSET randomization Ard Biesheuvel
  2020-06-15 10:27 ` Mark Rutland
@ 2020-06-15 16:34 ` Will Deacon
  1 sibling, 0 replies; 3+ messages in thread
From: Will Deacon @ 2020-06-15 16:34 UTC (permalink / raw)
  To: Ard Biesheuvel, linux-arm-kernel
  Cc: mark.rutland, catalin.marinas, Will Deacon

On Mon, 15 Jun 2020 12:19:39 +0200, Ard Biesheuvel wrote:
> TEXT_OFFSET was recently changed to 0x0, in preparation for its removal
> at a later stage, and a warning is emitted into the kernel log when the
> bootloader appears to have failed to take the TEXT_OFFSET image header
> value into account.
> 
> Ironically, this warning itself fails to take TEXT_OFFSET into account,
> and compares the kernel image's alignment modulo 2M against a hardcoded
> value of 0x0, and so the warning will trigger spuriously when TEXT_OFFSET
> randomization is enabled.
> 
> [...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64: remove TEXT_OFFSET randomization
      https://git.kernel.org/arm64/c/751c263bb74f

Cheers,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2020-06-15 16:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-15 10:19 [PATCH] arm64: remove TEXT_OFFSET randomization Ard Biesheuvel
2020-06-15 10:27 ` Mark Rutland
2020-06-15 16:34 ` Will Deacon

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.