Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4487721ybx; Mon, 4 Nov 2019 14:14:54 -0800 (PST) X-Google-Smtp-Source: APXvYqxRm1/eoe2mki/KxgEW9niK03N8xVyjrIJGskXFT0S0n+7NeARfpU2Z1SanEmxIlM6KFlnT X-Received: by 2002:aa7:c145:: with SMTP id r5mr9675733edp.102.1572905694121; Mon, 04 Nov 2019 14:14:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572905694; cv=none; d=google.com; s=arc-20160816; b=aQVsVwGMALNlJgB3QQ1AH3gl9ARjBmy6qbV/HatJ8YZEaHJ7d34C+Z7mQb0cUuEXLE ppqfitc/bcMhuzR4oRWsQ6Imt+Zwbo9vi8+tTrPsGieOtFR0YRL7ShSQnVUDTR7D28mF hCBYjofHeXU9wXPz55oFFAmQSHYmABvq/FUJ9D7ndLR0kuyiv6uWBW3MGpeSQlQhafVU d4+F2WVPYI1YPRTROtP9/fjUSlTodtPg2V0/VJPhQdQuosm7w8jqCHJ8W7KEw8PpiSf3 eI+TrXwret1qKO+9yhvTxSWGh4pYujZAeQKz+wA4IAwKKdk0dyUiniTbqlb35LZsiDHP SKeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bIF+cZK90p+2jCyoQc7Dcup5bsGynxYIG8w1TbxlNvc=; b=S8O0cNIM5mixyPJx2Q1Hh+3CyEJ3//mNGhVmREjh9wV7hp7Vl6o774FAyrRU0ArttA at8FtkMvuypzXNXatndD6xD6rwIihipCXZtIkd5u+KleMboYackcbRW6trxATD1lgt6z t9qKHKJ5gNiF4IIYE0U5iqdqd3OD82g/r1f2PEltF9zlicWhBz4C6FM6c7BNpVyb5ifc XZ1vaIk8pylnjNaktEtj4QINDiq/xtjramT189cQRrazkarXzEayjOJpzj4+qVi/s7aw E7U8zQ5+3txd/Ust9WJcbFmygceX2SNvxO43kpobIszsuhavcPamHdMapUvPXBJVW8gO YB9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dNDp+mcm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g11si8794752ejx.212.2019.11.04.14.14.30; Mon, 04 Nov 2019 14:14:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dNDp+mcm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390426AbfKDWJe (ORCPT + 99 others); Mon, 4 Nov 2019 17:09:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:42670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390418AbfKDWJd (ORCPT ); Mon, 4 Nov 2019 17:09:33 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7CE6F20650; Mon, 4 Nov 2019 22:09:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572905372; bh=mY9b+i7LidgwnXe/Qx61bnZHFbA9frZCx9Me8Ze/Sm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dNDp+mcmL1zuYWBTxNAQLuu0C/CbAHV3KSZJ7oDyUZtuyv26uOcv86rY1xqHGKhu+ JnWXioVG94lrxitryGRF8Aqk29ZzUaraAq99Tmpbkdh62nOstTpt5tje93XrO5rv6i nqyZbhJiVsTAGcrUfP1u6T2KgpPoPBjhwsYdc05A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilya Leoshkevich , Heiko Carstens , Vasily Gorbik Subject: [PATCH 5.3 122/163] s390/unwind: fix mixing regs and sp Date: Mon, 4 Nov 2019 22:45:12 +0100 Message-Id: <20191104212149.057129464@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104212140.046021995@linuxfoundation.org> References: <20191104212140.046021995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilya Leoshkevich commit a1d863ac3e1085e1fea9caafd87252d08731de2e upstream. unwind_for_each_frame stops after the first frame if regs->gprs[15] <= sp. The reason is that in case regs are specified, the first frame should be regs->psw.addr and the second frame should be sp->gprs[8]. However, currently the second frame is regs->gprs[15], which confuses outside_of_stack(). Fix by introducing a flag to distinguish this special case from unwinding the interrupt handler, for which the current behavior is appropriate. Fixes: 78c98f907413 ("s390/unwind: introduce stack unwind API") Signed-off-by: Ilya Leoshkevich Cc: stable@vger.kernel.org # v5.2+ Reviewed-by: Heiko Carstens Signed-off-by: Vasily Gorbik Signed-off-by: Greg Kroah-Hartman --- arch/s390/include/asm/unwind.h | 1 + arch/s390/kernel/unwind_bc.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) --- a/arch/s390/include/asm/unwind.h +++ b/arch/s390/include/asm/unwind.h @@ -35,6 +35,7 @@ struct unwind_state { struct task_struct *task; struct pt_regs *regs; unsigned long sp, ip; + bool reuse_sp; int graph_idx; bool reliable; bool error; --- a/arch/s390/kernel/unwind_bc.c +++ b/arch/s390/kernel/unwind_bc.c @@ -46,10 +46,15 @@ bool unwind_next_frame(struct unwind_sta regs = state->regs; if (unlikely(regs)) { - sp = READ_ONCE_NOCHECK(regs->gprs[15]); - if (unlikely(outside_of_stack(state, sp))) { - if (!update_stack_info(state, sp)) - goto out_err; + if (state->reuse_sp) { + sp = state->sp; + state->reuse_sp = false; + } else { + sp = READ_ONCE_NOCHECK(regs->gprs[15]); + if (unlikely(outside_of_stack(state, sp))) { + if (!update_stack_info(state, sp)) + goto out_err; + } } sf = (struct stack_frame *) sp; ip = READ_ONCE_NOCHECK(sf->gprs[8]); @@ -107,9 +112,9 @@ void __unwind_start(struct unwind_state { struct stack_info *info = &state->stack_info; unsigned long *mask = &state->stack_mask; + bool reliable, reuse_sp; struct stack_frame *sf; unsigned long ip; - bool reliable; memset(state, 0, sizeof(*state)); state->task = task; @@ -134,10 +139,12 @@ void __unwind_start(struct unwind_state if (regs) { ip = READ_ONCE_NOCHECK(regs->psw.addr); reliable = true; + reuse_sp = true; } else { sf = (struct stack_frame *) sp; ip = READ_ONCE_NOCHECK(sf->gprs[8]); reliable = false; + reuse_sp = false; } #ifdef CONFIG_FUNCTION_GRAPH_TRACER @@ -151,5 +158,6 @@ void __unwind_start(struct unwind_state state->sp = sp; state->ip = ip; state->reliable = reliable; + state->reuse_sp = reuse_sp; } EXPORT_SYMBOL_GPL(__unwind_start);