mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-06 10:00:17 +00:00
riscv: kprobes: Fix probe address validation
When adding a kprobe such as "p:probe/tcp_sendmsg _text+15392192",
arch_check_kprobe would start iterating all instructions starting from
_text until the probed address. Not only is this very inefficient, but
literal values in there (e.g. left by function patching) are
misinterpreted in a way that causes a desync.
Fix this by doing it like x86: start the iteration at the closest
preceding symbol instead of the given starting point.
Fixes: 87f48c7ccc ("riscv: kprobe: Fixup kernel panic when probing an illegal position")
Signed-off-by: Fabian Vogt <fvogt@suse.de>
Signed-off-by: Marvin Friedrich <marvin.friedrich@suse.com>
Acked-by: Guo Ren <guoren@kernel.org>
Link: https://lore.kernel.org/r/6191817.lOV4Wx5bFT@fvogt-thinkpad
Signed-off-by: Paul Walmsley <pjw@kernel.org>
This commit is contained in:
committed by
Paul Walmsley
parent
c199745d3a
commit
9e68bd803f
@@ -49,10 +49,15 @@ static void __kprobes arch_simulate_insn(struct kprobe *p, struct pt_regs *regs)
|
|||||||
post_kprobe_handler(p, kcb, regs);
|
post_kprobe_handler(p, kcb, regs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool __kprobes arch_check_kprobe(struct kprobe *p)
|
static bool __kprobes arch_check_kprobe(unsigned long addr)
|
||||||
{
|
{
|
||||||
unsigned long tmp = (unsigned long)p->addr - p->offset;
|
unsigned long tmp, offset;
|
||||||
unsigned long addr = (unsigned long)p->addr;
|
|
||||||
|
/* start iterating at the closest preceding symbol */
|
||||||
|
if (!kallsyms_lookup_size_offset(addr, NULL, &offset))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
tmp = addr - offset;
|
||||||
|
|
||||||
while (tmp <= addr) {
|
while (tmp <= addr) {
|
||||||
if (tmp == addr)
|
if (tmp == addr)
|
||||||
@@ -71,7 +76,7 @@ int __kprobes arch_prepare_kprobe(struct kprobe *p)
|
|||||||
if ((unsigned long)insn & 0x1)
|
if ((unsigned long)insn & 0x1)
|
||||||
return -EILSEQ;
|
return -EILSEQ;
|
||||||
|
|
||||||
if (!arch_check_kprobe(p))
|
if (!arch_check_kprobe((unsigned long)p->addr))
|
||||||
return -EILSEQ;
|
return -EILSEQ;
|
||||||
|
|
||||||
/* copy instruction */
|
/* copy instruction */
|
||||||
|
|||||||
Reference in New Issue
Block a user