linux/arch/riscv/kernel/probes
Björn Töpel b2d473a601
riscv, kprobes: Stricter c.jr/c.jalr decoding
In the compressed instruction extension, c.jr, c.jalr, c.mv, and c.add
is encoded the following way (each instruction is 16b):

---+-+-----------+-----------+--
100 0 rs1[4:0]!=0       00000 10 : c.jr
100 1 rs1[4:0]!=0       00000 10 : c.jalr
100 0  rd[4:0]!=0 rs2[4:0]!=0 10 : c.mv
100 1  rd[4:0]!=0 rs2[4:0]!=0 10 : c.add

The following logic is used to decode c.jr and c.jalr:

  insn & 0xf007 == 0x8002 => instruction is an c.jr
  insn & 0xf007 == 0x9002 => instruction is an c.jalr

When 0xf007 is used to mask the instruction, c.mv can be incorrectly
decoded as c.jr, and c.add as c.jalr.

Correct the decoding by changing the mask from 0xf007 to 0xf07f.

Fixes: c22b0bcb1d ("riscv: Add kprobes supported")
Signed-off-by: Björn Töpel <bjorn@rivosinc.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: Guo Ren <guoren@kernel.org>
Link: https://lore.kernel.org/r/20230102160748.1307289-1-bjorn@kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-01-05 12:30:41 -08:00
..
Makefile riscv: add riscv rethook implementation 2022-12-02 13:04:05 -08:00
decode-insn.c riscv: kprobes: implement the branch instructions 2021-07-21 23:22:34 -07:00
decode-insn.h
ftrace.c ftrace: disable preemption when recursion locked 2021-10-27 11:21:49 -04:00
kprobes.c riscv: add riscv rethook implementation 2022-12-02 13:04:05 -08:00
rethook.c riscv: add riscv rethook implementation 2022-12-02 13:04:05 -08:00
rethook.h riscv: add riscv rethook implementation 2022-12-02 13:04:05 -08:00
rethook_trampoline.S riscv: add riscv rethook implementation 2022-12-02 13:04:05 -08:00
simulate-insn.c riscv: kprobes: implement the branch instructions 2021-07-21 23:22:34 -07:00
simulate-insn.h riscv, kprobes: Stricter c.jr/c.jalr decoding 2023-01-05 12:30:41 -08:00
uprobes.c riscv:uprobe fix SR_SPIE set/clear handling 2022-08-11 14:14:52 -07:00