linux-stable/arch/riscv
Ruan Jinjie 952d1e4cbc riscv: fix kprobe __user string arg print fault issue
[ Upstream commit 99a670b206 ]

On riscv qemu platform, when add kprobe event on do_sys_open() to show
filename string arg, it just print fault as follow:

echo 'p:myprobe do_sys_open dfd=$arg1 filename=+0($arg2):string flags=$arg3
mode=$arg4' > kprobe_events

bash-166     [000] ...1.   360.195367: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename=(fault) flags=0x8241 mode=0x1b6

bash-166     [000] ...1.   360.219369: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename=(fault) flags=0x8241 mode=0x1b6

bash-191     [000] ...1.   360.378827: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename=(fault) flags=0x98800 mode=0x0

As riscv do not select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE,
the +0($arg2) addr is processed as a kernel address though it is a
userspace address, cause the above filename=(fault) print. So select
ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE to avoid the issue, after that the
kprobe trace is ok as below:

bash-166     [000] ...1.    96.767641: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename="/dev/null" flags=0x8241 mode=0x1b6

bash-166     [000] ...1.    96.793751: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename="/dev/null" flags=0x8241 mode=0x1b6

bash-177     [000] ...1.    96.962354: myprobe: (do_sys_open+0x0/0x84)
dfd=0xffffffffffffff9c filename="/sys/kernel/debug/tracing/events/kprobes/"
flags=0x98800 mode=0x0

Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
Acked-by: Björn Töpel <bjorn@rivosinc.com>
Fixes: 0ebeea8ca8 ("bpf: Restrict bpf_probe_read{, str}() only to archs where they work")
Link: https://lore.kernel.org/r/20230504072910.3742842-1-ruanjinjie@huawei.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-06-14 11:13:09 +02:00
..
boot riscv: dts: sifive: fu740: fix size of pcie 32bit memory 2023-01-24 07:22:46 +01:00
configs RISC-V: defconfigs: Set CONFIG_FB=y, for FB console 2022-07-12 16:34:54 +02:00
errata riscv: skip errata_cip_453.o if CONFIG_ERRATA_SIFIVE_CIP_453 is disabled 2021-06-01 21:16:41 -07:00
include riscv: Move early dtb mapping into the fixmap region 2023-05-01 08:23:24 +09:00
kernel riscv: Do not set initial_boot_params to the linear address of the dtb 2023-05-01 08:23:24 +09:00
lib riscv: lib: uaccess: fix CSR_STATUS SR_SUM bit 2022-08-31 17:16:36 +02:00
mm riscv: Fix unused variable warning when BUILTIN_DTB is set 2023-06-09 10:32:15 +02:00
net riscv, bpf: Emit fixed-length instructions for BPF_PSEUDO_FUNC 2022-12-31 13:14:16 +01:00
Kbuild riscv: Allow device trees to be built into the kernel 2020-05-18 11:38:05 -07:00
Kconfig riscv: fix kprobe __user string arg print fault issue 2023-06-14 11:13:09 +02:00
Kconfig.debug
Kconfig.erratas riscv: alternative only works on !XIP_KERNEL 2022-03-16 14:23:42 +01:00
Kconfig.socs riscv: alternative only works on !XIP_KERNEL 2022-03-16 14:23:42 +01:00
Makefile riscv: Handle zicsr/zifencei issues between clang and binutils 2023-03-30 12:47:59 +02:00