Re: [PATCH v13 3/8] powerpc/kprobes: Mark newly allocated probes as ROX

2021-05-13 Thread Christophe Leroy




Le 10/05/2021 à 03:18, Jordan Niethe a écrit :

From: Russell Currey 

Add the arch specific insn page allocator for powerpc. This allocates
ROX pages if STRICT_KERNEL_RWX is enabled. These pages are only written
to with patch_instruction() which is able to write RO pages.

Reviewed-by: Daniel Axtens 
Signed-off-by: Russell Currey 
Signed-off-by: Christophe Leroy 
[jpn: Reword commit message, switch to __vmalloc_node_range()]
Signed-off-by: Jordan Niethe 
---
v9: - vmalloc_exec() no longer exists
 - Set the page to RW before freeing it
v10: - use __vmalloc_node_range()
v11: - Neaten up
v12: - Switch from __vmalloc_node_range() to module_alloc()
v13: Use strict_kernel_rwx_enabled()
---
  arch/powerpc/kernel/kprobes.c | 17 +
  1 file changed, 17 insertions(+)

diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 01ab2163659e..b517f3e6e7c5 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -19,11 +19,13 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
  #include 
  #include 
+#include 
  #include 
  
  DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;

@@ -103,6 +105,21 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, 
unsigned int offset)
return addr;
  }
  
+void *alloc_insn_page(void)

+{
+   void *page;
+
+   page = module_alloc(PAGE_SIZE);
+   if (!page)
+   return NULL;
+
+   if (strict_kernel_rwx_enabled()) {


I'm not sure this is OK.

I think we need to make a new helper strict_module_rwx_enabled() because I don't think we want to 
call that when CONFIG_STRICT_MODULE_RWX is not selected.




+   set_memory_ro((unsigned long)page, 1);
+   set_memory_x((unsigned long)page, 1);
+   }
+   return page;
+}
+
  int arch_prepare_kprobe(struct kprobe *p)
  {
int ret = 0;



[PATCH v13 3/8] powerpc/kprobes: Mark newly allocated probes as ROX

2021-05-09 Thread Jordan Niethe
From: Russell Currey 

Add the arch specific insn page allocator for powerpc. This allocates
ROX pages if STRICT_KERNEL_RWX is enabled. These pages are only written
to with patch_instruction() which is able to write RO pages.

Reviewed-by: Daniel Axtens 
Signed-off-by: Russell Currey 
Signed-off-by: Christophe Leroy 
[jpn: Reword commit message, switch to __vmalloc_node_range()]
Signed-off-by: Jordan Niethe 
---
v9: - vmalloc_exec() no longer exists
- Set the page to RW before freeing it
v10: - use __vmalloc_node_range()
v11: - Neaten up
v12: - Switch from __vmalloc_node_range() to module_alloc()
v13: Use strict_kernel_rwx_enabled()
---
 arch/powerpc/kernel/kprobes.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c
index 01ab2163659e..b517f3e6e7c5 100644
--- a/arch/powerpc/kernel/kprobes.c
+++ b/arch/powerpc/kernel/kprobes.c
@@ -19,11 +19,13 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
@@ -103,6 +105,21 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, 
unsigned int offset)
return addr;
 }
 
+void *alloc_insn_page(void)
+{
+   void *page;
+
+   page = module_alloc(PAGE_SIZE);
+   if (!page)
+   return NULL;
+
+   if (strict_kernel_rwx_enabled()) {
+   set_memory_ro((unsigned long)page, 1);
+   set_memory_x((unsigned long)page, 1);
+   }
+   return page;
+}
+
 int arch_prepare_kprobe(struct kprobe *p)
 {
int ret = 0;
-- 
2.25.1