2323#include <linux/slab.h>
2424#include <linux/stop_machine.h>
2525#include <linux/sched/debug.h>
26+ #include <linux/set_memory.h>
2627#include <linux/stringify.h>
28+ #include <linux/vmalloc.h>
2729#include <asm/traps.h>
2830#include <asm/ptrace.h>
2931#include <asm/cacheflush.h>
@@ -42,10 +44,21 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
4244static void __kprobes
4345post_kprobe_handler (struct kprobe_ctlblk * , struct pt_regs * );
4446
47+ static int __kprobes patch_text (kprobe_opcode_t * addr , u32 opcode )
48+ {
49+ void * addrs [1 ];
50+ u32 insns [1 ];
51+
52+ addrs [0 ] = addr ;
53+ insns [0 ] = opcode ;
54+
55+ return aarch64_insn_patch_text (addrs , insns , 1 );
56+ }
57+
4558static void __kprobes arch_prepare_ss_slot (struct kprobe * p )
4659{
4760 /* prepare insn slot */
48- p -> ainsn .api .insn [ 0 ] = cpu_to_le32 ( p -> opcode );
61+ patch_text ( p -> ainsn .api .insn , p -> opcode );
4962
5063 flush_icache_range ((uintptr_t ) (p -> ainsn .api .insn ),
5164 (uintptr_t ) (p -> ainsn .api .insn ) +
@@ -118,15 +131,15 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
118131 return 0 ;
119132}
120133
121- static int __kprobes patch_text ( kprobe_opcode_t * addr , u32 opcode )
134+ void * alloc_insn_page ( void )
122135{
123- void * addrs [1 ];
124- u32 insns [1 ];
136+ void * page ;
125137
126- addrs [0 ] = (void * )addr ;
127- insns [0 ] = (u32 )opcode ;
138+ page = vmalloc_exec (PAGE_SIZE );
139+ if (page )
140+ set_memory_ro ((unsigned long )page , 1 );
128141
129- return aarch64_insn_patch_text ( addrs , insns , 1 ) ;
142+ return page ;
130143}
131144
132145/* arm kprobe: install breakpoint in text */
0 commit comments