Skip to content

Commit b4657f7

Browse files
iamjpnmpe
authored andcommitted
powerpc/kprobes: Don't allow breakpoints on suffixes
Do not allow inserting breakpoints on the suffix of a prefix instruction in kprobes. Signed-off-by: Jordan Niethe <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c9c831a commit b4657f7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

arch/powerpc/kernel/kprobes.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,27 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset)
106106
int arch_prepare_kprobe(struct kprobe *p)
107107
{
108108
int ret = 0;
109+
struct kprobe *prev;
109110
struct ppc_inst insn = ppc_inst_read((struct ppc_inst *)p->addr);
111+
struct ppc_inst prefix = ppc_inst_read((struct ppc_inst *)(p->addr - 1));
110112

111113
if ((unsigned long)p->addr & 0x03) {
112114
printk("Attempt to register kprobe at an unaligned address\n");
113115
ret = -EINVAL;
114116
} else if (IS_MTMSRD(insn) || IS_RFID(insn) || IS_RFI(insn)) {
115117
printk("Cannot register a kprobe on rfi/rfid or mtmsr[d]\n");
116118
ret = -EINVAL;
119+
} else if (ppc_inst_prefixed(prefix)) {
120+
printk("Cannot register a kprobe on the second word of prefixed instruction\n");
121+
ret = -EINVAL;
122+
}
123+
preempt_disable();
124+
prev = get_kprobe(p->addr - 1);
125+
preempt_enable_no_resched();
126+
if (prev &&
127+
ppc_inst_prefixed(ppc_inst_read((struct ppc_inst *)prev->ainsn.insn))) {
128+
printk("Cannot register a kprobe on the second word of prefixed instruction\n");
129+
ret = -EINVAL;
117130
}
118131

119132
/* insn must be on a special executable page on ppc64. This is

0 commit comments

Comments
 (0)