linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/kprobes: Simplify alloc_insn_page() with  __vmalloc_node_range
@ 2021-04-13 10:03 Jisheng Zhang
  2021-04-13 13:00 ` Masami Hiramatsu
  0 siblings, 1 reply; 9+ messages in thread
From: Jisheng Zhang @ 2021-04-13 10:03 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, x86,
	H. Peter Anvin, Masami Hiramatsu, Jiri Olsa
  Cc: linux-kernel

Use the __vmalloc_node_range() to simplify x86's alloc_insn_page()
implementation.

Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
---
 arch/x86/kernel/kprobes/core.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index df776cdca327..75081f3dbe44 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -383,26 +383,10 @@ static int prepare_boost(kprobe_opcode_t *buf, struct kprobe *p,
 /* Make page to RO mode when allocate it */
 void *alloc_insn_page(void)
 {
-	void *page;
-
-	page = module_alloc(PAGE_SIZE);
-	if (!page)
-		return NULL;
-
-	set_vm_flush_reset_perms(page);
-	/*
-	 * First make the page read-only, and only then make it executable to
-	 * prevent it from being W+X in between.
-	 */
-	set_memory_ro((unsigned long)page, 1);
-
-	/*
-	 * TODO: Once additional kernel code protection mechanisms are set, ensure
-	 * that the page was not maliciously altered and it is still zeroed.
-	 */
-	set_memory_x((unsigned long)page, 1);
-
-	return page;
+	return __vmalloc_node_range(PAGE_SIZE, PAGE_SIZE, VMALLOC_START,
+			VMALLOC_END, GFP_KERNEL, PAGE_KERNEL_ROX,
+			VM_FLUSH_RESET_PERMS, NUMA_NO_NODE,
+			__builtin_return_address(0));
 }
 
 /* Recover page to RW mode before releasing it */
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-04-16 13:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 10:03 [PATCH] x86/kprobes: Simplify alloc_insn_page() with __vmalloc_node_range Jisheng Zhang
2021-04-13 13:00 ` Masami Hiramatsu
2021-04-14  7:14   ` Jisheng Zhang
2021-04-14  7:27   ` Jisheng Zhang
2021-04-14  8:22     ` Masami Hiramatsu
2021-04-14 13:13       ` Jarkko Sakkinen
2021-04-14 13:12     ` Jarkko Sakkinen
2021-04-16  7:06       ` Jisheng Zhang
2021-04-16 13:11         ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).