From patchwork Mon May 17 14:01:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 440109 Delivered-To: patch@linaro.org Received: by 2002:a02:7a1b:0:0:0:0:0 with SMTP id a27csp1135939jac; Mon, 17 May 2021 07:21:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFmFihkTIjbIgC0zGh8+dpGwo9xLmwj4a/BGIYYu1tmCQd+Gj9bRBD41f8c992BeX/m3O2 X-Received: by 2002:a05:6602:140c:: with SMTP id t12mr166105iov.169.1621261284702; Mon, 17 May 2021 07:21:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621261284; cv=none; d=google.com; s=arc-20160816; b=ZeMiJL4fOYzl+lUtmlnJuYN3Tc4K7fpmTTHJu+dlmKPr9FLNuPS+0q1d+fTTnikhcJ RUAiZTvkiwSBANrfZZ6Dfci3M+mtHYxZAFkjZfDLb9Cmh3cSo+SwyEvBLOqRnkz+73mg Sa5sQufC7P4fDsWABJZnDGmfOMN/TxQLn1T6zAE/110Jt8x5W6rQJhrWW4sRvH5tuaxw h4Ch2iqjiS1L3+d0foa62G1vcll0ORy/JGoxdD0lsq+vlrcFf2O4o4+Q4IRUh1Hb434p a+DF+Co4p4Ra0NMHoIirCtolcvndblgsY7gradPYGvnEs/Cn7bsF2Kch+mChqQKf9pEJ ht0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QPohYBnvEe8qdD9UFh+63W/w/Y4p0Ztc+M4JoX/V/2E=; b=Yh2UBIz2o5E4Xeqkvvvkepdy44fVKEPStPBlPpm6fHH5kcSgA/1Qju/+i3kPf9xa54 VkrCXwqRbA4Ip6sBFtGxorZoA+kymLqLQcaE2ZD4J7NbNt7TAsfMeTJfQ4SSPedYp4bA W41O4bRwVSvI6iME2r0upUmOOYn8A6e9rW82grKTlUQFL3bMGaIucSqY3WHZNu3iHN1K ukw7SKaZA6/ycFmqeQifySEoKsNtTxo07lYdd7CZrhyARAUCa7ZthBubC0V4aiwkHWtG 9odyfcqUMX1Zq9rgt5L9LpJEjbzZtfFFNK2rD0FfGYC+H1R2MRvFtlv+5xtbzfw7iqeX 2N0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BNJpKld1; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si18328560ilh.102.2021.05.17.07.21.24; Mon, 17 May 2021 07:21:24 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BNJpKld1; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238426AbhEQOWg (ORCPT + 12 others); Mon, 17 May 2021 10:22:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:36042 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239513AbhEQOUi (ORCPT ); Mon, 17 May 2021 10:20:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1EEAF6144A; Mon, 17 May 2021 14:11:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260686; bh=H/UjSLWe2gKRKNd5bR/1Arj/5DEzJMyIMf14pVzdwN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BNJpKld1HKOEGpt8aMbZ3yUnHD6II6eRYx6s+oPEPKsI/WIIcIBdWznRblbcHjr2n yccFYG9LwMCM89vqjojMu8NlstQDW/BYxrFuDDuuIbWK+wuuUl8m4mJpYxRG9YudN3 MnfYx4dRKmIelS22I3IAP54bygVkP0geBZmOXG8o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Leo Yan , Will Deacon , Mark Brown , "Madhavan T. Venkataraman" , Catalin Marinas , Sasha Levin Subject: [PATCH 5.12 195/363] arm64: stacktrace: restore terminal records Date: Mon, 17 May 2021 16:01:01 +0200 Message-Id: <20210517140309.174909250@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mark Rutland [ Upstream commit 8533d5bfad41e74b7dd80d292fd484913cdfb374 ] We removed the terminal frame records in commit: 6106e1112cc69a36 ("arm64: remove EL0 exception frame record") ... on the assumption that as we no longer used them to find the pt_regs at exception boundaries, they were no longer necessary. However, Leo reports that as an unintended side-effect, this causes traces which cross secondary_start_kernel to terminate one entry too late, with a spurious "0" entry. There are a few ways we could sovle this, but as we're planning to use terminal records for RELIABLE_STACKTRACE, let's revert the logic change for now, keeping the update comments and accounting for the changes in commit: 3c02600144bdb0a1 ("arm64: stacktrace: Report when we reach the end of the stack") This is effectively a partial revert of commit: 6106e1112cc69a36 ("arm64: remove EL0 exception frame record") Signed-off-by: Mark Rutland Fixes: 6106e1112cc6 ("arm64: remove EL0 exception frame record") Reported-by: Leo Yan Tested-by: Leo Yan Cc: Will Deacon Cc: Mark Brown Cc: "Madhavan T. Venkataraman" Link: https://lore.kernel.org/r/20210429104813.GA33550@C02TD0UTHF1T.local Signed-off-by: Catalin Marinas Signed-off-by: Sasha Levin --- arch/arm64/kernel/entry.S | 6 +++--- arch/arm64/kernel/stacktrace.c | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) -- 2.30.2 diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index 6acfc5e6b5e0..9b205744a233 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -263,16 +263,16 @@ alternative_else_nop_endif stp lr, x21, [sp, #S_LR] /* - * For exceptions from EL0, terminate the callchain here. + * For exceptions from EL0, create a terminal frame record. * For exceptions from EL1, create a synthetic frame record so the * interrupted code shows up in the backtrace. */ .if \el == 0 - mov x29, xzr + stp xzr, xzr, [sp, #S_STACKFRAME] .else stp x29, x22, [sp, #S_STACKFRAME] - add x29, sp, #S_STACKFRAME .endif + add x29, sp, #S_STACKFRAME #ifdef CONFIG_ARM64_SW_TTBR0_PAN alternative_if_not ARM64_HAS_PAN diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index d55bdfb7789c..7032a5f9e624 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -44,10 +44,6 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) unsigned long fp = frame->fp; struct stack_info info; - /* Terminal record; nothing to unwind */ - if (!fp) - return -ENOENT; - if (fp & 0xf) return -EINVAL; @@ -108,6 +104,12 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) frame->pc = ptrauth_strip_insn_pac(frame->pc); + /* + * This is a terminal record, so we have finished unwinding. + */ + if (!frame->fp && !frame->pc) + return -ENOENT; + return 0; } NOKPROBE_SYMBOL(unwind_frame);