Skip to contentSkip to conversation

arm64: Fix Kconfig dependencies for RANDOMIZE_BASE

PATCH New Jeff Vander Stoep 4 participants 6 messages Jul 26, 2016 – Jul 27, 2016 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: Fix Kconfig dependencies for RANDOMIZE_BASE

Selecting CONFIG_RANDOMIZE_BASE=y and CONFIG_MODULES=n causes a build error due to dependencies on modules. This patch makes KASLR module config options dependent on CONFIG_MODULES=y.

---
 arch/arm64/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +2 -1
index 7e23f95..c9eff79 100644
@@ -891,7 +891,6 @@ config RELOCATABLE
 
 config RANDOMIZE_BASE
 	bool "Randomize the address of the kernel image"
-	select ARM64_MODULE_PLTS
 	select RELOCATABLE
 	help
 	  Randomizes the virtual address at which the kernel image is
@@ -911,6 +910,8 @@ config RANDOMIZE_BASE
 config RANDOMIZE_MODULE_REGION_FULL
 	bool "Randomize the module region independently from the core kernel"
 	depends on RANDOMIZE_BASE
+	depends on MODULES
+	select ARM64_MODULE_PLTS
 	default y
 	help
 	  Randomizes the location of the module region without considering the
Signature · 1 line
2.8.0.rc3.226.g39d4020
maintainer
#1 lore raw

PATCH 1/1 arm64: Fix Kconfig dependencies for RANDOMIZE_BASE

Quoted 14 lines · Jeff Vander Stoep

Selecting CONFIG_RANDOMIZE_BASE=y and CONFIG_MODULES=n causes a build error due to dependencies on modules. This patch makes KASLR module config options dependent on CONFIG_MODULES=y.

---
 arch/arm64/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +0 -0
index 7e23f95..c9eff79 100644

arch/arm64/Kconfig config RELOCATABLE · line 896

Quoted 7 lines
arch/arm64/Kconfig +0 -1
@@ -891,7 +891,6 @@ config RELOCATABLE
 
 config RANDOMIZE_BASE
 	bool "Randomize the address of the kernel image"
-	select ARM64_MODULE_PLTS
 	select RELOCATABLE
 	help
 	  Randomizes the virtual address at which the kernel image is

I thought we need the module PLTs once we randomize the kernel base, independent of whether we randomize the modules base or not. Could we do something like:

select ARM64_MODULE_PLTS if MODULES

Whichever way we fix this, we probably need:

Fixes f80fb3a3d508 ("arm64: add support for kernel ASLR")
Cc <[email protected]> # 4.6+
Signature · 1 line
Catalin
#2 lore raw

PATCH 1/1 arm64: Fix Kconfig dependencies for RANDOMIZE_BASE

Quoted 16 lines · Catalin Marinas
Quoted 15 lines · Jeff Vander Stoep

Selecting CONFIG_RANDOMIZE_BASE=y and CONFIG_MODULES=n causes a build error due to dependencies on modules. This patch makes KASLR module config options dependent on CONFIG_MODULES=y.

---
 arch/arm64/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +0 -0
index 7e23f95..c9eff79 100644
@@ -891,7 +891,6 @@ config RELOCATABLE
 
Quoted 9 lines

arch/arm64/Kconfig config RELOCATABLE · line 896

Quoted 6 lines
arch/arm64/Kconfig +0 -1
 config RANDOMIZE_BASE
      bool "Randomize the address of the kernel image"
-     select ARM64_MODULE_PLTS
      select RELOCATABLE
      help
        Randomizes the virtual address at which the kernel image is

I thought we need the module PLTs once we randomize the kernel base, independent of whether we randomize the modules base or not.

Indeed. The module region is always randomized with KASLR, but either fully (i.e., anywhere in the vmalloc region) or partially, in which case a random 128 MB range is selected that also covers vmlinux's .text segment, allowing jumps without veneers. However, since this range is part of the ordinary vmalloc space, there is a >0 probability that other allocations may exhaust it before you have loaded all your modules, in which case the module loader will fall back to ordinary vmalloc region allocations, which are most likely too far away to be resolved without PLTs

Quoted 10 lines

Could we do
something like:

select ARM64_MODULE_PLTS if MODULES

Whichever way we fix this, we probably need:

Fixes f80fb3a3d508 ("arm64: add support for kernel ASLR")
Cc <[email protected]> # 4.6+

With these changes

reviewer
#3 lore raw

PATCH 1/1 arm64: Fix Kconfig dependencies for RANDOMIZE_BASE

Quoted 27 lines · Ard Biesheuvel
Quoted 16 lines · Catalin Marinas
Quoted 15 lines · Jeff Vander Stoep

Selecting CONFIG_RANDOMIZE_BASE=y and CONFIG_MODULES=n causes a build error due to dependencies on modules. This patch makes KASLR module config options dependent on CONFIG_MODULES=y.

---
 arch/arm64/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +0 -0
index 7e23f95..c9eff79 100644
@@ -891,7 +891,6 @@ config RELOCATABLE
 
Quoted 9 lines

arch/arm64/Kconfig config RELOCATABLE · line 896

