arm64/mm: Remove randomization of the linear map
RFC PATCH 1/1 arm64/mm: Remove randomization of the linear map
From: Ard Biesheuvel <[email protected]>
Since commit
97d6786e0669 ("arm64: mm: account for hotplug memory when randomizing the linear region")
the decision whether or not to randomize the placement of the system's DRAM inside the linear map is based on the capabilities of the CPU rather than how much memory is present at boot time. This change was necessary because memory hotplug may result in DRAM appearing in places that are not covered by the linear region at all (and therefore unusable) if the decision is solely based on the memory map at boot.
In the Android GKI kernel, which requires support for memory hotplug, and is built with a reduced virtual address space of only 39 bits wide, randomization of the linear map never happens in practice as a result. And even on arm64 kernels built with support for 48 bit virtual addressing, the wider PArange of recent CPUs means that linear map randomization is slowly becoming a feature that only works on systems that will soon be obsolete.
So let's just remove this feature. We can always bring it back in an improved form if there is a real need for it.
--- arch/arm64/kernel/image-vars.h | 1 - arch/arm64/kernel/kaslr.c | 2 -- arch/arm64/kernel/pi/kaslr_early.c | 4 ---- arch/arm64/mm/init.c | 20 -------------------- 4 files changed, 27 deletions(-)
arch/arm64/kernel/image-vars.h +0 -1
@@ -51,7 +51,6 @@ PROVIDE(__pi_arm64_use_ng_mappings = arm64_use_ng_mappings);PROVIDE (__pi_cavium_erratum_27456_cpus = cavium_erratum_27456_cpus);#endif PROVIDE (__pi__ctype = _ctype); -PROVIDE (__pi_memstart_offset_seed = memstart_offset_seed);PROVIDE (__pi_init_idmap_pg_dir = init_idmap_pg_dir);PROVIDE (__pi_init_idmap_pg_end = init_idmap_pg_end);
arch/arm64/kernel/kaslr.c +0 -2
@@ -10,8 +10,6 @@#include <asm/cpufeature.h> #include <asm/memory.h> -u16 __initdata memstart_offset_seed; -bool __ro_after_init __kaslr_is_enabled = false;void __init kaslr_init (void )
arch/arm64/kernel/pi/kaslr_early.c +0 -4
@@ -18,8 +18,6 @@#include "pi.h" -extern u16 memstart_offset_seed; -static u64 __init get_kaslr_seed (void *fdt,int node) {static char const seed_str[]__initconst ="kaslr-seed" ;
@@ -53,8 +51,6 @@ u64 __init kaslr_early_init(void *fdt, int chosen)return 0 ; } - memstart_offset_seed = seed &U16_MAX ; -/* * OK, so we are proceeding with KASLR enabled. Calculate a suitable * kernel image offset from the seed. Let's place the kernel in the
arch/arm64/mm/init.c +0 -20
@@ -277,26 +277,6 @@ void __init arm64_memblock_init(void) } } -if (IS_ENABLED (CONFIG_RANDOMIZE_BASE )) { -extern u16 memstart_offset_seed; -u64 mmfr0 =read_cpuid (ID_AA64MMFR0_EL1 ); -int parange =cpuid_feature_extract_unsigned_field ( - mmfr0,ID_AA64MMFR0_EL1_PARANGE_SHIFT ); -s64 range = linear_region_size - -BIT (id_aa64mmfr0_parange_to_phys_shift (parange)); - -/* -* If the size of the linear region exceeds, by a sufficient -* margin, the size of the region that the physical memory can -* span, randomize the linear region as well. -*/ -if (memstart_offset_seed >0 && range >= (s64 )ARM64_MEMSTART_ALIGN ) { - range /=ARM64_MEMSTART_ALIGN ; - memstart_addr -=ARM64_MEMSTART_ALIGN * - ((range * memstart_offset_seed) >>16 ); - } - } -/* * Register the kernel text, kernel data, initrd, and initial * pagetables with memblock.
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog
Quoted 25 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Since commit
97d6786e0669("arm64: mm: account for hotplug memory when randomizing the linear region")the decision whether or not to randomize the placement of the system's DRAM inside the linear map is based on the capabilities of the CPU rather than how much memory is present at boot time. This change was necessary because memory hotplug may result in DRAM appearing in places that are not covered by the linear region at all (and therefore unusable) if the decision is solely based on the memory map at boot.
In the Android GKI kernel, which requires support for memory hotplug, and is built with a reduced virtual address space of only 39 bits wide, randomization of the linear map never happens in practice as a result. And even on arm64 kernels built with support for 48 bit virtual addressing, the wider PArange of recent CPUs means that linear map randomization is slowly becoming a feature that only works on systems that will soon be obsolete.
So let's just remove this feature. We can always bring it back in an improved form if there is a real need for it.
Quoted 7 lines
Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Ryan Roberts <[email protected]>Cc Mark Rutland <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Kees Cook <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>
Additional note based on an off-list discussion with Kees and the KSPP team:
Initially, the randomization of the linear map was considered to be a layer of defense against the abuse of writable linear aliases of read-only mappings in the vmalloc range, such as module text and rodata. This has been addressed in the meantime, by mapping the linear region down to pages by default, and mapping linear aliases read-only if the vmalloc mapping is read-only.
So considering that, and the fact that randomization of the linear map occurs rarely if at all on recent CPUs, I think we should go ahead and remove this feature.
Quoted 23 lines · Ard Biesheuvel
Quoted 22 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Since commit
97d6786e0669("arm64: mm: account for hotplug memory when randomizing the linear region")the decision whether or not to randomize the placement of the system's DRAM inside the linear map is based on the capabilities of the CPU rather than how much memory is present at boot time. This change was necessary because memory hotplug may result in DRAM appearing in places that are not covered by the linear region at all (and therefore unusable) if the decision is solely based on the memory map at boot.
In the Android GKI kernel, which requires support for memory hotplug, and is built with a reduced virtual address space of only 39 bits wide, randomization of the linear map never happens in practice as a result. And even on arm64 kernels built with support for 48 bit virtual addressing, the wider PArange of recent CPUs means that linear map randomization is slowly becoming a feature that only works on systems that will soon be obsolete.
Quoted 2 lines
Quoted 2 lines
So let's just remove this feature. We can always bring it back in an improved form if there is a real need for it.
The argument certainly makes sense to me.
Quoted 9 lines
Quoted 8 lines
Cc Catalin Marinas <[email protected]>Cc Will Deacon <[email protected]>Cc Ryan Roberts <[email protected]>Cc Mark Rutland <[email protected]>Cc Anshuman Khandual <[email protected]>Cc Kees Cook <[email protected]>Signed-off-by Ard Biesheuvel <[email protected]>
Quoted 6 lines
Additional note based on an off-list discussion with Kees and the KSPP team:
Initially, the randomization of the linear map was considered to be a layer of defense against the abuse of writable linear aliases of read-only mappings in the vmalloc range, such as module text and rodata.
I would have assumed that there is already a level of randomization for this use case because vmalloc will be allocating random pages from the buddy, so the location of a given vmalloc alias in the linear map is already somewhat random?
Perhaps the regions of interest are allocated early in boot when the pages the buddy gives you are still pretty predictable? In this case could there be any argument for adding a capability to the buddy to give out somewhat randomised pages, at least during boot?
Quoted 7 lines
This has been addressed in the meantime, by mapping the linear region down to pages by default, and mapping linear aliases read-only if the vmalloc mapping is read-only.
So considering that, and the fact that randomization of the linear map occurs rarely if at all on recent CPUs, I think we should go ahead and remove this feature.
Quoted 4 lines · Ard Biesheuvel
Since commit
97d6786e0669("arm64: mm: account for hotplug memory when randomizing the linear region")
Quoted 8 lines
the decision whether or not to randomize the placement of the system's DRAM inside the linear map is based on the capabilities of the CPU rather than how much memory is present at boot time. This change was necessary because memory hotplug may result in DRAM appearing in places that are not covered by the linear region at all (and therefore unusable) if the decision is solely based on the memory map at boot.
[...]
Applied to arm64 (for-next/mm), thanks!
[1/1] arm64/mm: Remove randomization of the linear map
https://git.kernel.org/arm64/c/1db780bafa4c
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev