Skip to content

Commit 6ca0553

Browse files
chleroympe
authored andcommitted
powerpc/32s: Use dedicated segment for modules with STRICT_KERNEL_RWX
When STRICT_KERNEL_RWX is set, we want to set NX bit on vmalloc segments. But modules require exec. Use a dedicated segment for modules. There is not much space above kernel, and we don't waste vmalloc space to do alignment. Therefore, we take the segment before PAGE_OFFSET for modules. Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/eb8faba9148b6cf17c696ba776b4e8ee2f6313bf.1593428200.git.christophe.leroy@csgroup.eu
1 parent f1a1f7a commit 6ca0553

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,7 @@ config TASK_SIZE_BOOL
12131213
config TASK_SIZE
12141214
hex "Size of user task space" if TASK_SIZE_BOOL
12151215
default "0x80000000" if PPC_8xx
1216+
default "0xb0000000" if PPC_BOOK3S_32 && STRICT_KERNEL_RWX
12161217
default "0xc0000000"
12171218
endmenu
12181219

arch/powerpc/include/asm/book3s/32/pgtable.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,19 @@ int map_kernel_page(unsigned long va, phys_addr_t pa, pgprot_t prot);
184184
*/
185185
#define VMALLOC_OFFSET (0x1000000) /* 16M */
186186

187-
/*
188-
* With CONFIG_STRICT_KERNEL_RWX, kernel segments are set NX. But when modules
189-
* are used, NX cannot be set on VMALLOC space. So vmalloc VM space and linear
190-
* memory shall not share segments.
191-
*/
192-
#if defined(CONFIG_STRICT_KERNEL_RWX) && defined(CONFIG_MODULES)
193-
#define VMALLOC_START ((ALIGN((long)high_memory, 256L << 20) + VMALLOC_OFFSET) & \
194-
~(VMALLOC_OFFSET - 1))
195-
#else
196187
#define VMALLOC_START ((((long)high_memory + VMALLOC_OFFSET) & ~(VMALLOC_OFFSET-1)))
197-
#endif
198188

199189
#ifdef CONFIG_KASAN_VMALLOC
200190
#define VMALLOC_END ALIGN_DOWN(ioremap_bot, PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
201191
#else
202192
#define VMALLOC_END ioremap_bot
203193
#endif
204194

195+
#ifdef CONFIG_STRICT_KERNEL_RWX
196+
#define MODULES_END ALIGN_DOWN(PAGE_OFFSET, SZ_256M)
197+
#define MODULES_VADDR (MODULES_END - SZ_256M)
198+
#endif
199+
205200
#ifndef __ASSEMBLY__
206201
#include <linux/sched.h>
207202
#include <linux/threads.h>

arch/powerpc/mm/ptdump/ptdump.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ struct addr_marker {
7474

7575
static struct addr_marker address_markers[] = {
7676
{ 0, "Start of kernel VM" },
77+
#ifdef MODULES_VADDR
78+
{ 0, "modules start" },
79+
{ 0, "modules end" },
80+
#endif
7781
{ 0, "vmalloc() Area" },
7882
{ 0, "vmalloc() End" },
7983
#ifdef CONFIG_PPC64
@@ -352,6 +356,10 @@ static void populate_markers(void)
352356
address_markers[i++].start_address = PAGE_OFFSET;
353357
#else
354358
address_markers[i++].start_address = TASK_SIZE;
359+
#endif
360+
#ifdef MODULES_VADDR
361+
address_markers[i++].start_address = MODULES_VADDR;
362+
address_markers[i++].start_address = MODULES_END;
355363
#endif
356364
address_markers[i++].start_address = VMALLOC_START;
357365
address_markers[i++].start_address = VMALLOC_END;

0 commit comments

Comments
 (0)