Re: [PATCH v5 1/2] riscv: mm: make EXECMEM_KPROBES writable without CONFIG_STRICT_MODULE_RWX

"Lad, Prabhakar" <[email protected]>
Newsgroups org.kernel.vger.linux-kernel,org.infradead.lists.linux-riscv
Message-ID <CA+V-a8snwsAHGF6RSmS+uwurcW3oOsW=-=NXwioB9x8A4e-RLQ@mail.gmail.com>
On Fri, Aug 14, 2026 at 9:29 AM Xiaofeng Yuan <[email protected]> wrote:
>
> When CONFIG_STRICT_MODULE_RWX is not set, execmem cannot create
> temporary writable mappings for read-only executable pages. In this
> case, the execmem ranges must already have writable permissions.
>
> Currently EXECMEM_KPROBES unconditionally uses PAGE_KERNEL_READ_EXEC,
> which causes kprobe instruction slot writes to trigger page faults
> on systems where CONFIG_STRICT_MODULE_RWX is not enabled.
>
> Fix this by using PAGE_KERNEL_EXEC when CONFIG_STRICT_MODULE_RWX
> is not available.
>
> Signed-off-by: Xiaofeng Yuan <[email protected]>
> ---
>  arch/riscv/mm/init.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
Tested-by: Lad Prabhakar <[email protected]>

Cheers,
Prabhakar

> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 85bdcce63a..b084a72e5d 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -1462,7 +1462,9 @@ struct execmem_info __init *execmem_arch_setup(void)
>                         [EXECMEM_KPROBES] = {
>                                 .start  = VMALLOC_START,
>                                 .end    = VMALLOC_END,
> -                               .pgprot = PAGE_KERNEL_READ_EXEC,
> +                               .pgprot = IS_ENABLED(CONFIG_STRICT_MODULE_RWX) ?
> +                                         PAGE_KERNEL_READ_EXEC :
> +                                         PAGE_KERNEL_EXEC,
>                                 .alignment = 1,
>                         },
>                         [EXECMEM_BPF] = {
> --
> 2.43.0
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.