Skip to content

Commit 5185e7f

Browse files
rpptakpm00
authored andcommitted
x86/module: enable ROX caches for module text on 64 bit
Enable execmem's cache of PMD_SIZE'ed pages mapped as ROX for module text allocations on 64 bit. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Mike Rapoport (Microsoft) <[email protected]> Reviewed-by: Luis Chamberlain <[email protected]> Tested-by: kdevops <[email protected]> Cc: Andreas Larsson <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Borislav Petkov (AMD) <[email protected]> Cc: Brian Cain <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Christophe Leroy <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dinh Nguyen <[email protected]> Cc: Geert Uytterhoeven <[email protected]> Cc: Guo Ren <[email protected]> Cc: Helge Deller <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Johannes Berg <[email protected]> Cc: John Paul Adrian Glaubitz <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Liam R. Howlett <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Masami Hiramatsu (Google) <[email protected]> Cc: Matt Turner <[email protected]> Cc: Max Filippov <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Michal Simek <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Richard Weinberger <[email protected]> Cc: Russell King <[email protected]> Cc: Song Liu <[email protected]> Cc: Stafford Horne <[email protected]> Cc: Steven Rostedt (Google) <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Thomas Bogendoerfer <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Uladzislau Rezki (Sony) <[email protected]> Cc: Vineet Gupta <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 2e45474 commit 5185e7f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ config X86
8383
select ARCH_HAS_DMA_OPS if GART_IOMMU || XEN
8484
select ARCH_HAS_EARLY_DEBUG if KGDB
8585
select ARCH_HAS_ELF_RANDOMIZE
86+
select ARCH_HAS_EXECMEM_ROX if X86_64
8687
select ARCH_HAS_FAST_MULTIPLIER
8788
select ARCH_HAS_FORTIFY_SOURCE
8889
select ARCH_HAS_GCOV_PROFILE_ALL

arch/x86/mm/init.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,18 +1053,53 @@ unsigned long arch_max_swapfile_size(void)
10531053
#ifdef CONFIG_EXECMEM
10541054
static struct execmem_info execmem_info __ro_after_init;
10551055

1056+
#ifdef CONFIG_ARCH_HAS_EXECMEM_ROX
1057+
void execmem_fill_trapping_insns(void *ptr, size_t size, bool writeable)
1058+
{
1059+
/* fill memory with INT3 instructions */
1060+
if (writeable)
1061+
memset(ptr, INT3_INSN_OPCODE, size);
1062+
else
1063+
text_poke_set(ptr, INT3_INSN_OPCODE, size);
1064+
}
1065+
#endif
1066+
10561067
struct execmem_info __init *execmem_arch_setup(void)
10571068
{
10581069
unsigned long start, offset = 0;
1070+
enum execmem_range_flags flags;
1071+
pgprot_t pgprot;
10591072

10601073
if (kaslr_enabled())
10611074
offset = get_random_u32_inclusive(1, 1024) * PAGE_SIZE;
10621075

10631076
start = MODULES_VADDR + offset;
10641077

1078+
if (IS_ENABLED(CONFIG_ARCH_HAS_EXECMEM_ROX)) {
1079+
pgprot = PAGE_KERNEL_ROX;
1080+
flags = EXECMEM_KASAN_SHADOW | EXECMEM_ROX_CACHE;
1081+
} else {
1082+
pgprot = PAGE_KERNEL;
1083+
flags = EXECMEM_KASAN_SHADOW;
1084+
}
1085+
10651086
execmem_info = (struct execmem_info){
10661087
.ranges = {
1067-
[EXECMEM_DEFAULT] = {
1088+
[EXECMEM_MODULE_TEXT] = {
1089+
.flags = flags,
1090+
.start = start,
1091+
.end = MODULES_END,
1092+
.pgprot = pgprot,
1093+
.alignment = MODULE_ALIGN,
1094+
},
1095+
[EXECMEM_KPROBES ... EXECMEM_BPF] = {
1096+
.flags = EXECMEM_KASAN_SHADOW,
1097+
.start = start,
1098+
.end = MODULES_END,
1099+
.pgprot = PAGE_KERNEL,
1100+
.alignment = MODULE_ALIGN,
1101+
},
1102+
[EXECMEM_MODULE_DATA] = {
10681103
.flags = EXECMEM_KASAN_SHADOW,
10691104
.start = start,
10701105
.end = MODULES_END,

0 commit comments

Comments
 (0)