From patchwork Mon Mar 15 16:57:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12140097 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=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,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 EAEF7C433DB for ; Mon, 15 Mar 2021 17:00:54 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 995DA64DC4 for ; Mon, 15 Mar 2021 17:00:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 995DA64DC4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=EB3TaxRrbmi0lY4UlfaUF70U65nQ/DWonN6Jv3MDYDw=; b=IEkDwIcx1ZGMC/VgQUoh08E22 /J+XzkCADg9kHs2ceH29cRl0nUsz7cuZUZcuzzSg+Li7buyF6ztGICNq+9aHTosi5j5YM85p7Mm1n S8Peenl8XyZHdoNVkSPJGK4jaidvE3aok3xIxbHgZ3KsS11zDhHx3cjpd3Qzt4crxg6sqE/B8jyIT 9Qidcf6vrf6GxmhTV88kO/eE2CqPy9IMH1DTYDEFLbDqAdC6bWLlAftiVaSj4mIYi6cPVYA5lIMf3 qjBOS4vK3fDAXWvY5yQdoQ4z2v/vyVMFPFeRp17Ue++dMe9iAwLtSgvp3XVfjZHoWPv4+AZ5GWXR1 O5RNCNMig==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lLqYi-00GPzK-Ba; Mon, 15 Mar 2021 16:59:12 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lLqXo-00GPnS-2h for linux-arm-kernel@lists.infradead.org; Mon, 15 Mar 2021 16:58:18 +0000 Received: from x64host.home (unknown [47.187.194.202]) by linux.microsoft.com (Postfix) with ESMTPSA id 0D28B20B26FA; Mon, 15 Mar 2021 09:58:12 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0D28B20B26FA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1615827493; bh=0gTjptmyQZ07PiZCSnD/YKcvyyL392ig4rm2FEjYn/Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=R91XTzYfYCb0ZGw7P5w4k2c0wPMwNZx0Cb+QOzipMegJEzUGor2RF4EgdBmkFiCl2 myKycQk1amy6owG1HVBpw2L8EDnrxOhlsmEcvGJNMcxBmYgdrTzwMJWJ4ZHWh8xB4g +vEDShINtXTKrHlAz0KkHIh8BpePpQG/nsUveU70= From: madvenka@linux.microsoft.com To: broonie@kernel.org, mark.rutland@arm.com, jpoimboe@redhat.com, jthierry@redhat.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [RFC PATCH v2 3/8] arm64: Terminate the stack trace at TASK_FRAME and EL0_FRAME Date: Mon, 15 Mar 2021 11:57:55 -0500 Message-Id: <20210315165800.5948-4-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210315165800.5948-1-madvenka@linux.microsoft.com> References: <5997dfe8d261a3a543667b83c902883c1e4bd270> <20210315165800.5948-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210315_165816_314072_EF667302 X-CRM114-Status: GOOD ( 11.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: "Madhavan T. Venkataraman" Implement the following checks in the unwinder to detect the terminating frame reliably: - The frame must end in task_pt_regs(task)->stackframe. - The frame type must be either TASK_FRAME or EL0_FRAME. Signed-off-by: Madhavan T. Venkataraman --- arch/arm64/kernel/stacktrace.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index ad20981dfda4..504cd161339d 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -43,16 +43,22 @@ int notrace unwind_frame(struct task_struct *tsk, struct stackframe *frame) { unsigned long fp = frame->fp; struct stack_info info; + struct pt_regs *regs; - /* Terminal record; nothing to unwind */ - if (!fp) - return -ENOENT; + if (!tsk) + tsk = current; + regs = task_pt_regs(tsk); - if (fp & 0xf) + /* Terminal record, nothing to unwind */ + if (fp == (unsigned long) regs->stackframe) { + if (regs->frame_type == TASK_FRAME || + regs->frame_type == EL0_FRAME) + return -ENOENT; return -EINVAL; + } - if (!tsk) - tsk = current; + if (!fp || fp & 0xf) + return -EINVAL; if (!on_accessible_stack(tsk, fp, &info)) return -EINVAL;