All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
To: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	linuxppc-dev@lists.ozlabs.org
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>,
	Venkat Rao Bagalkote <venkat88@linux.ibm.com>,
	linux-kernel@vger.kernel.org,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	Mike Rapoport <rppt@kernel.org>
Subject: Re: [PATCHv3 2/4] powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32
Date: Thu, 26 Nov 2026 08:53:37 +0530	[thread overview]
Message-ID: <ld6gjmx2.ritesh.list@gmail.com> (raw)
In-Reply-To: <92b40ffa-c9bd-4d1c-b60b-f27e89102f9d@kernel.org>

"Christophe Leroy (CS GROUP)" <chleroy@kernel.org> writes:

> Hi Ritesh,
>
> There is a problem with the subject of most of your patches: the space 
> between "PATCH" and "v3" is missing, therefore patchwork doesn't fully 
> understand and it doesn't remove the PATCH word as it does when the 
> space is there. I have not checked whether b4 understands it.
>

Thanks so much for pointing that out. Ealier I used to have a space
between PATCH and vxx, however once a kernel release manager of a
different area, told me that their script is missing my changes, though
he fixed his internal script - but later I decided maybe to remove that
space.

Looking at this a bit more closer, I agree, I should keep that space.
Seems like Sashiko is also unhappy when we don't have that. Looks like
w/o a space, it doesn't mark it as a series and rather consider the
series as individual patches.

> Le 25/11/2026 à 17:52, 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
>> 
>> ...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.
>> 
>> 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, 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.
>> 
>> Hence, use the modules area for EXECMEM_KPROBES on book3s/32.
>
> The patch is now correct as it now if #ifdef MODULES_VADDR block, but 
> the description is incomplete.
>
> The description misses the 8xx for the reason explained here: 
> https://lore.kernel.org/all/f7834f3e-6c43-4b58-806d-fe4c07a93457@kernel.org/
>
> And that reason also applies to book3s/32, as reminded here by yourself: 
> https://lore.kernel.org/all/zev77i3i.ritesh.list@gmail.com/
>

I remember updating the commit msg somewhere, however seems like I might
have overwrote it and lost that change.

let me fix that up in v4 like this -


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.


-ritesh





  reply	other threads:[~2026-11-26  4:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 16:52 [PATCHv3 0/4] powerpc: kprobes insn page fixes Ritesh Harjani (IBM)
2026-11-25 16:52 ` [PATCHv3 1/4] powerpc/execmem: Don't leave kprobes insn pages W+X when CONFIG_MODULES=n Ritesh Harjani (IBM)
2026-11-25 18:49   ` Christophe Leroy (CS GROUP)
2026-11-25 16:52 ` [PATCHv3 2/4] powerpc/execmem: Allocate kprobes insn pages from the modules area on book3s/32 Ritesh Harjani (IBM)
2026-11-25 18:47   ` Christophe Leroy (CS GROUP)
2026-11-26  3:23     ` Ritesh Harjani [this message]
2026-11-25 16:52 ` [PATCHv3 3/4] powerpc/ptdump: Show the exec flag of kernel mappings on e500 Ritesh Harjani (IBM)
2026-11-25 16:52 ` [PATCHv3 4/4] powerpc/mm: Drop PAGE_KERNEL_EXEC Ritesh Harjani (IBM)
2026-11-25 18:49   ` Christophe Leroy (CS GROUP)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ld6gjmx2.ritesh.list@gmail.com \
    --to=ritesh.list@gmail.com \
    --cc=chleroy@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=rppt@kernel.org \
    --cc=sshegde@linux.ibm.com \
    --cc=venkat88@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.