From patchwork Thu Apr 6 15:12:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cabaj X-Patchwork-Id: 1766196 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=sw/8wcAX; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PslP45w3Zz1yZq for ; Fri, 7 Apr 2023 01:12:56 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pkRI9-0008H7-Nq; Thu, 06 Apr 2023 15:12:49 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pkRHz-0008AA-Nb for kernel-team@lists.ubuntu.com; Thu, 06 Apr 2023 15:12:39 +0000 Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 85C843F04B for ; Thu, 6 Apr 2023 15:12:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1680793959; bh=Ooe+yztgcUcbzq+ufhZOyvsrxT7GUqpqnkNyDAQ3rPE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sw/8wcAXatfHByun+3QHUFZ07UJAwxeuDApnldLhBfTipOI5wzUJQsMYgiJnH7vCt lNYOyhBOV71RB62KTifi89w6LNRdtaGj19K99ct6KOVSiesv6RxF4L1WxF41xbVrXr 5dxseKJmpuWG3BhNdK26+R60JZ31ENJERy5B8nzWekkS37BBjBmrYHsp9sef4zRKBD XAl6NaNh55mBcc47zZwIJ6KFf/jhCVq9rMt84mF/03ATQghJtFseyCIJGrzlEoV+YJ PCMCBfnrU9X4nKpVkAnSJanfWIsltfNepqlq0VtpYiP7D9eCh/ZCNysCHqKxT+6Ay0 2kP8g7R+sCknQ== Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-54c0b8ca2d1so26734627b3.17 for ; Thu, 06 Apr 2023 08:12:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680793958; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ooe+yztgcUcbzq+ufhZOyvsrxT7GUqpqnkNyDAQ3rPE=; b=IJpiwpe4i3NXrmzvw5EfNM2L7hotE74cdxzLP8v6QVTxAzTsSTUTGWu+kahLAYpGWd iQJAj2x1CGy3VEXTfMxrY6rR3LxJ7yjZiPpV62is6Hy6WK3Wo+QGZpB+ggKBumWbbTl0 yRgM/UIfCNTVa5MEbw6O9ZnnLjxhs7USRndeuKz5Otzpl/a1lpWiBhf+fTY9SiNbEChq lyouBlMIJCplmFsjNWjeimH84Y+ZU++EhUPTsYiyH5xg4QDj0WBrZJLhvykP+wiJ8n7/ rc4kCMVR4oXVm6+XfWLZsL+ye6XKjMbSa4f+HZ9WPhGVq1GdLw96tYzZ2WEwZEAhcMaB DIig== X-Gm-Message-State: AAQBX9ff0N/DGgd+Op459K7WbzSGVLMlZR8bsk+GsAMZveD8AoCodvwP CvDmf7qGKBv52txMpJBV+gV/GM/B+40OS6Bp3DfMT3C+IbD30Jf5WxM+pctCc3tvPjgz7wyC8kb N2oMuUgpwLhl+oIGlCzsy5cu2+DxcJK7IPIGePDwzKmUxbVDc5g== X-Received: by 2002:a81:8a41:0:b0:546:3f6b:b94c with SMTP id a62-20020a818a41000000b005463f6bb94cmr9790025ywg.7.1680793958341; Thu, 06 Apr 2023 08:12:38 -0700 (PDT) X-Google-Smtp-Source: AKy350bZxB6pTFQmwTdkEDJZSS0HsNk8H8Pn2xMIrdFK2qL8A1eNJRCg8v6I2R4XilfNM2i3fEqlyg== X-Received: by 2002:a81:8a41:0:b0:546:3f6b:b94c with SMTP id a62-20020a818a41000000b005463f6bb94cmr9790013ywg.7.1680793958073; Thu, 06 Apr 2023 08:12:38 -0700 (PDT) Received: from smtp.gmail.com (h69-130-246-116.mdtnwi.broadband.dynamic.tds.net. [69.130.246.116]) by smtp.gmail.com with ESMTPSA id 80-20020a811453000000b00545a0818480sm373564ywu.16.2023.04.06.08.12.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Apr 2023 08:12:37 -0700 (PDT) From: John Cabaj To: kernel-team@lists.ubuntu.com Subject: [SRU][jammy][PATCH v3 4/5] s390/unwind: recover kretprobe modified return address in stacktrace Date: Thu, 6 Apr 2023 10:12:32 -0500 Message-Id: <20230406151233.405626-5-john.cabaj@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230406151233.405626-1-john.cabaj@canonical.com> References: <20230406151233.405626-1-john.cabaj@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Vasily Gorbik BugLink: https://bugs.launchpad.net/bugs/2013603 (Kernel livepatch ftrace graph fix) Based on commit cd9bc2c92588 ("arm64: Recover kretprobe modified return address in stacktrace"). """ 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. """ Original patch series: https://lore.kernel.org/all/163163030719.489837.2236069935502195491.stgit@devnote2/ Reviewed-by: Tobias Huschle Signed-off-by: Vasily Gorbik (cherry picked from commit d81675b60d0959cfa3727f03d5b90558fb457011) Signed-off-by: John Cabaj --- arch/s390/include/asm/unwind.h | 13 +++++++++++++ arch/s390/kernel/unwind_bc.c | 8 ++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/s390/include/asm/unwind.h b/arch/s390/include/asm/unwind.h index 5ebf534ef753..0bf06f1682d8 100644 --- a/arch/s390/include/asm/unwind.h +++ b/arch/s390/include/asm/unwind.h @@ -4,6 +4,8 @@ #include #include +#include +#include #include #include @@ -36,10 +38,21 @@ struct unwind_state { struct pt_regs *regs; unsigned long sp, ip; int graph_idx; + struct llist_node *kr_cur; bool reliable; bool error; }; +/* Recover the return address modified by kretprobe and ftrace_graph. */ +static inline unsigned long unwind_recover_ret_addr(struct unwind_state *state, + unsigned long ip) +{ + ip = ftrace_graph_ret_addr(state->task, &state->graph_idx, ip, NULL); + if (is_kretprobe_trampoline(ip)) + ip = kretprobe_find_ret_addr(state->task, (void *)state->sp, &state->kr_cur); + return ip; +} + void __unwind_start(struct unwind_state *state, struct task_struct *task, struct pt_regs *regs, unsigned long first_frame); bool unwind_next_frame(struct unwind_state *state); diff --git a/arch/s390/kernel/unwind_bc.c b/arch/s390/kernel/unwind_bc.c index 707fd99f6734..984970389bab 100644 --- a/arch/s390/kernel/unwind_bc.c +++ b/arch/s390/kernel/unwind_bc.c @@ -103,13 +103,11 @@ bool unwind_next_frame(struct unwind_state *state) if (sp & 0x7) goto out_err; - ip = ftrace_graph_ret_addr(state->task, &state->graph_idx, ip, (void *) sp); - /* Update unwind state */ state->sp = sp; - state->ip = ip; state->regs = regs; state->reliable = reliable; + state->ip = unwind_recover_ret_addr(state, ip); return true; out_err: @@ -161,12 +159,10 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task, ip = READ_ONCE_NOCHECK(sf->gprs[8]); } - ip = ftrace_graph_ret_addr(state->task, &state->graph_idx, ip, NULL); - /* Update unwind state */ state->sp = sp; - state->ip = ip; state->reliable = true; + state->ip = unwind_recover_ret_addr(state, ip); if (!first_frame) return;