From patchwork Thu Mar 30 19:11:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cabaj X-Patchwork-Id: 1763409 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=h+4FLtyj; 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 4PnY1N02cyz1yZ1 for ; Fri, 31 Mar 2023 06:11:18 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1phxfz-0002x8-33; Thu, 30 Mar 2023 19:11:11 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1phxfu-0002vv-R4 for kernel-team@lists.ubuntu.com; Thu, 30 Mar 2023 19:11:06 +0000 Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) (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-0.canonical.com (Postfix) with ESMTPS id 7D1BE3F200 for ; Thu, 30 Mar 2023 19:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1680203466; bh=7oxJ9zRitBasXwG5x3gENoi+vBNUVa1g2MjNzm3G9w8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=h+4FLtyjZrsnCpHtofhOBuYG0X1OpAKFcFlyo4y29ZwGRbuo1mhCzL56DCnQaksi0 wmx7IQFQPLgK91wLaYxEHfAIsBgeVlifHPGLLdIgwPKuO5Ruwov8Qwm+LWAkMIDxBU 12MX8Z6i1Z20lVtMdQKMJyKsuLXm9qkpwgUdL78ChRB70Wdp/EjQGdbIH28h+jtqYl 9QI6IL89GhXWhEwVCLlCdMAm0WqUDg5s654u4rRfDXrmxnKz5A0EmdCQ79Bm4DMsre iTMhdJxoTeLGEYC95wQKdLcBIQwH3vmNjcune8LOj/xJIMe9tDMIqsGt11tqv1HVnm qcN8EcW6OcJwA== Received: by mail-yb1-f197.google.com with SMTP id k199-20020a2524d0000000b00b7f3a027e50so4886957ybk.4 for ; Thu, 30 Mar 2023 12:11:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680203465; 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=7oxJ9zRitBasXwG5x3gENoi+vBNUVa1g2MjNzm3G9w8=; b=IA0wgUlLbS6/dKVNfgwE6o3K3cohTZ4bUJPwkvFYWZ/dJl8EDWpwJptzh714HqHvlN ++cgsV1fc9P4IaVGv01ccV4up9oyDQ33I5dGEUSnYIqKIfpc2Ez4xsvucesunybis3qA L+KUCzP8TmsMSSUa5Va+fjAG7Pfzo51snyM9BepB+WJPuIVwIH9XA8NT+8SI8meFdats HPNrQgd22CDgw1Kt0JLWdsNBCloO0ZbRRYBIbwkQBbwYKE4zHyz9r07ax1SfwJmbqWIR K6Pkf39QXdJWT9S11iqsAg4KY1qBjLA+d7rPD2wdi7ptQV8uMjNnFglwPGVGcmSa5uaG HPnA== X-Gm-Message-State: AAQBX9exTKvpLY0XUZORM1bWL9KAyQrqQd9r+yRg8Pt29XCHnqdmjUd4 54yrIDzPqyMttfdmchpx6UfsoRBBV9X3Wz7UbU5z0HN1af17hox4z9t4ByJU3KL8+h260HCymGz nG1CGZuUaZCn+CE1aqiJPx7yBpi+URjQ8LBkhZ0O0dl6d/8QR5w== X-Received: by 2002:a0d:e253:0:b0:541:891f:86f6 with SMTP id l80-20020a0de253000000b00541891f86f6mr22902525ywe.19.1680203465279; Thu, 30 Mar 2023 12:11:05 -0700 (PDT) X-Google-Smtp-Source: AKy350YdKfeKTKzOR1Sv8yH0SuGYK5WoJ2bMX+j/O9nU2RChM4wntz2KJ6/f9aLAtHfPH3nxPDK1jQ== X-Received: by 2002:a0d:e253:0:b0:541:891f:86f6 with SMTP id l80-20020a0de253000000b00541891f86f6mr22902509ywe.19.1680203464984; Thu, 30 Mar 2023 12:11:04 -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 k10-20020a81ff0a000000b00545a0818473sm42251ywn.3.2023.03.30.12.11.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 12:11:04 -0700 (PDT) From: John Cabaj To: kernel-team@lists.ubuntu.com Subject: [SRU][jammy][PATCH 4/5] s390/unwind: recover kretprobe modified return address in stacktrace Date: Thu, 30 Mar 2023 14:11:00 -0500 Message-Id: <20230330191101.2034512-5-john.cabaj@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230330191101.2034512-1-john.cabaj@canonical.com> References: <20230330191101.2034512-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/1639924 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;