Skip to content

Commit eb74232

Browse files
guoren83palmer-dabbelt
authored andcommitted
riscv: kprobe: Fixup misaligned load text
The current kprobe would cause a misaligned load for the probe point. This patch fixup it with two half-word loads instead. Fixes: c22b0bc ("riscv: Add kprobes supported") Signed-off-by: Guo Ren <[email protected]> Signed-off-by: Guo Ren <[email protected]> Link: https://lore.kernel.org/linux-riscv/[email protected]/ Reported-by: Bjorn Topel <[email protected]> Reviewed-by: Björn Töpel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent cb80242 commit eb74232

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

arch/riscv/kernel/probes/kprobes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,18 @@ static bool __kprobes arch_check_kprobe(struct kprobe *p)
6565

6666
int __kprobes arch_prepare_kprobe(struct kprobe *p)
6767
{
68-
unsigned long probe_addr = (unsigned long)p->addr;
68+
u16 *insn = (u16 *)p->addr;
6969

70-
if (probe_addr & 0x1)
70+
if ((unsigned long)insn & 0x1)
7171
return -EILSEQ;
7272

7373
if (!arch_check_kprobe(p))
7474
return -EILSEQ;
7575

7676
/* copy instruction */
77-
p->opcode = *p->addr;
77+
p->opcode = (kprobe_opcode_t)(*insn++);
78+
if (GET_INSN_LENGTH(p->opcode) == 4)
79+
p->opcode |= (kprobe_opcode_t)(*insn) << 16;
7880

7981
/* decode instruction */
8082
switch (riscv_probe_decode_insn(p->addr, &p->ainsn.api)) {

0 commit comments

Comments
 (0)