Quoted 6 lines
arch/arm64/Kconfig +0 -1
 config RANDOMIZE_BASE
      bool "Randomize the address of the kernel image"
-     select ARM64_MODULE_PLTS
      select RELOCATABLE
      help
        Randomizes the virtual address at which the kernel image is

I thought we need the module PLTs once we randomize the kernel base, independent of whether we randomize the modules base or not.

Quoted 9 lines

Indeed. The module region is always randomized with KASLR, but either fully (i.e., anywhere in the vmalloc region) or partially, in which case a random 128 MB range is selected that also covers vmlinux's .text segment, allowing jumps without veneers. However, since this range is part of the ordinary vmalloc space, there is a >0 probability that other allocations may exhaust it before you have loaded all your modules, in which case the module loader will fall back to ordinary vmalloc region allocations, which are most likely too far away to be resolved without PLTs

Looking at module_alloc, we only fall back when CONFIG_ARM64_MODULE_PLTS is selected, no? So the allocation would fail completely in the case of the range being exhausted.

I agree that it's sensible to select CONFIG_ARM64_MODULE_PLTS so as to be able to load modules regardless of other vmalloc allocations exhausting a VA range.

Quoted 7 lines
Quoted 7 lines

Could we do
something like:

select ARM64_MODULE_PLTS if MODULES

Whichever way we fix this, we probably need:

Quoted 7 lines
Quoted 3 lines
Fixes f80fb3a3d508 ("arm64: add support for kernel ASLR")
Cc <[email protected]> # 4.6+

With these changes

FWIW, likewise:

Thanks,
Mark.

maintainer
#4 lore raw

PATCH 1/1 arm64: Fix Kconfig dependencies for RANDOMIZE_BASE

In reply to Ard Biesheuvel
Quoted 44 lines · Ard Biesheuvel
Quoted 16 lines · Catalin Marinas
Quoted 15 lines · Jeff Vander Stoep

Selecting CONFIG_RANDOMIZE_BASE=y and CONFIG_MODULES=n causes a build error due to dependencies on modules. This patch makes KASLR module config options dependent on CONFIG_MODULES=y.

---
 arch/arm64/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +0 -0
index 7e23f95..c9eff79 100644
@@ -891,7 +891,6 @@ config RELOCATABLE
 
Quoted 9 lines

arch/arm64/Kconfig config RELOCATABLE · line 896

Quoted 6 lines
arch/arm64/Kconfig +0 -1
 config RANDOMIZE_BASE
      bool "Randomize the address of the kernel image"
-     select ARM64_MODULE_PLTS
      select RELOCATABLE
      help
        Randomizes the virtual address at which the kernel image is

I thought we need the module PLTs once we randomize the kernel base, independent of whether we randomize the modules base or not.

Indeed. The module region is always randomized with KASLR, but either fully (i.e., anywhere in the vmalloc region) or partially, in which case a random 128 MB range is selected that also covers vmlinux's .text segment, allowing jumps without veneers. However, since this range is part of the ordinary vmalloc space, there is a >0 probability that other allocations may exhaust it before you have loaded all your modules, in which case the module loader will fall back to ordinary vmalloc region allocations, which are most likely too far away to be resolved without PLTs

Quoted 7 lines

Could we do
something like:

select ARM64_MODULE_PLTS if MODULES

Whichever way we fix this, we probably need:

Quoted 7 lines
Quoted 3 lines
Fixes f80fb3a3d508 ("arm64: add support for kernel ASLR")
Cc <[email protected]> # 4.6+

With these changes

Thanks. I pushed my variant above to arm64 for-next/core.

Signature · 1 line
Catalin
maintainer
#5 lore raw

PATCH 1/1 arm64: Fix Kconfig dependencies for RANDOMIZE_BASE

In reply to Catalin Marinas
Quoted 16 lines · Catalin Marinas
Quoted 15 lines · Jeff Vander Stoep

Selecting CONFIG_RANDOMIZE_BASE=y and CONFIG_MODULES=n causes a build error due to dependencies on modules. This patch makes KASLR module config options dependent on CONFIG_MODULES=y.

---
 arch/arm64/Kconfig | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/Kconfig +0 -0
index 7e23f95..c9eff79 100644
@@ -891,7 +891,6 @@ config RELOCATABLE
 
Quoted 9 lines

arch/arm64/Kconfig config RELOCATABLE · line 896

Quoted 6 lines
arch/arm64/Kconfig +0 -1
 config RANDOMIZE_BASE
 	bool "Randomize the address of the kernel image"
-	select ARM64_MODULE_PLTS
 	select RELOCATABLE
 	help
 	  Randomizes the virtual address at which the kernel image is

I thought we need the module PLTs once we randomize the kernel base, independent of whether we randomize the modules base or not.

Looking at the code, I think we don't really need the PLTs when the modules are randomised together with the kernel image. So I think your original patch is fine.

Quoted 2 lines
Fixes f80fb3a3d508 ("arm64: add support for kernel ASLR")
Cc <[email protected]> # 4.6+

I'll add these myself. Unless Ard has any objections, I'll queue this for 4.8.

Thanks.

Signature · 1 line
Catalin