* [PATCH v4 0/4] powerpc: kprobes insn page fixes
@ 2026-11-26 4:25 Ritesh Harjani (IBM)
2026-11-26 4:25 ` [PATCH v4 1/4] powerpc/execmem: Don't leave kprobes insn pages W+X when CONFIG_MODULES=n Ritesh Harjani (IBM)
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Ritesh Harjani (IBM) @ 2026-11-26 4:25 UTC (permalink / raw)
To: linuxppc-dev
Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy,
Michael Ellerman, Nicholas Piggin, Shrikanth Hegde,
Ritesh Harjani (IBM)
Hi All,
Misc few fixes that came out of looking at a W+X warning at boot with
KPROBES=y and MODULES=n.
v3 -> v4:
=========
1. fixed the commit msg and added details for book3s/32 and 8xx in patch-2
v2 -> v3:
=========
1. Collected RB tags, addressed review comments & suggestions from Christophe
2. Removed PAGE_KERNEL_EXEC in the cleanup patch-4
v2: https://lore.kernel.org/linuxppc-dev/cover.1794572365.git.ritesh.list@gmail.com/
Ritesh Harjani (IBM) (4):
powerpc/execmem: Don't leave kprobes insn pages W+X when CONFIG_MODULES=n
powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32 and 8xx
powerpc/ptdump: Show the exec flag of kernel mappings on e500
powerpc/mm: Drop PAGE_KERNEL_EXEC
arch/powerpc/include/asm/pgtable.h | 3 ---
arch/powerpc/mm/mem.c | 15 +++++++++++----
arch/powerpc/mm/ptdump/shared.c | 6 +++---
3 files changed, 14 insertions(+), 10 deletions(-)
--
2.39.5
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4 1/4] powerpc/execmem: Don't leave kprobes insn pages W+X when CONFIG_MODULES=n
2026-11-26 4:25 [PATCH v4 0/4] powerpc: kprobes insn page fixes Ritesh Harjani (IBM)
@ 2026-11-26 4:25 ` Ritesh Harjani (IBM)
2026-11-26 4:26 ` [PATCH v4 2/4] powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32 and 8xx Ritesh Harjani (IBM)
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Ritesh Harjani (IBM) @ 2026-11-26 4:25 UTC (permalink / raw)
To: linuxppc-dev
Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy,
Michael Ellerman, Nicholas Piggin, Shrikanth Hegde,
Ritesh Harjani (IBM)
commit 2e83e2ce34ff ("arch, mm: promote DEBUG_WX to CHECK_WX"), made
CHECK_WX default STRICT_KERNEL_RWX.
Now on powerpc, when we boot with CONFIG_KPROBES=y and CONFIG_MODULES=n,
we can see the following warning splat at boot:
powerpc/mm: Found insecure W+X mapping at address 000000002ea08992/0xc008000000000000
WARNING: arch/powerpc/mm/ptdump/ptdump.c:194 at note_page+0x4dc/0x4fc, CPU#0: swapper/0/1
NIP [c0000000000ac204] note_page+0x4dc/0x4fc
LR [c0000000000ac200] note_page+0x4d8/0x4fc
Call Trace:
note_page+0x4d8/0x4fc (unreliable)
ptdump_pte_entry+0x70/0x94
walk_pte_range_inner+0x15c/0x260
walk_pgd_range+0x6d8/0xd5c
walk_page_range_debug+0xa4/0xf0
ptdump_walk_pgd+0xec/0x304
ptdump_check_wx+0xd8/0x154
kernel_init+0x94/0x26c
ret_from_kernel_user_thread+0x14/0x1c
Checked W+X mappings: FAILED, 1 W+X pages found
This happens because CHECK_WX noted a writeable + executable mapping.
This happens because execmem_arch_setup(), checks for
struct_modules_rwx_enabled(), while kprobes depenency on modules was earlier
removed via commit 7582b7be16d0 ("kprobes: remove dependency on CONFIG_MODULES")
Since the insn slots are only written with patch_instruction(), which does not
need this mapping to be writable. This patch fixes it by checking for
strict_kernel_rwx_enabled() instead.
Fixes: 7582b7be16d0 ("kprobes: remove dependency on CONFIG_MODULES")
Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
arch/powerpc/mm/mem.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index b617b69452cd..77b63b52d8f2 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -388,7 +388,7 @@ static void prealloc_execmem_pgtable(void) { }
struct execmem_info __init *execmem_arch_setup(void)
{
- pgprot_t kprobes_prot = strict_module_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
+ pgprot_t kprobes_prot = strict_kernel_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC;
unsigned long fallback_start = 0, fallback_end = 0;
unsigned long start, end;
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 2/4] powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32 and 8xx
2026-11-26 4:25 [PATCH v4 0/4] powerpc: kprobes insn page fixes Ritesh Harjani (IBM)
2026-11-26 4:25 ` [PATCH v4 1/4] powerpc/execmem: Don't leave kprobes insn pages W+X when CONFIG_MODULES=n Ritesh Harjani (IBM)
@ 2026-11-26 4:26 ` Ritesh Harjani (IBM)
2026-11-26 10:16 ` Christophe Leroy (CS GROUP)
2026-11-26 4:26 ` [PATCH v4 3/4] powerpc/ptdump: Show the exec flag of kernel mappings on e500 Ritesh Harjani (IBM)
2026-11-26 4:26 ` [PATCH v4 4/4] powerpc/mm: Drop PAGE_KERNEL_EXEC Ritesh Harjani (IBM)
3 siblings, 1 reply; 7+ messages in thread
From: Ritesh Harjani (IBM) @ 2026-11-26 4:26 UTC (permalink / raw)
To: linuxppc-dev
Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy,
Michael Ellerman, Nicholas Piggin, Shrikanth Hegde,
Ritesh Harjani (IBM), Mike Rapoport
On book3s/32, a kprobe on an instruction that can't be emulated and has
to be single stepped out of line, crashes the kernel. For e.g. with the
following cmds...
~> echo 9 > /proc/sys/kernel/printk
~> mount -t debugfs debugfs /sys/kernel/debug
~> echo 'p:wx filldir64+0xb8' > /sys/kernel/debug/tracing/kprobe_events
~> echo 1 > /sys/kernel/debug/tracing/events/kprobes/wx/enable
~> echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable
~> ls
...we can see the following crash:
kernel tried to execute exec-protected page (f101a008) - exploit attempt? (uid: 0)
BUG: Unable to handle kernel instruction fetch
Faulting instruction address: 0xc02b919c
Vector: 400 (Instruction Access) at [f19a9d60]
pc: c02b919c: filldir64+0xb8/0x2dc
lr: c02b9148: filldir64+0x64/0x2dc
sp: f19a9e20
msr: 10029032
current = 0xc112e900
pid = 102, comm = ls
enter ? for help
[f19a9e20] c1a8d420 (unreliable)
[f19a9e50] c02e4074 dcache_readdir+0x208/0x2a8
[f19a9e90] c02b8c5c iterate_dir+0x88/0x1fc
[f19a9ec0] c02b96e0 sys_getdents64+0x88/0x198
[f19a9f10] c0014400 system_call_exception+0xf8/0x20c
[f19a9f30] c00191ac ret_from_syscall+0x0/0x2c
---- Exception: c00 (System Call) at a7596164
SP (af802310) is in userspace
This happens because on book3s/32 the exec permission is per segment
(256MB), not per page. The page tables have no hardware exec bit, only
the segment registers have a no-execute (N) bit. mmu_mark_initmem_nx()
sets N on all the kernel segments except the ones of the modules area.
So nothing in the vmalloc area can be executed, even when the page is
mapped with PAGE_KERNEL_ROX or PAGE_KERNEL_EXEC, because _PAGE_EXEC is
a software only bit there and the segment's N bit is what the MMU
enforces.
8xx and 603 (which is book3s/32) have one more problem. Their ITLB miss
handlers walk only the current task's PGD, whose kernel entries are
copied from swapper_pg_dir in pgd_alloc(). Only kernel text and the
modules area are sure to be in that copy, the modules area because
prealloc_execmem_pgtable() creates its page tables at boot. Unlike the
DTLB path, nothing fixes up a missing entry on an ITLB miss. So an insn
page in a vmalloc area mapped after the task's PGD was allocated can't
be executed.
Before commit 1b750c2fbf82 ("powerpc: extend execmem_params for kprobes
allocations"), the kprobes insn pages came from module_alloc(). That
commit moved them to the whole of the vmalloc space, on the grounds that
kprobes use a breakpoint and don't need to be near the kernel text.
That is fine on platforms where the exec permission is per page,
as PAGE_KERNEL_ROX is then enough to make a vmalloc page executable.
It is not on book3s/32 and 8xx, where the modules area is not only close to
the kernel text but is also the only page-mapped area whose segment is
left executable. So the insn pages must keep coming from there.
MODULES_VADDR is only defined on book3s/32 and 8xx, so use the modules
area for EXECMEM_KPROBES whenever it is defined.
Fixes: 1b750c2fbf82 ("powerpc: extend execmem_params for kprobes allocations")
Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
arch/powerpc/mm/mem.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 77b63b52d8f2..8a0fdfd028dd 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -391,6 +391,7 @@ struct execmem_info __init *execmem_arch_setup(void)
pgprot_t kprobes_prot = strict_kernel_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC;
unsigned long fallback_start = 0, fallback_end = 0;
+ unsigned long kprobes_start, kprobes_end;
unsigned long start, end;
/*
@@ -410,9 +411,15 @@ struct execmem_info __init *execmem_arch_setup(void)
}
end = MODULES_END;
+
+ kprobes_start = MODULES_VADDR;
+ kprobes_end = MODULES_END;
#else
start = VMALLOC_START;
end = VMALLOC_END;
+
+ kprobes_start = VMALLOC_START;
+ kprobes_end = VMALLOC_END;
#endif
prealloc_execmem_pgtable();
@@ -428,8 +435,8 @@ struct execmem_info __init *execmem_arch_setup(void)
.fallback_end = fallback_end,
},
[EXECMEM_KPROBES] = {
- .start = VMALLOC_START,
- .end = VMALLOC_END,
+ .start = kprobes_start,
+ .end = kprobes_end,
.pgprot = kprobes_prot,
.alignment = 1,
},
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 3/4] powerpc/ptdump: Show the exec flag of kernel mappings on e500
2026-11-26 4:25 [PATCH v4 0/4] powerpc: kprobes insn page fixes Ritesh Harjani (IBM)
2026-11-26 4:25 ` [PATCH v4 1/4] powerpc/execmem: Don't leave kprobes insn pages W+X when CONFIG_MODULES=n Ritesh Harjani (IBM)
2026-11-26 4:26 ` [PATCH v4 2/4] powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32 and 8xx Ritesh Harjani (IBM)
@ 2026-11-26 4:26 ` Ritesh Harjani (IBM)
2026-11-26 4:26 ` [PATCH v4 4/4] powerpc/mm: Drop PAGE_KERNEL_EXEC Ritesh Harjani (IBM)
3 siblings, 0 replies; 7+ messages in thread
From: Ritesh Harjani (IBM) @ 2026-11-26 4:26 UTC (permalink / raw)
To: linuxppc-dev
Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy,
Michael Ellerman, Nicholas Piggin, Shrikanth Hegde,
Ritesh Harjani (IBM)
On e500, _PAGE_EXEC is made of two bits, _PAGE_BAP_SX and _PAGE_BAP_UX,
and a kernel mapping only has _PAGE_BAP_SX (supervisor bit). The flag
table requires all the bits of the mask to be set to print "X", so
kernel_page_tables never shows a kernel mapping as executable:
w/o this patch:
0xf1015000-0xf1015fff 0x00000000 4K PTE r present coherent accessed
Print "X" when any of the bits is set the same way it is done for
_PAGE_READ and _PAGE_WRITE:
with this patch:
0xf1015000-0xf1015fff 0x00000000 4K PTE r X present coherent accessed
This only changes what is displayed. ptdump_check_wx() uses pte_exec()
which already tests for either of the bits.
Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
arch/powerpc/mm/ptdump/shared.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/mm/ptdump/shared.c b/arch/powerpc/mm/ptdump/shared.c
index edc69da19b85..e28a41a8b1ac 100644
--- a/arch/powerpc/mm/ptdump/shared.c
+++ b/arch/powerpc/mm/ptdump/shared.c
@@ -22,9 +22,9 @@ static const struct flag_info flag_array[] = {
.clear = "w",
}, {
.mask = _PAGE_EXEC,
- .val = _PAGE_EXEC,
- .set = " X ",
- .clear = " ",
+ .val = 0,
+ .set = " ",
+ .clear = " X ",
}, {
.mask = _PAGE_PRESENT,
.val = _PAGE_PRESENT,
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 4/4] powerpc/mm: Drop PAGE_KERNEL_EXEC
2026-11-26 4:25 [PATCH v4 0/4] powerpc: kprobes insn page fixes Ritesh Harjani (IBM)
` (2 preceding siblings ...)
2026-11-26 4:26 ` [PATCH v4 3/4] powerpc/ptdump: Show the exec flag of kernel mappings on e500 Ritesh Harjani (IBM)
@ 2026-11-26 4:26 ` Ritesh Harjani (IBM)
3 siblings, 0 replies; 7+ messages in thread
From: Ritesh Harjani (IBM) @ 2026-11-26 4:26 UTC (permalink / raw)
To: linuxppc-dev
Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel, chleroy,
Michael Ellerman, Nicholas Piggin, Shrikanth Hegde,
Ritesh Harjani (IBM)
On powerpc PAGE_KERNEL_EXEC is just an alias to PAGE_KERNEL_X.
The comment above it's definition saying
("Make modules code happy. We don't set RO yet"), is stale.
Since commit 4fcc636615b1 ("powerpc/modules: Make module_alloc() Strict Module
RWX aware") module text is allocated with PAGE_KERNEL when STRICT_MODULE_RWX is
enabled and only made executable later, so there is no longer a reason for
a separate name.
Convert the remaining users to PAGE_KERNEL_X and remove the definition.
No functional change intended.
Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
arch/powerpc/include/asm/pgtable.h | 3 ---
arch/powerpc/mm/mem.c | 4 ++--
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
index d20ff2ae02f5..ea06a85f0fa8 100644
--- a/arch/powerpc/include/asm/pgtable.h
+++ b/arch/powerpc/include/asm/pgtable.h
@@ -20,9 +20,6 @@ struct mm_struct;
#include <asm/nohash/pgtable.h>
#endif /* !CONFIG_PPC_BOOK3S */
-/* Make modules code happy. We don't set RO yet */
-#define PAGE_KERNEL_EXEC PAGE_KERNEL_X
-
/* Advertise special mapping type for AGP */
#define PAGE_AGP (PAGE_KERNEL_NC)
#define HAVE_PAGE_AGP
diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 8a0fdfd028dd..bc83e45b7ae9 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -388,8 +388,8 @@ static void prealloc_execmem_pgtable(void) { }
struct execmem_info __init *execmem_arch_setup(void)
{
- pgprot_t kprobes_prot = strict_kernel_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
- pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC;
+ pgprot_t kprobes_prot = strict_kernel_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_X;
+ pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_X;
unsigned long fallback_start = 0, fallback_end = 0;
unsigned long kprobes_start, kprobes_end;
unsigned long start, end;
--
2.39.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v4 2/4] powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32 and 8xx
2026-11-26 4:26 ` [PATCH v4 2/4] powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32 and 8xx Ritesh Harjani (IBM)
@ 2026-11-26 10:16 ` Christophe Leroy (CS GROUP)
2026-11-26 13:26 ` Ritesh Harjani
0 siblings, 1 reply; 7+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-11-26 10:16 UTC (permalink / raw)
To: Ritesh Harjani (IBM), linuxppc-dev
Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel,
Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, Mike Rapoport
Le 26/11/2026 à 05:26, Ritesh Harjani (IBM) a écrit :
> On book3s/32, a kprobe on an instruction that can't be emulated and has
> to be single stepped out of line, crashes the kernel. For e.g. with the
> following cmds...
> ~> echo 9 > /proc/sys/kernel/printk
> ~> mount -t debugfs debugfs /sys/kernel/debug
> ~> echo 'p:wx filldir64+0xb8' > /sys/kernel/debug/tracing/kprobe_events
> ~> echo 1 > /sys/kernel/debug/tracing/events/kprobes/wx/enable
> ~> echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable
> ~> ls
>
> ...we can see the following crash:
> kernel tried to execute exec-protected page (f101a008) - exploit attempt? (uid: 0)
> BUG: Unable to handle kernel instruction fetch
> Faulting instruction address: 0xc02b919c
> Vector: 400 (Instruction Access) at [f19a9d60]
Unrelated to this patch, but shouldn't the above address [f19a9d60] be
identical to the one in the "kernel tried to execute exec-protected page
(f101a008)" ?
> pc: c02b919c: filldir64+0xb8/0x2dc
> lr: c02b9148: filldir64+0x64/0x2dc
> sp: f19a9e20
> msr: 10029032
> current = 0xc112e900
> pid = 102, comm = ls
> enter ? for help
> [f19a9e20] c1a8d420 (unreliable)
> [f19a9e50] c02e4074 dcache_readdir+0x208/0x2a8
> [f19a9e90] c02b8c5c iterate_dir+0x88/0x1fc
> [f19a9ec0] c02b96e0 sys_getdents64+0x88/0x198
> [f19a9f10] c0014400 system_call_exception+0xf8/0x20c
> [f19a9f30] c00191ac ret_from_syscall+0x0/0x2c
> ---- Exception: c00 (System Call) at a7596164
> SP (af802310) is in userspace
>
> This happens because on book3s/32 the exec permission is per segment
> (256MB), not per page. The page tables have no hardware exec bit, only
> the segment registers have a no-execute (N) bit. mmu_mark_initmem_nx()
> sets N on all the kernel segments except the ones of the modules area.
> So nothing in the vmalloc area can be executed, even when the page is
> mapped with PAGE_KERNEL_ROX or PAGE_KERNEL_EXEC, because _PAGE_EXEC is
> a software only bit there and the segment's N bit is what the MMU
> enforces.
>
> 8xx and 603 (which is book3s/32) have one more problem. Their ITLB miss
> handlers walk only the current task's PGD, whose kernel entries are
> copied from swapper_pg_dir in pgd_alloc(). Only kernel text and the
> modules area are sure to be in that copy, the modules area because
> prealloc_execmem_pgtable() creates its page tables at boot. Unlike the
> DTLB path, nothing fixes up a missing entry on an ITLB miss. So an insn
> page in a vmalloc area mapped after the task's PGD was allocated can't
> be executed.
>
> Before commit 1b750c2fbf82 ("powerpc: extend execmem_params for kprobes
> allocations"), the kprobes insn pages came from module_alloc(). That
> commit moved them to the whole of the vmalloc space, on the grounds that
> kprobes use a breakpoint and don't need to be near the kernel text.
> That is fine on platforms where the exec permission is per page,
> as PAGE_KERNEL_ROX is then enough to make a vmalloc page executable.
> It is not on book3s/32 and 8xx, where the modules area is not only close to
> the kernel text but is also the only page-mapped area whose segment is
> left executable. So the insn pages must keep coming from there.
>
> MODULES_VADDR is only defined on book3s/32 and 8xx, so use the modules
> area for EXECMEM_KPROBES whenever it is defined.
>
> Fixes: 1b750c2fbf82 ("powerpc: extend execmem_params for kprobes allocations")
> Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
> ---
> arch/powerpc/mm/mem.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
> index 77b63b52d8f2..8a0fdfd028dd 100644
> --- a/arch/powerpc/mm/mem.c
> +++ b/arch/powerpc/mm/mem.c
> @@ -391,6 +391,7 @@ struct execmem_info __init *execmem_arch_setup(void)
> pgprot_t kprobes_prot = strict_kernel_rwx_enabled() ? PAGE_KERNEL_ROX : PAGE_KERNEL_EXEC;
> pgprot_t prot = strict_module_rwx_enabled() ? PAGE_KERNEL : PAGE_KERNEL_EXEC;
> unsigned long fallback_start = 0, fallback_end = 0;
> + unsigned long kprobes_start, kprobes_end;
> unsigned long start, end;
>
> /*
> @@ -410,9 +411,15 @@ struct execmem_info __init *execmem_arch_setup(void)
> }
>
> end = MODULES_END;
> +
> + kprobes_start = MODULES_VADDR;
> + kprobes_end = MODULES_END;
> #else
> start = VMALLOC_START;
> end = VMALLOC_END;
> +
> + kprobes_start = VMALLOC_START;
> + kprobes_end = VMALLOC_END;
> #endif
>
> prealloc_execmem_pgtable();
> @@ -428,8 +435,8 @@ struct execmem_info __init *execmem_arch_setup(void)
> .fallback_end = fallback_end,
> },
> [EXECMEM_KPROBES] = {
> - .start = VMALLOC_START,
> - .end = VMALLOC_END,
> + .start = kprobes_start,
> + .end = kprobes_end,
> .pgprot = kprobes_prot,
> .alignment = 1,
> },
> --
> 2.39.5
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4 2/4] powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32 and 8xx
2026-11-26 10:16 ` Christophe Leroy (CS GROUP)
@ 2026-11-26 13:26 ` Ritesh Harjani
0 siblings, 0 replies; 7+ messages in thread
From: Ritesh Harjani @ 2026-11-26 13:26 UTC (permalink / raw)
To: Christophe Leroy (CS GROUP), linuxppc-dev
Cc: Madhavan Srinivasan, Venkat Rao Bagalkote, linux-kernel,
Michael Ellerman, Nicholas Piggin, Shrikanth Hegde, Mike Rapoport
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org> writes:
> Le 26/11/2026 à 05:26, Ritesh Harjani (IBM) a écrit :
>> On book3s/32, a kprobe on an instruction that can't be emulated and has
>> to be single stepped out of line, crashes the kernel. For e.g. with the
>> following cmds...
>> ~> echo 9 > /proc/sys/kernel/printk
>> ~> mount -t debugfs debugfs /sys/kernel/debug
>> ~> echo 'p:wx filldir64+0xb8' > /sys/kernel/debug/tracing/kprobe_events
>> ~> echo 1 > /sys/kernel/debug/tracing/events/kprobes/wx/enable
>> ~> echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable
>> ~> ls
>>
>> ...we can see the following crash:
>> kernel tried to execute exec-protected page (f101a008) - exploit attempt? (uid: 0)
>> BUG: Unable to handle kernel instruction fetch
>> Faulting instruction address: 0xc02b919c
>> Vector: 400 (Instruction Access) at [f19a9d60]
>
> Unrelated to this patch, but shouldn't the above address [f19a9d60] be
> identical to the one in the "kernel tried to execute exec-protected page
> (f101a008)" ?
>
Actually this log is taken from xmon. So [f19a9d60] is not a fault
address. xmon prints the address of the exception frame (pt_regs) there,
i.e.
arch/powerpc/xmon/xmon.c
static void excprint(struct pt_regs *fp)
{
unsigned long trap;
#ifdef CONFIG_SMP
printf("cpu 0x%x: ", smp_processor_id());
#endif /* CONFIG_SMP */
trap = TRAP(fp);
printf("Vector: %lx %s at [%px]\n", fp->trap, getvecname(trap), fp);
^^^ it comes from this print here
>> pc: c02b919c: filldir64+0xb8/0x2dc
>> lr: c02b9148: filldir64+0x64/0x2dc
>> sp: f19a9e20
>> msr: 10029032
>> current = 0xc112e900
>> pid = 102, comm = ls
>> enter ? for help
>> [f19a9e20] c1a8d420 (unreliable)
>> [f19a9e50] c02e4074 dcache_readdir+0x208/0x2a8
>> [f19a9e90] c02b8c5c iterate_dir+0x88/0x1fc
>> [f19a9ec0] c02b96e0 sys_getdents64+0x88/0x198
>> [f19a9f10] c0014400 system_call_exception+0xf8/0x20c
>> [f19a9f30] c00191ac ret_from_syscall+0x0/0x2c
>> ---- Exception: c00 (System Call) at a7596164
>> SP (af802310) is in userspace
>>
>> This happens because on book3s/32 the exec permission is per segment
>> (256MB), not per page. The page tables have no hardware exec bit, only
>> the segment registers have a no-execute (N) bit. mmu_mark_initmem_nx()
>> sets N on all the kernel segments except the ones of the modules area.
>> So nothing in the vmalloc area can be executed, even when the page is
>> mapped with PAGE_KERNEL_ROX or PAGE_KERNEL_EXEC, because _PAGE_EXEC is
>> a software only bit there and the segment's N bit is what the MMU
>> enforces.
>>
>> 8xx and 603 (which is book3s/32) have one more problem. Their ITLB miss
>> handlers walk only the current task's PGD, whose kernel entries are
>> copied from swapper_pg_dir in pgd_alloc(). Only kernel text and the
>> modules area are sure to be in that copy, the modules area because
>> prealloc_execmem_pgtable() creates its page tables at boot. Unlike the
>> DTLB path, nothing fixes up a missing entry on an ITLB miss. So an insn
>> page in a vmalloc area mapped after the task's PGD was allocated can't
>> be executed.
>>
>> Before commit 1b750c2fbf82 ("powerpc: extend execmem_params for kprobes
>> allocations"), the kprobes insn pages came from module_alloc(). That
>> commit moved them to the whole of the vmalloc space, on the grounds that
>> kprobes use a breakpoint and don't need to be near the kernel text.
>> That is fine on platforms where the exec permission is per page,
>> as PAGE_KERNEL_ROX is then enough to make a vmalloc page executable.
>> It is not on book3s/32 and 8xx, where the modules area is not only close to
>> the kernel text but is also the only page-mapped area whose segment is
>> left executable. So the insn pages must keep coming from there.
>>
>> MODULES_VADDR is only defined on book3s/32 and 8xx, so use the modules
>> area for EXECMEM_KPROBES whenever it is defined.
>>
>> Fixes: 1b750c2fbf82 ("powerpc: extend execmem_params for kprobes allocations")
>> Suggested-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
>> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
>> Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
>> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
>
> Reviewed-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
>
Thanks Christophe for your reviews and suggestions!
-ritesh
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-26 13:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 4:25 [PATCH v4 0/4] powerpc: kprobes insn page fixes Ritesh Harjani (IBM)
2026-11-26 4:25 ` [PATCH v4 1/4] powerpc/execmem: Don't leave kprobes insn pages W+X when CONFIG_MODULES=n Ritesh Harjani (IBM)
2026-11-26 4:26 ` [PATCH v4 2/4] powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32 and 8xx Ritesh Harjani (IBM)
2026-11-26 10:16 ` Christophe Leroy (CS GROUP)
2026-11-26 13:26 ` Ritesh Harjani
2026-11-26 4:26 ` [PATCH v4 3/4] powerpc/ptdump: Show the exec flag of kernel mappings on e500 Ritesh Harjani (IBM)
2026-11-26 4:26 ` [PATCH v4 4/4] powerpc/mm: Drop PAGE_KERNEL_EXEC Ritesh Harjani (IBM)
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.