From patchwork Wed May 26 08:03:41 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: 12280835 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 501FEC2B9F7 for ; Wed, 26 May 2021 08:03:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 298AB613D3 for ; Wed, 26 May 2021 08:03:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233236AbhEZIFS (ORCPT ); Wed, 26 May 2021 04:05:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:40472 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233182AbhEZIFS (ORCPT ); Wed, 26 May 2021 04:05:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 45E3F613B4; Wed, 26 May 2021 08:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622016227; bh=IjupCuH7LUBDawzWyZY7m3hIBhvkMzv28EFK3pFOSwg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cQr8s3XJkWkywOHXFJrqwkPjpIR3KYXk8arUIvGshrkE6iUkMaRoIvgUDVx95Y6L2 PNpvrhp4vYdRN81oPdGdqoYbC0iHXhO4lxy9UE87xWyjsrs1SC75Pa6VSDYmmunMDT jMstLLc/QoU9ahAoxfJXfF8Ju+Co2Au1b24eDErK0/vmgSUnnGN1evH6xeqqTJfmf+ msuYyhXyq3Ftj7SlI9QlF5s3feDYhnZxfiyWoWFY5/GUHTf0sKkBgRPoIhERfmF6ry pRKB7x2l50mD3QV7si/3VMvq3Bfw/kWdgXY3kNmSkmiwjt6js2os9OorJjTgo4t5FU FmUhV9O5mdO7A== 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 v6 09/13] kprobes: Setup instruction pointer in __kretprobe_trampoline_handler Date: Wed, 26 May 2021 17:03:41 +0900 Message-Id: <162201622111.278331.11505326612383898085.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <162201612941.278331.5293566981784464165.stgit@devnote2> References: <162201612941.278331.5293566981784464165.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 --- 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) {