From patchwork Fri Mar 31 14:00:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cabaj X-Patchwork-Id: 1763792 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=KsCskTTz; 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 4Pp24v31LJz1yZ6 for ; Sat, 1 Apr 2023 01:01:03 +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 1piFJI-0002d3-ES; Fri, 31 Mar 2023 14:00:56 +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 1piFJA-0002Wi-FF for kernel-team@lists.ubuntu.com; Fri, 31 Mar 2023 14:00:48 +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 656673F231 for ; Fri, 31 Mar 2023 14:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1680271247; bh=Ooe+yztgcUcbzq+ufhZOyvsrxT7GUqpqnkNyDAQ3rPE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KsCskTTziZYSTUfIMayaxqleajujA9bHVzoB8fE6YJ9mm49+0FjQJahbUuQsGIvUn 82YK+g+lDMYcOZnHXKzkgj53vCX5aMxwBmBg/xLu8HNscAvwDgARg8i4IP51YmzIhu dW36ffi5NzrN+WrvM6HFQGRf+e2K9bXFkbHf6r1tBGiQJMPdcc7x2YI7RHckqe0sX8 /0HzINNQ978aotd2XaCIk3MI7RAcOw8/nEBuQ5LreXHTv5gaqP5i7Y71wF9u/yNoQX pfaKE/hDU7dod6vmteA8ApGmfhmF08RXujXxFyR+FbrKUmrTv+4dMATOEkSF5YTILu Vct/pKOFbOtWw== Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-545dd1a1e31so168801107b3.22 for ; Fri, 31 Mar 2023 07:00:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680271246; 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=kqA95jdf6oC1OJx7ycNBNnniMTuhHSL7xDtlAUz8BPIKIZ0+a/BaszSg6OVajgWfNI lB9UsGpHzfp09RLjaZDkVhpQ3LNYClxjOxPYL0ONiWrfFQFdZHX1ZVdfivvJbGhIeUlC AAJgdJjrwc1f8NEQo/d4YAVqZkoOVp3aB/9e/6KN0SDx1KenQLcJcYMVFDy0mwUJZE/F 1FLX2I67zjiNuXM0pjy6IlTkfT7RoaIlYJq9hXWLjaB2A2zSPu46z+LJhrVY0ui32C9H gm2Dj+Uj1oTnp7GJW2Guxm5zcmd53prsWkEhmLoICz+OodI7vOZKhcxWbj/y+HCJcjZ0 Azhg== X-Gm-Message-State: AAQBX9cZZLpiyNVs2X6lu0Krhwx7smU8HW7X00muhzQGcFyprtFoa9gD DoVljNHhC42OTzD7n1/28OZE9rO3uPUU6S6Fk2bdsg2sbG14qJVgzWCcYg3ODHsBh0TCJD4S+zK mTgVrEoD2kNk4NWrrsMU8B20XC8m1dzlRHBa0susFYvMjXTuLeg== X-Received: by 2002:a25:c04:0:b0:b81:6cda:2ba8 with SMTP id 4-20020a250c04000000b00b816cda2ba8mr1565585ybm.59.1680271246214; Fri, 31 Mar 2023 07:00:46 -0700 (PDT) X-Google-Smtp-Source: AKy350ai0XrfFNeVO9wxMGaWjtKF40Iz8h22tkRQ5VhWtNSAYsAfNpdfaR8oBLUqTIeJvYsoOc5a0w== X-Received: by 2002:a25:c04:0:b0:b81:6cda:2ba8 with SMTP id 4-20020a250c04000000b00b816cda2ba8mr1565537ybm.59.1680271245815; Fri, 31 Mar 2023 07:00:45 -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 a5-20020a256605000000b00b7e0d092f91sm584336ybc.18.2023.03.31.07.00.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Mar 2023 07:00:45 -0700 (PDT) From: John Cabaj To: kernel-team@lists.ubuntu.com Subject: [SRU][jammy][PATCH v2 4/5] s390/unwind: recover kretprobe modified return address in stacktrace Date: Fri, 31 Mar 2023 09:00:40 -0500 Message-Id: <20230331140041.2112510-5-john.cabaj@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230331140041.2112510-1-john.cabaj@canonical.com> References: <20230331140041.2112510-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;