arch_prepare_kprobe() writes the copied instruction and a single-step completion breakpoint into an out-of-line instruction slot, but does not synchronize the instruction cache for it. Due to arch_arm_kprobe() only flushing the probed instruction by calling flush_insn_slot(), the executable slot may remain unflushed when the kprobe is hit. On machines without coherent instruction and data caches, executing the slot can therefore fetch stale instructions. This becomes critical when get_insn_slot() reuses a just-freed slot. In this case, the instruction cache still holds a removed kprobe's copied instruction. Such misexecution may lead to obscure issues or kernel panics. Call flush_icache_range() to really finish the preparation, so that both the copied instruction and the single-step completion breakpoint are published for later use. Fixes: c1bf207d6ee1 ("MIPS: kprobe: Add support.") Cc: stable@vger.kernel.org Co-developed-by: Mike Yang Signed-off-by: Mike Yang Signed-off-by: Rong Zhang --- arch/mips/kernel/kprobes.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/mips/kernel/kprobes.c b/arch/mips/kernel/kprobes.c index dc39f5b3fb83..058f230d8faf 100644 --- a/arch/mips/kernel/kprobes.c +++ b/arch/mips/kernel/kprobes.c @@ -131,6 +131,15 @@ int arch_prepare_kprobe(struct kprobe *p) p->ainsn.insn[1] = breakpoint2_insn; p->opcode = *p->addr; + /* + * While arming the probe will flush the probed instruction, this + * publishes the copied instruction and the single-step breakpoint, + * which is crucial when reusing a slot. + */ + flush_icache_range((unsigned long)p->ainsn.insn, + (unsigned long)p->ainsn.insn + + (MAX_INSN_SIZE * sizeof(kprobe_opcode_t))); + out: return ret; } -- 2.55.0