From patchwork Fri Oct 8 12:28:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 12545249 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 36439C433F5 for ; Fri, 8 Oct 2021 12:36:10 +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 E592C60F6B for ; Fri, 8 Oct 2021 12:36:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E592C60F6B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fqzI35Jv/iTP6dOPL3yh+j3mj1nnRco6HNG+zWqC2g8=; b=SQ+jyjrZiA1/ae 16Wb8ECKcviPFOqcxrSEZJzIXPAvxGKP5w18VtNe7CHPoPzVAsi6AXhbQFlQ2w08B3L1exjCqyyKN lh8MQVdSdIUjW+JhQyacLj8DZCLRyJm/9LVY7cZkzFeEVh6dutMm1tUx/g0qGeuYT0do4/0jTr2RJ kDXBHwicA8uv/JyTYImggfnQIXLp8yiDdBlGIs+TITgVjjlwGCC5khJlj2jqoGqagsreEJkwNjoET TIgUH2GTjWV2Omug5A58n9OPFWeQRFsrR/d/bZrEOtO8C419ZRC5j2xcYLWrevhjKzaPLhhqiG76h Fkh0N7hMSevZtmgUZjWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYp4s-002jxQ-Vy; Fri, 08 Oct 2021 12:34:20 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYozn-002i9R-AW for linux-arm-kernel@lists.infradead.org; Fri, 08 Oct 2021 12:29:04 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1013860F48; Fri, 8 Oct 2021 12:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633696143; bh=/fT89EnJsGeXhhESlz3WvMkeVLw4KkN/f3I7P9dDp9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sQ0r4b3lc0WUZghApOlyszzr1mHp8U+/0PurlKy1yL3QsbY6qY3jJRtxGpXKn0+Hf fx+Lpb9sX7qbZYiczfUldC6a/MSjtPahlpt3/bcjYAOUF/PZyxy8A/ELtS1yUwinwl bvA1x1pfD6ziohrg71hXn11V6ACK3lE5dLM5cKIlB3eFvNfOZlY5kvCDUdwLsIOhfl bbHDi9lbkBljlwqjkrPhYPQuywFkBY33xZ+ovZJqHexIF2FJ3jb7yoGLjsUDGenvzf l3iChYypnr6osJxYpCosymh+u38WfU6EIP7VKq3Xr2rOEWnoPL8AyYgYqRPpexnQbV I3Ka9JJWs3Yzw== From: Masami Hiramatsu To: Steven Rostedt Cc: "Naveen N . Rao" , Ananth N Mavinakayanahalli , Ingo Molnar , linux-kernel@vger.kernel.org, mhiramat@kernel.org, Sven Schnelle , Catalin Marinas , Will Deacon , Russell King , Nathan Chancellor , Nick Desaulniers , linux-arm-kernel@lists.infradead.org Subject: [PATCH 5/8] arm64: Recover kretprobe modified return address in stacktrace Date: Fri, 8 Oct 2021 21:28:58 +0900 Message-Id: <163369613866.636038.15240679956943005288.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163369609308.636038.15295764725220907794.stgit@devnote2> References: <163369609308.636038.15295764725220907794.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211008_052903_429615_BE3C92A7 X-CRM114-Status: GOOD ( 14.54 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; }; 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); 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)); if (regs) start_backtrace(&frame, regs->regs[29], regs->pc); else if (task == current)