From patchwork Wed Jan 11 11:38:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 13096476 X-Patchwork-Delegate: mhiramat@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14EB8C46467 for ; Wed, 11 Jan 2023 11:40:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238327AbjAKLkE (ORCPT ); Wed, 11 Jan 2023 06:40:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238514AbjAKLji (ORCPT ); Wed, 11 Jan 2023 06:39:38 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E019192A1; Wed, 11 Jan 2023 03:38:05 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Cx+emcn75jSfAAAA--.2916S3; Wed, 11 Jan 2023 19:38:04 +0800 (CST) Received: from [10.130.0.135] (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxPuSbn75jOegXAA--.7699S3; Wed, 11 Jan 2023 19:38:03 +0800 (CST) To: Masami Hiramatsu , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" Cc: linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org From: Tiezhu Yang Subject: kernel hangs when kprobe memcpy Message-ID: Date: Wed, 11 Jan 2023 19:38:03 +0800 User-Agent: Mozilla/5.0 (X11; Linux mips64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-CM-TRANSID: AQA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jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r 1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUv cSsGvfC2KfnxnUUI43ZEXa7IU8hiSPUUUUU== Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org Hi all, (1) I have the following test environment, kernel hangs when kprobe memcpy: system: x86_64 fedora 36 kernel version: Linux 5.7 (compile and update) test case: modprobe kprobe_example symbol="memcpy" (CONFIG_SAMPLE_KPROBES=m) In order to fix build errors, it needs to unset CONFIG_NFP and do the following changes: commit 52a9dab6d892 ("libsubcmd: Fix use-after-free for realloc(..., 0)") commit de979c83574a ("x86/entry: Build thunk_$(BITS) only if CONFIG_PREEMPTION=y") (2) Using the latest upstream mainline kernel, no hang problem due to the commit e3a9e681adb7 ("x86/entry: Fixup bad_iret vs noinstr") to prohibit probing memcpy which is put into the .noinstr.text section. # modprobe kprobe_example symbol="memcpy" modprobe: ERROR: could not insert 'kprobe_example': Invalid argument In my opinion, according to the commit message, the above commit is not intended to fix the memcpy hang problem, the problem was fixed by accident. (3) If make handler_pre() and handler_post() as empty functions in the 5.7 kernel code, the above hang problem does not exist. pr_info("<%s> p->addr = 0x%p, msr = 0x%lx\n", I want to know what is the real reason of the hang problem when kprobe memcpy, I guess it may be kprobe recursion, what do you think? Thank you. By the way, kprobe memset has no problem whether or not handler_pre() and handler_post() are empty functions. Thanks, Tiezhu Signed-off-by: Masami Hiramatsu (Google) diff --git a/samples/kprobes/kprobe_example.c b/samples/kprobes/kprobe_example.c index fd346f58ddba..c194171d8a46 100644 --- a/samples/kprobes/kprobe_example.c +++ b/samples/kprobes/kprobe_example.c @@ -28,8 +28,6 @@ static struct kprobe kp = { static int __kprobes handler_pre(struct kprobe *p, struct pt_regs *regs) { #ifdef CONFIG_X86 - pr_info("<%s> p->addr = 0x%p, ip = %lx, flags = 0x%lx\n", - p->symbol_name, p->addr, regs->ip, regs->flags); #endif #ifdef CONFIG_PPC pr_info("<%s> p->addr = 0x%p, nip = 0x%lx, msr = 0x%lx\n", @@ -65,8 +63,6 @@ static void __kprobes handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long flags) { #ifdef CONFIG_X86 - pr_info("<%s> p->addr = 0x%p, flags = 0x%lx\n", - p->symbol_name, p->addr, regs->flags); #endif #ifdef CONFIG_PPC