linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] riscv: fix kprobe __user string arg print fault issue
@ 2023-05-04  7:29 Ruan Jinjie
  2023-05-15 11:55 ` Ruan Jinjie
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ruan Jinjie @ 2023-05-04  7:29 UTC (permalink / raw)
  To: paul.walmsley, palmer, aou, linux-riscv, linux-kernel; +Cc: ruanjinjie

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>
---
v2:
- add the config in alphabetical order
---
v3:
- change signed-off-by to use full name
---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index d2967fefa1d7..b08ed929e220 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -26,6 +26,7 @@ config RISCV
 	select ARCH_HAS_GIGANTIC_PAGE
 	select ARCH_HAS_KCOV
 	select ARCH_HAS_MMIOWB
+	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
 	select ARCH_HAS_PMEM_API
 	select ARCH_HAS_PTE_SPECIAL
 	select ARCH_HAS_SET_DIRECT_MAP if MMU
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] riscv: fix kprobe __user string arg print fault issue
  2023-05-04  7:29 [PATCH v3] riscv: fix kprobe __user string arg print fault issue Ruan Jinjie
@ 2023-05-15 11:55 ` Ruan Jinjie
  2023-06-02  9:41   ` Björn Töpel
  2023-06-08 18:53 ` Palmer Dabbelt
  2023-06-08 19:00 ` patchwork-bot+linux-riscv
  2 siblings, 1 reply; 5+ messages in thread
From: Ruan Jinjie @ 2023-05-15 11:55 UTC (permalink / raw)
  To: paul.walmsley, palmer, aou, linux-riscv, linux-kernel

Ping.

On 2023/5/4 15:29, Ruan Jinjie wrote:
> 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>
> ---
> v2:
> - add the config in alphabetical order
> ---
> v3:
> - change signed-off-by to use full name
> ---
>  arch/riscv/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index d2967fefa1d7..b08ed929e220 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -26,6 +26,7 @@ config RISCV
>  	select ARCH_HAS_GIGANTIC_PAGE
>  	select ARCH_HAS_KCOV
>  	select ARCH_HAS_MMIOWB
> +	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
>  	select ARCH_HAS_PMEM_API
>  	select ARCH_HAS_PTE_SPECIAL
>  	select ARCH_HAS_SET_DIRECT_MAP if MMU

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] riscv: fix kprobe __user string arg print fault issue
  2023-05-15 11:55 ` Ruan Jinjie
@ 2023-06-02  9:41   ` Björn Töpel
  0 siblings, 0 replies; 5+ messages in thread
From: Björn Töpel @ 2023-06-02  9:41 UTC (permalink / raw)
  To: Ruan Jinjie, paul.walmsley, palmer, aou, linux-riscv,
	linux-kernel, palmer

Ruan Jinjie <ruanjinjie@huawei.com> writes:

> Ping.

Maybe it's not clear *why* we need
ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE on RISC-V?

ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE is used in the kernel to
determine what "memory access" function to use, e.g.

  | #ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
  |         if ((unsigned long)str_val < TASK_SIZE)
  |             ret = strncpy_from_user_nofault(str_field, str_val, STR_VAR_LEN_MAX);
  |         else
  | #endif
  |             ret = strncpy_from_kernel_nofault(str_field, str_val, STR_VAR_LEN_MAX);

RISC-V makes use of the SUM bit [1], which requires the kernel flips a
bit explicitly to touch user memory, so it's important to use the
correct access function.

What this means, is that if
CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE is *not* defined for RV
kernels, the copy_from_kernel will fault (as Jinjie points out in the
commit message).

The fixes tag should be when Daniel Borkmann introduced the config -- or
that makes sense from a backport perspective.

Maybe Palmer can add a lore link to this post, and the following
fixes-tag

  Fixes: 0ebeea8ca8a4 ("bpf: Restrict bpf_probe_read{, str}() only to archs where they work")

when applying?


Björn

[1] https://github.com/riscv/riscv-isa-manual/blob/main/src/supervisor.adoc?plain=1#L118

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] riscv: fix kprobe __user string arg print fault issue
  2023-05-04  7:29 [PATCH v3] riscv: fix kprobe __user string arg print fault issue Ruan Jinjie
  2023-05-15 11:55 ` Ruan Jinjie
@ 2023-06-08 18:53 ` Palmer Dabbelt
  2023-06-08 19:00 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 5+ messages in thread
From: Palmer Dabbelt @ 2023-06-08 18:53 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, aou, linux-riscv, linux-kernel,
	Ruan Jinjie


On Thu, 04 May 2023 15:29:10 +0800, Ruan Jinjie wrote:
> 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
> 
> [...]

Applied, thanks!

[1/1] riscv: fix kprobe __user string arg print fault issue
      https://git.kernel.org/palmer/c/99a670b2069c

Best regards,
-- 
Palmer Dabbelt <palmer@rivosinc.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] riscv: fix kprobe __user string arg print fault issue
  2023-05-04  7:29 [PATCH v3] riscv: fix kprobe __user string arg print fault issue Ruan Jinjie
  2023-05-15 11:55 ` Ruan Jinjie
  2023-06-08 18:53 ` Palmer Dabbelt
@ 2023-06-08 19:00 ` patchwork-bot+linux-riscv
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+linux-riscv @ 2023-06-08 19:00 UTC (permalink / raw)
  To: Ruan Jinjie; +Cc: linux-riscv, paul.walmsley, palmer, aou, linux-kernel

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Thu, 4 May 2023 15:29:10 +0800 you wrote:
> 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
> 
> [...]

Here is the summary with links:
  - [v3] riscv: fix kprobe __user string arg print fault issue
    https://git.kernel.org/riscv/c/99a670b2069c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-08 19:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-04  7:29 [PATCH v3] riscv: fix kprobe __user string arg print fault issue Ruan Jinjie
2023-05-15 11:55 ` Ruan Jinjie
2023-06-02  9:41   ` Björn Töpel
2023-06-08 18:53 ` Palmer Dabbelt
2023-06-08 19:00 ` patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).