riscv: kprobes: fix placement in arch_prepare_ss_slot
PATCH 1/1 riscv: kprobes: fix placement in arch_prepare_ss_slot
The second patch_text_nosync() in arch_prepare_ss_slot should be pointing after the first instruction, however p->ainsn.api.insn is a pointer to a probe_opcode_t which is 4 bytes... this means an instruction of length 2 moves the pointer by 8 bytes.
This means a kprobe may fail to work and recurse into the bad instruction handler (which then itself fails as the original lock still seems to be held?)
--- arch/riscv/kernel/probes/kprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/probes/kprobes.c +1 -1
@@ -30,7 +30,7 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p) p->ainsn.api.restore = (unsigned long )p->addr + len;patch_text_nosync (p->ainsn.api.insn, &p->opcode, len); -patch_text_nosync (p->ainsn.api.insn + len, &insn,GET_INSN_LENGTH (insn)); +patch_text_nosync ((void *)p->ainsn.api.insn + len, &insn,GET_INSN_LENGTH (insn)); }static void __kprobes arch_prepare_simulate (struct kprobe *p)
Signature · 7 lines
2.37.2.352.g3c44437643 _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv
Alexandre Ghiti
reviewerHi Ben,
Quoted 21 lines · Ben Dooks
The second
patch_text_nosync()inarch_prepare_ss_slotshould be pointing after the first instruction, howeverp->ainsn.api.insnis a pointer to aprobe_opcode_twhich is 4 bytes... this means an instruction of length 2 moves the pointer by 8 bytes.This means a kprobe may fail to work and recurse into the bad instruction handler (which then itself fails as the original lock still seems to be held?)
Fixes b1756750a397f36ddc857 ("riscv: kprobes: Use patch_text_nosync() for insn slots")Signed-off-by Ben Dooks <[email protected]>Cc Samuel Holland <[email protected]>--- arch/riscv/kernel/probes/kprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/riscv/kernel/probes/kprobes.c +0
-0
arch/riscv/kernel/probes/kprobes.c static void __kprobes arch_prepare_ss_slot(struct kprobe *p) · line 36
Quoted 8 lines
arch/riscv/kernel/probes/kprobes.c +1
-1@@ -30,7 +30,7 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p) p->ainsn.api.restore = (unsigned long )p->addr + len;patch_text_nosync (p->ainsn.api.insn, &p->opcode, len); -patch_text_nosync (p->ainsn.api.insn + len, &insn,GET_INSN_LENGTH (insn)); +patch_text_nosync ((void *)p->ainsn.api.insn + len, &insn,GET_INSN_LENGTH (insn)); }static void __kprobes arch_prepare_simulate (struct kprobe *p)
Nam already came up with the same fix a few weeks ago: https://lore.kernel.org/linux-riscv/[email protected]/
Thanks anyway!
Alex
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
This patch was applied to riscv/linux.git (fixes) by Palmer Dabbelt <[email protected]>:
Hello:
This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <[email protected]>:
Quoted 10 lines · On Mon, 16 Dec 2024 13:05:44 +0000 you wrote:
The second
patch_text_nosync()inarch_prepare_ss_slotshould be pointing after the first instruction, howeverp->ainsn.api.insnis a pointer to aprobe_opcode_twhich is 4 bytes... this means an instruction of length 2 moves the pointer by 8 bytes.This means a kprobe may fail to work and recurse into the bad instruction handler (which then itself fails as the original lock still seems to be held?)
[...]
Here is the summary with links:
- riscv: kprobes: fix placement in arch_prepare_ss_slot
https://git.kernel.org/riscv/c/13134cc94914
You are awesome, thank you!
Signature · 9 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html _______________________________________________ linux-riscv mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-riscv