linux-stable/arch
Guo Ren 12316538b1 riscv: kprobe: Fixup kernel panic when probing an illegal position
[ Upstream commit 87f48c7ccc ]

The kernel would panic when probed for an illegal position. eg:

(CONFIG_RISCV_ISA_C=n)

echo 'p:hello kernel_clone+0x16 a0=%a0' >> kprobe_events
echo 1 > events/kprobes/hello/enable
cat trace

Kernel panic - not syncing: stack-protector: Kernel stack
is corrupted in: __do_sys_newfstatat+0xb8/0xb8
CPU: 0 PID: 111 Comm: sh Not tainted
6.2.0-rc1-00027-g2d398fe49a4d #490
Hardware name: riscv-virtio,qemu (DT)
Call Trace:
[<ffffffff80007268>] dump_backtrace+0x38/0x48
[<ffffffff80c5e83c>] show_stack+0x50/0x68
[<ffffffff80c6da28>] dump_stack_lvl+0x60/0x84
[<ffffffff80c6da6c>] dump_stack+0x20/0x30
[<ffffffff80c5ecf4>] panic+0x160/0x374
[<ffffffff80c6db94>] generic_handle_arch_irq+0x0/0xa8
[<ffffffff802deeb0>] sys_newstat+0x0/0x30
[<ffffffff800158c0>] sys_clone+0x20/0x30
[<ffffffff800039e8>] ret_from_syscall+0x0/0x4
---[ end Kernel panic - not syncing: stack-protector:
Kernel stack is corrupted in: __do_sys_newfstatat+0xb8/0xb8 ]---

That is because the kprobe's ebreak instruction broke the kernel's
original code. The user should guarantee the correction of the probe
position, but it couldn't make the kernel panic.

This patch adds arch_check_kprobe in arch_prepare_kprobe to prevent an
illegal position (Such as the middle of an instruction).

Fixes: c22b0bcb1d ("riscv: Add kprobes supported")
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Björn Töpel <bjorn@kernel.org>
Link: https://lore.kernel.org/r/20230201040604.3390509-1-guoren@kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-02-09 11:28:09 +01:00
..
alpha alpha: fix syscall entry in !AUDUT_SYSCALL case 2022-12-31 13:31:55 +01:00
arc ARC: mm: fix leakage of memory allocated for PTE 2022-10-17 16:32:12 -07:00
arm ARM: omap1: fix building gpio15xx 2023-02-06 08:06:32 +01:00
arm64 arm64: dts: imx8mm-verdin: Do not power down eth-phy 2023-02-09 11:28:02 +01:00
csky - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
hexagon - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
ia64 elfcore: Add a cprm parameter to elf_core_extra_{phdrs,data_size} 2023-01-18 11:58:12 +01:00
loongarch LoongArch: Get frame info in unwind_start() when regs is not available 2023-02-06 08:06:32 +01:00
m68k - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
microblaze kbuild: fix "cat: .version: No such file or directory" 2022-11-24 09:26:02 +09:00
mips of/fdt: run soc memory setup when early_init_dt_scan_memory fails 2023-01-12 12:02:51 +01:00
nios2 nios2: add FORCE for vmlinuz.gz 2022-11-27 08:28:41 +09:00
openrisc OpenRISC 6.1 Updates 2022-10-15 16:47:33 -07:00
parisc parisc: Align parisc MADV_XXX constants with all other architectures 2023-01-14 10:33:40 +01:00
powerpc powerpc/imc-pmu: Fix use of mutex in IRQs disabled section 2023-01-18 11:58:21 +01:00
riscv riscv: kprobe: Fixup kernel panic when probing an illegal position 2023-02-09 11:28:09 +01:00
s390 use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
sh - hfs and hfsplus kmap API modernization from Fabio Francesco 2022-10-12 11:00:22 -07:00
sparc mm: add dummy pmd_young() for architectures not having it 2022-11-30 14:49:41 -08:00
um um: virt-pci: Avoid GCC non-NULL warning 2023-01-07 11:11:52 +01:00
x86 use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
xtensa xtensa: add __umulsidi3 helper 2023-01-07 11:11:46 +01:00
.gitignore
Kconfig ftrace: Allow WITH_ARGS flavour of graph tracer with shadow call stack 2022-12-31 13:32:45 +01:00