From patchwork Thu May 27 06:40:29 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: 12283551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EE23C4707F for ; Thu, 27 May 2021 06:40:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 61878613DA for ; Thu, 27 May 2021 06:40:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234608AbhE0GmP (ORCPT ); Thu, 27 May 2021 02:42:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:60512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234473AbhE0GmG (ORCPT ); Thu, 27 May 2021 02:42:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2CBD2613D8; Thu, 27 May 2021 06:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622097633; bh=FkkjM9IdASzlPy5rbPRT2RtG01kVXUCEr1Rvtd2a5iU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kUIzp22oaxs7bdAZkppqknpu4nQorQEHVlVUIT5PVlhTfoQDkD1o75sNzoG9QpvvS KUsdYssxWebYiv3Zi0VuDW80Jq/hCWMR9WUbt65KHGO86xlSEN/PRHjoCnp/Xlo2c2 ph3nsxEyj4iVj5qr9UHp7/hpo+YfeZuJ2vzeB10tUzOzKx8xG/9tk+ZuITN3rv+T0V enIwlgkOSJswJCw2RIFBaHmY7qndRYTBSwF8tPnwjYwUovBgMm2xWLo69uFyONi7Du 33w4Z3iN44r9JyBv4pW0eV+OCLOllRrUorPG7FeRnarLtGUHv/iYlM0q+nV1eKOr9w iyaMp9wKddfuA== From: Masami Hiramatsu To: Steven Rostedt , Ingo Molnar Cc: X86 ML , Masami Hiramatsu , Daniel Xu , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kuba@kernel.org, mingo@redhat.com, ast@kernel.org, tglx@linutronix.de, kernel-team@fb.com, yhs@fb.com, Josh Poimboeuf , linux-ia64@vger.kernel.org, Abhishek Sagar , Andrii Nakryiko Subject: [PATCH -tip v7 09/13] kprobes: Setup instruction pointer in __kretprobe_trampoline_handler Date: Thu, 27 May 2021 15:40:29 +0900 Message-Id: <162209762943.436794.874947392889792501.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <162209754288.436794.3904335049560916855.stgit@devnote2> References: <162209754288.436794.3904335049560916855.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org To simplify the stacktrace with pt_regs from kretprobe handler, set the correct return address to the instruction pointer in the pt_regs before calling kretprobe handlers. Suggested-by: Josh Poimboeuf Signed-off-by: Masami Hiramatsu Tested-by: Andrii Nakryik --- Changes in v3: - Cast the correct_ret_addr to unsigned long. --- kernel/kprobes.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 54e5b89aad67..1598aca375c9 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1914,6 +1914,9 @@ unsigned long __kretprobe_trampoline_handler(struct pt_regs *regs, BUG_ON(1); } + /* Set the instruction pointer to the correct address */ + instruction_pointer_set(regs, (unsigned long)correct_ret_addr); + /* Run them. */ first = current->kretprobe_instances.first; while (first) {