riscv: fix kprobes on minimal kernel configs
v2 cover riscv: fix kprobes on minimal kernel configs
When building with an allnoconfig-derived minimal configuration (without CONFIG_STRICT_MODULE_RWX), kprobes fails because instruction slot pages from EXECMEM_KPROBES are read-only and patch_map() bypasses the fixmap writable alias.
These two patches fix the infrastructure.
v2:
- use CONFIG_STRICT_MODULE_RWX instead of CONFIG_ARCH_HAS_EXECMEM_ROX in PATCH 1/2 (per Nam Cao's review)
Xiaofeng Yuan (2):
riscv: mm: make EXECMEM_KPROBES writable without
CONFIG_STRICT_MODULE_RWX
riscv: patch: skip fixmap mapping when kernel text is already
writable
arch/riscv/kernel/patch.c | 3 ++- arch/riscv/mm/init.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-)
PATCH v2 1/2 riscv: mm: make EXECMEM_KPROBES writable without CONFIG_STRICT_MODULE_RWX
...
---
v2: use CONFIG_STRICT_MODULE_RWX instead of CONFIG_ARCH_HAS_EXECMEM_ROX (per Nam Cao's review)
arch/riscv/mm/init.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/riscv/mm/init.c +3 -1
@@ -1457,7 +1457,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] = {
Signature · 1 line
2.43.0
Re: [PATCH v2 1/2] riscv: mm: make EXECMEM_KPROBES writable without CONFIG_STRICT_MODULE_RWX
Quoted 3 lines · Xiaofeng Yuan
...
Signed-off-by Xiaofeng Yuan <[email protected]>
Commit description is missing.
For the diff:
PATCH v2 2/2 riscv: patch: skip fixmap mapping when kernel text is already writable
In reply to Xiaofeng Yuan...
--- arch/riscv/kernel/patch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/riscv/kernel/patch.c +2 -1
@@ -44,7 +44,8 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap)uintptr_t uintaddr = (uintptr_t ) addr;phys_addr_t phys; -if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) { +if (IS_ENABLED (CONFIG_STRICT_KERNEL_RWX ) && + (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr))) { phys =__pa_symbol (addr); }else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) {struct page *page =vmalloc_to_page (addr);
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] riscv: patch: skip fixmap mapping when kernel text is already writable
Quoted 3 lines · Xiaofeng Yuan
...
Signed-off-by Xiaofeng Yuan <[email protected]>
Also missing commit description.
Quoted 9 lines
--- arch/riscv/kernel/patch.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/riscv/kernel/patch.c +0
-0
arch/riscv/kernel/patch.c static __always_inline void *patch_map(void *addr, const unsigned int fixmap) · line 51
Quoted 9 lines
arch/riscv/kernel/patch.c +2
-1@@ -44,7 +44,8 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap)uintptr_t uintaddr = (uintptr_t ) addr;phys_addr_t phys; -if (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr)) { +if (IS_ENABLED (CONFIG_STRICT_KERNEL_RWX ) && + (core_kernel_text (uintaddr) ||is_kernel_exittext (uintaddr))) { phys =__pa_symbol (addr); }else if (IS_ENABLED (CONFIG_STRICT_MODULE_RWX )) {struct page *page =vmalloc_to_page (addr);
Probably cleaner to have
if (!IS_ENABLED(CONFIG_STRICT_MODULE_RWX))
return addr;
at the beginning of this function. And get rid ofCONFIG_STRICT_MODULE_RWX for the rest.
But looks functionally correct to me.
Nam