Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS Kprobes: Deny probes on ll/sc instructions

As ll/sc instruction are for atomic read-modify-write operations, allowing
probes on top of these insturctions is a bad idea.

Signed-off-by: Victor Kamensky <kamensky@cisco.com>
Signed-off-by: Maneesh Soni <manesoni@cisco.com>
Cc: David Daney <david.daney@cavium.com>
Cc: ananth@in.ibm.com
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/2912/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Maneesh Soni and committed by
Ralf Baechle
9233c1ee 41dde781

+31
+31
arch/mips/kernel/kprobes.c
··· 113 113 return 0; 114 114 } 115 115 116 + /* 117 + * insn_has_ll_or_sc function checks whether instruction is ll or sc 118 + * one; putting breakpoint on top of atomic ll/sc pair is bad idea; 119 + * so we need to prevent it and refuse kprobes insertion for such 120 + * instructions; cannot do much about breakpoint in the middle of 121 + * ll/sc pair; it is upto user to avoid those places 122 + */ 123 + static int __kprobes insn_has_ll_or_sc(union mips_instruction insn) 124 + { 125 + int ret = 0; 126 + 127 + switch (insn.i_format.opcode) { 128 + case ll_op: 129 + case lld_op: 130 + case sc_op: 131 + case scd_op: 132 + ret = 1; 133 + break; 134 + default: 135 + break; 136 + } 137 + return ret; 138 + } 139 + 116 140 int __kprobes arch_prepare_kprobe(struct kprobe *p) 117 141 { 118 142 union mips_instruction insn; ··· 144 120 int ret = 0; 145 121 146 122 insn = p->addr[0]; 123 + 124 + if (insn_has_ll_or_sc(insn)) { 125 + pr_notice("Kprobes for ll and sc instructions are not" 126 + "supported\n"); 127 + ret = -EINVAL; 128 + goto out; 129 + } 147 130 148 131 if (insn_has_delayslot(insn)) { 149 132 pr_notice("Kprobes for branch and jump instructions are not"