Skip to content

Commit a3f547a

Browse files
Werkovhansendc
authored andcommitted
x86/mm: Do not shuffle CPU entry areas without KASLR
The commit 97e3d26 ("x86/mm: Randomize per-cpu entry area") fixed an omission of KASLR on CPU entry areas. It doesn't take into account KASLR switches though, which may result in unintended non-determinism when a user wants to avoid it (e.g. debugging, benchmarking). Generate only a single combination of CPU entry areas offsets -- the linear array that existed prior randomization when KASLR is turned off. Since we have 3f148f3 ("x86/kasan: Map shadow for percpu pages on demand") and followups, we can use the more relaxed guard kasrl_enabled() (in contrast to kaslr_memory_enabled()). Fixes: 97e3d26 ("x86/mm: Randomize per-cpu entry area") Signed-off-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/20230306193144.24605-1-mkoutny%40suse.com
1 parent cbebd68 commit a3f547a

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/mm/cpu_entry_area.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <asm/fixmap.h>
1111
#include <asm/desc.h>
1212
#include <asm/kasan.h>
13+
#include <asm/setup.h>
1314

1415
static DEFINE_PER_CPU_PAGE_ALIGNED(struct entry_stack_page, entry_stack_storage);
1516

@@ -29,6 +30,12 @@ static __init void init_cea_offsets(void)
2930
unsigned int max_cea;
3031
unsigned int i, j;
3132

33+
if (!kaslr_enabled()) {
34+
for_each_possible_cpu(i)
35+
per_cpu(_cea_offset, i) = i;
36+
return;
37+
}
38+
3239
max_cea = (CPU_ENTRY_AREA_MAP_SIZE - PAGE_SIZE) / CPU_ENTRY_AREA_SIZE;
3340

3441
/* O(sodding terrible) */

0 commit comments

Comments
 (0)