From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4C25C433EF for ; Wed, 13 Oct 2021 11:29:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6922260D07 for ; Wed, 13 Oct 2021 11:29:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6922260D07 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BmhnaQ1gEB9wE6xTFkuQu5ugF3ezC5QZ9R3nkshJlNg=; b=azPwuxs89MhhkZ kU5YftI7kRTS/QnP8rz3uTlEKNqEv3sUNFhawEL44moppugU+HtJEjtHt/1kQkWex9fRBhlS51S/8 3oa/D3PjooyaKpoD0eOIvSU3z5VJBmhnOo2vZ2WpVDN92WVQuhLLrQlbD5jzQa7TdTGtkXO+durab V1oX46pfV00l7k/kOswY2a6reDUNUKsk8m+ZnHVEBFPhZ1cClI6K5v6It5pr/pa1CBo/Ui90oLtpc 1weA/6kzMJsTxttia7k80HA5hbinDA2NxpXYRBuZoJsXHs8lOHbMaV7l2sGfUhlyqIcRk2y5ud0BP Ax/6JH8IYvF8funGo9xg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1macQ6-00GJ1L-Gc; Wed, 13 Oct 2021 11:27:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mabGr-00Fvtd-2e for linux-arm-kernel@lists.infradead.org; Wed, 13 Oct 2021 10:14:02 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 41B1913D5; Wed, 13 Oct 2021 03:13:57 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.73.189]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3F2FC3F70D; Wed, 13 Oct 2021 03:13:54 -0700 (PDT) Date: Wed, 13 Oct 2021 11:13:51 +0100 From: Mark Rutland To: Masami Hiramatsu Cc: Steven Rostedt , "Naveen N . Rao" , Ananth N Mavinakayanahalli , Ingo Molnar , linux-kernel@vger.kernel.org, Sven Schnelle , Catalin Marinas , Will Deacon , Russell King , Nathan Chancellor , Nick Desaulniers , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 5/8] arm64: Recover kretprobe modified return address in stacktrace Message-ID: <20211013101351.GB3187@C02TD0UTHF1T.local> References: <163369609308.636038.15295764725220907794.stgit@devnote2> <163369613866.636038.15240679956943005288.stgit@devnote2> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <163369613866.636038.15240679956943005288.stgit@devnote2> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211013_031401_255552_22B47669 X-CRM114-Status: GOOD ( 25.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Oct 08, 2021 at 09:28:58PM +0900, Masami Hiramatsu wrote: > Since the kretprobe replaces the function return address with > the kretprobe_trampoline on the stack, stack unwinder shows it > instead of the correct return address. > > This checks whether the next return address is the > __kretprobe_trampoline(), and if so, try to find the correct > return address from the kretprobe instance list. > > With this fix, now arm64 can enable > CONFIG_ARCH_CORRECT_STACKTRACE_ON_KRETPROBE, and pass the > kprobe self tests. > > Signed-off-by: Masami Hiramatsu > --- > arch/arm64/Kconfig | 1 + > arch/arm64/include/asm/stacktrace.h | 2 ++ > arch/arm64/kernel/stacktrace.c | 3 +++ > 3 files changed, 6 insertions(+) > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index 5c7ae4c3954b..edde5171ffb2 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -11,6 +11,7 @@ config ARM64 > select ACPI_PPTT if ACPI > select ARCH_HAS_DEBUG_WX > select ARCH_BINFMT_ELF_STATE > + select ARCH_CORRECT_STACKTRACE_ON_KRETPROBE > select ARCH_ENABLE_HUGEPAGE_MIGRATION if HUGETLB_PAGE && MIGRATION > select ARCH_ENABLE_MEMORY_HOTPLUG > select ARCH_ENABLE_MEMORY_HOTREMOVE > diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h > index 8aebc00c1718..8f997a602651 100644 > --- a/arch/arm64/include/asm/stacktrace.h > +++ b/arch/arm64/include/asm/stacktrace.h > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -59,6 +60,7 @@ struct stackframe { > #ifdef CONFIG_FUNCTION_GRAPH_TRACER > int graph; > #endif > + struct llist_node *kr_cur; As with the fgraph bits above, please make this depedn on the relevant Kconfig, i.e. | #ifdef CONFIG_KRETPROBES | struct llist_node *kr_cur; | #endif > }; > > extern int unwind_frame(struct task_struct *tsk, struct stackframe *frame); > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index 8982a2b78acf..f1eef5745542 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -129,6 +129,8 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) > frame->pc = ret_stack->ret; > } > #endif /* CONFIG_FUNCTION_GRAPH_TRACER */ > + if (is_kretprobe_trampoline(frame->pc)) > + frame->pc = kretprobe_find_ret_addr(tsk, (void *)frame->fp, &frame->kr_cur); Please ifdef this, like the CONFIG_FUNCTION_GRAPH_TRACER bits above. i.e. | #ifdef CONFIG_KRETPROBES | if (is_kretprobe_trampoline(frame->pc)) | frame->pc = kretprobe_find_ret_addr(tsk, (void *)frame->fp, &frame->kr_cur); | #endif What does kretprobe_find_ret_addr() do when it can't find the original address? I couldn't spot it in this series or in mainline. As a future thing, I'd like to be able to have monotonicity and completeness checks as part of the unwind, i.e. checking that we consume the kretprobe address *in-order*, and can identify whether we've skipped any, so that we can identify when unwinding has gone wrong. Does it do that today? It'd be nice if it could signal failure reliably (without causing a BUG() or similar), e.g. by returning an error code. > frame->pc = ptrauth_strip_insn_pac(frame->pc); > > @@ -224,6 +226,7 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, > { > struct stackframe frame; > > + memset(&frame, 0, sizeof(frame)); Please initialise stackframe::kr_cur in start_backtrace, where we initialize all the other fields in struct stackframe, i.e. just after the CONFIG_FUNCTION_GRAPH_TRACER bit, have: | #ifdef CONFIG_KRETPROBES | frame->kr_cur = NULL; | #endif Thanks, Mark. > if (regs) > start_backtrace(&frame, regs->regs[29], regs->pc); > else if (task == current) > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel