Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2229292imm; Thu, 18 Oct 2018 11:03:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV63KC2BMQb1zwGqxhbGWhz5AQuWMI8TbDm72mEqIHtjCOZLee2ckuBOIPQTXf71hENhqglVf X-Received: by 2002:a62:12c9:: with SMTP id 70-v6mr31667756pfs.140.1539885816863; Thu, 18 Oct 2018 11:03:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539885816; cv=none; d=google.com; s=arc-20160816; b=ihsdYCdUSwFQwk7MUoslYjYSoC7MspaAbIUy6wQXw247ILijhpmys43+7zA/+2WHsg tSbjUrdO0ZD9UXCCdDf7nWpNS+4LY/gu8RxhAtxlylJXOniQauZCEKo7YyLw/Dtqg0AC cbqOCE+9iYuJ7OFetLLmzbr8jKqGPCzjwcpEH4zNA3zdIPCXC/Q9U29xxhqIj1HDcQxG f4aP68F9H5T2CHt8D03xXCucWNhHXJbIw+DEuEXlrYyG5Sln7phSuws6ujo2gJRwXm1X d/iak13cGr8Y+7+A+aSDJo8cCFZcyYPAxeiukWsuTawLZddbL5sul7v2ww3msC+bMscs JOig== 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=iplsyWH5BHiYBo0SrBeGQ8195iPf0sT/UDpiPdJNJkM=; b=Tc0NlBZ1OLGX8t1GH1hokUMdzb6k82aFzdhQtWIR3dhVwS6nuKz2V4tSyoZc8wxIk+ uJlBE+ZEaeB1Qk5OnI18kdwmdRUjhllKSg147QnHHNshRG7JUPL+2g1GxhFWoL4IEaL6 l5C7DPATSG/gsbh1XJy8Jcl6wZ96xq/il/YFk093FEz9ku+00++TVCwsHl0S+jMZeaCL 5as05fw6BsmAfd7qaE419piN199Ca9jSdiZva8kJkeSB6k0KLMjrz8v0RxP7PVf4boKP UIl1iNz+Tg0HlLk0HjItRRO/0tsa3RrGRjXPrz72mVeimllqyJQzua/sRrT/tbHkXfJ5 kQug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=A6d+QtZt; 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 ce19-v6si23885097plb.162.2018.10.18.11.03.21; Thu, 18 Oct 2018 11:03:36 -0700 (PDT) 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=A6d+QtZt; 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 S1729491AbeJSCDD (ORCPT + 99 others); Thu, 18 Oct 2018 22:03:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:51156 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728298AbeJSCDD (ORCPT ); Thu, 18 Oct 2018 22:03:03 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (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 07DBB205C9; Thu, 18 Oct 2018 18:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539885657; bh=Q6UJ6hNVwggFKvDmA42g0y+vcUenp3k4S6+94zvz41Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A6d+QtZtF3ezCcts4V6TpPsA9AfMNuFu6OHN8i2bkxYyh5k+lF4X6fPyLRVyZhH59 Gt/txS0kqp8B8TCcUSAmUdgD+A7mhZ2RweGrn+4S8dmrfTMRQJOBvfZH20qQ/lbabk E08r0eBAveiSZ7zKOcO4T4JA1BU6OPnGs78b+Czc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Breno Leitao , Michael Neuling , Michael Ellerman , Sasha Levin Subject: [PATCH 4.14 28/41] powerpc/tm: Avoid possible userspace r1 corruption on reclaim Date: Thu, 18 Oct 2018 19:54:43 +0200 Message-Id: <20181018175421.775568378@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018175416.718399607@linuxfoundation.org> References: <20181018175416.718399607@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael Neuling [ Upstream commit 96dc89d526ef77604376f06220e3d2931a0bfd58 ] Current we store the userspace r1 to PACATMSCRATCH before finally saving it to the thread struct. In theory an exception could be taken here (like a machine check or SLB miss) that could write PACATMSCRATCH and hence corrupt the userspace r1. The SLB fault currently doesn't touch PACATMSCRATCH, but others do. We've never actually seen this happen but it's theoretically possible. Either way, the code is fragile as it is. This patch saves r1 to the kernel stack (which can't fault) before we turn MSR[RI] back on. PACATMSCRATCH is still used but only with MSR[RI] off. We then copy r1 from the kernel stack to the thread struct once we have MSR[RI] back on. Suggested-by: Breno Leitao Signed-off-by: Michael Neuling Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/tm.S | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/arch/powerpc/kernel/tm.S +++ b/arch/powerpc/kernel/tm.S @@ -170,6 +170,13 @@ _GLOBAL(tm_reclaim) std r11, GPR11(r1) /* Temporary stash */ /* + * Move the saved user r1 to the kernel stack in case PACATMSCRATCH is + * clobbered by an exception once we turn on MSR_RI below. + */ + ld r11, PACATMSCRATCH(r13) + std r11, GPR1(r1) + + /* * Store r13 away so we can free up the scratch SPR for the SLB fault * handler (needed once we start accessing the thread_struct). */ @@ -205,7 +212,7 @@ _GLOBAL(tm_reclaim) SAVE_GPR(8, r7) /* user r8 */ SAVE_GPR(9, r7) /* user r9 */ SAVE_GPR(10, r7) /* user r10 */ - ld r3, PACATMSCRATCH(r13) /* user r1 */ + ld r3, GPR1(r1) /* user r1 */ ld r4, GPR7(r1) /* user r7 */ ld r5, GPR11(r1) /* user r11 */ ld r6, GPR12(r1) /* user r12 */