Message ID | 20230504072910.3742842-1-ruanjinjie@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp120696vqo; Thu, 4 May 2023 00:35:38 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5VqruVMVYK6R/vmBwdDQeRTDyt+G/nFifQk27P+/4RJsElK8rBETTcXnK6XZGG2sg99zRy X-Received: by 2002:a05:6a20:12c2:b0:ee:3ddf:9737 with SMTP id v2-20020a056a2012c200b000ee3ddf9737mr1199376pzg.28.1683185738182; Thu, 04 May 2023 00:35:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683185738; cv=none; d=google.com; s=arc-20160816; b=h39z2qeSJuFtuxcheQxhWC12spYQ0MDqpr+xvREM5xeDUHNfDdho/LXQ/gFoluIot/ MzmHZVbCLJvuBaN5Us0seTVuIALg4HyMKWFhvUaxCHcAEW8luVboIS0y7kyU9U4I9eAh rdLxrgOqFcWmHeLHATyzfiltRw56dc2aRrcSD6sJoreTktLF0XWL6PxBleSes9Ztlqx+ mp7lsrbW4cIvtPqlhFW1y0XUl7R05RMKP5ioLmhwn0BFcQbtPy4c1tMEL7rT9zwuM4ce Xx2kG7fdyiXxwLd9RpzOSg64TLjTZFcYSv0VmKNv20pq8z7zXs+NzpFkqB5FPgIFeLq4 dTiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=zlW3C29JcVZ29sZjhJqtHH6KVt9+JSQcXHs6qVqDB2I=; b=cj2HPMwlgIDlTkeWoveQF5PgVgmzlD4erIS93hPgOeR3PnTnRtd9i6nbU9mCdRAoI6 OuETMqD1CFwg3pBpEPTsNEtH/F85dcGrvtb8RNbTNvXq8omMk7qPZQGYhWaz/UvQ9vjp UvIEuttzcm4IdMc5nuVwFhrM8lrzz3V/SPXXL120cCqP1hJeCbJe0TZnnMhRFBJcXSFO cbhoRYzAPASoDCq9Uy+9WZyVcFtnP97cYkJM5tqvpMkp2d/JFO9AgZLMzZLhUkJbVaaa 4CBo+VIbpBzP4KjJIpc5p7NMSQKLmW4qsC7jjuwN8eIrrij64D/3pRJlLBycXi7UYdBk +uNA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s6-20020a656446000000b0050309caf60esi3857052pgv.750.2023.05.04.00.35.26; Thu, 04 May 2023 00:35:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbjEDHaq (ORCPT <rfc822;lhua1029@gmail.com> + 99 others); Thu, 4 May 2023 03:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbjEDHao (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 4 May 2023 03:30:44 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01C071990 for <linux-kernel@vger.kernel.org>; Thu, 4 May 2023 00:30:42 -0700 (PDT) Received: from kwepemi500008.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QBllY1VzkzLnd1; Thu, 4 May 2023 15:27:53 +0800 (CST) Received: from huawei.com (10.67.175.83) by kwepemi500008.china.huawei.com (7.221.188.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 4 May 2023 15:30:40 +0800 From: Ruan Jinjie <ruanjinjie@huawei.com> To: <paul.walmsley@sifive.com>, <palmer@dabbelt.com>, <aou@eecs.berkeley.edu>, <linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org> CC: <ruanjinjie@huawei.com> Subject: [PATCH v3] riscv: fix kprobe __user string arg print fault issue Date: Thu, 4 May 2023 15:29:10 +0800 Message-ID: <20230504072910.3742842-1-ruanjinjie@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.175.83] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500008.china.huawei.com (7.221.188.139) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764948168613680337?= X-GMAIL-MSGID: =?utf-8?q?1764948168613680337?= |
Series |
[v3] riscv: fix kprobe __user string arg print fault issue
|
|
Commit Message
Jinjie Ruan
May 4, 2023, 7:29 a.m. UTC
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(+)
Comments
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
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
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,
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!
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