23
23
#include <linux/slab.h>
24
24
#include <linux/stop_machine.h>
25
25
#include <linux/sched/debug.h>
26
+ #include <linux/set_memory.h>
26
27
#include <linux/stringify.h>
28
+ #include <linux/vmalloc.h>
27
29
#include <asm/traps.h>
28
30
#include <asm/ptrace.h>
29
31
#include <asm/cacheflush.h>
@@ -42,10 +44,21 @@ DEFINE_PER_CPU(struct kprobe_ctlblk, kprobe_ctlblk);
42
44
static void __kprobes
43
45
post_kprobe_handler (struct kprobe_ctlblk * , struct pt_regs * );
44
46
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
+
45
58
static void __kprobes arch_prepare_ss_slot (struct kprobe * p )
46
59
{
47
60
/* prepare insn slot */
48
- p -> ainsn .api .insn [ 0 ] = cpu_to_le32 ( p -> opcode );
61
+ patch_text ( p -> ainsn .api .insn , p -> opcode );
49
62
50
63
flush_icache_range ((uintptr_t ) (p -> ainsn .api .insn ),
51
64
(uintptr_t ) (p -> ainsn .api .insn ) +
@@ -118,15 +131,15 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
118
131
return 0 ;
119
132
}
120
133
121
- static int __kprobes patch_text ( kprobe_opcode_t * addr , u32 opcode )
134
+ void * alloc_insn_page ( void )
122
135
{
123
- void * addrs [1 ];
124
- u32 insns [1 ];
136
+ void * page ;
125
137
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 );
128
141
129
- return aarch64_insn_patch_text ( addrs , insns , 1 ) ;
142
+ return page ;
130
143
}
131
144
132
145
/* arm kprobe: install breakpoint in text */
0 commit comments