[PW_SID:1155302] riscv: kprobes: Reject reserved branch encodings - #2564
[PW_SID:1155302] riscv: kprobes: Reject reserved branch encodings#2564linux-riscv-bot wants to merge 3 commits into
Conversation
The available-counter mask was a single unsigned long, but iteration uses RISCV_MAX_COUNTERS, which is 64. On RV32 that reads past the object. Filling with an unsigned-long bit at index 32 and above is also wrong. Use DECLARE_BITMAP and set_bit/bitmap helpers. Walk each bitmap word into CFG_MATCH when checking events, when allocating an index, and when stopping all counters. Set the counter base to i times BITS_PER_LONG. Share the CFG_MATCH ecall through a small helper so the 32-bit argument split is not duplicated. On qemu-system-riscv32 the probe bitmap has bits above XLEN set, so the first word alone is not enough. Fixes: e999143 ("RISC-V: Add perf platform driver based on SBI PMU extension") Assisted-by: DeepSeek:deepseek-v3 Signed-off-by: Xixin Liu <liuxixin@kylinos.cn> Link: https://patch.msgid.link/prpmask02cmap.v2.1786434000.git.liuxixin@kylinos.cn [pjw@kernel.org: updated to apply] Signed-off-by: Paul Walmsley <pjw@kernel.org>
simulate_branch() cannot emulate the reserved branch encodings (funct3 010/011) and returns false for them, but arch_simulate_insn() ignores the return value. A probe on such an encoding, e.g. placed on data misdecoded as instructions, therefore keeps the instruction pointer on the breakpoint, and the CPU traps on it forever. Reject these encodings in riscv_probe_decode_insn(), like the other instruction classes already rejected there, so registration fails with -EINVAL instead. All simulator failure paths then become unreachable: register indices are bounded by construction, and the c.jr/c.jalr reserved encodings are already filtered by the decode predicates. Fixes: c22b0bc ("riscv: Add kprobes supported") Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn> Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
1252e7d to
cf66746
Compare
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
|
Patch 1: "riscv: kprobes: Reject reserved branch encodings" |
PR for series 1155302 applied to workflow__riscv__fixes
Name: riscv: kprobes: Reject reserved branch encodings
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1155302
Version: 1