mips/kprobes: flush_insn_slot should flush only if probe initialised
diff mbox

Message ID -
State Accepted
Delegated to: Ralf Baechle
Headers show

Commit Message

Marcin Nowakowski June 8, 2017, 1:20 p.m. UTC
When ftrace is used with kprobes, it is possible for a kprobe to contain
an invalid location (ie. only initialised to 0 and not to a specific
location in the code). Trying to perform a cache flush on such location
leads to a crash r4k_flush_icache_range().

Signed-off-by: Marcin Nowakowski <>
---
 arch/mips/include/asm/kprobes.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Ralf Baechle June 8, 2017, 1:41 p.m. UTC | #1
On Thu, Jun 08, 2017 at 03:20:32PM +0200, Marcin Nowakowski wrote:

> When ftrace is used with kprobes, it is possible for a kprobe to contain
> an invalid location (ie. only initialised to 0 and not to a specific
> location in the code). Trying to perform a cache flush on such location
> leads to a crash r4k_flush_icache_range().

Cute, 2.6.36+ ...

Applied,

  Ralf

Patch
diff mbox

diff --git a/arch/mips/include/asm/kprobes.h b/arch/mips/include/asm/kprobes.h
index 291846d..ad1a999 100644
--- a/arch/mips/include/asm/kprobes.h
+++ b/arch/mips/include/asm/kprobes.h
@@ -43,7 +43,8 @@  typedef union mips_instruction kprobe_opcode_t;
 
 #define flush_insn_slot(p)						\
 do {									\
-	flush_icache_range((unsigned long)p->addr,			\
+	if (p->addr)							\
+		flush_icache_range((unsigned long)p->addr,		\
 			   (unsigned long)p->addr +			\
 			   (MAX_INSN_SIZE * sizeof(kprobe_opcode_t)));	\
 } while (0)