Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3728428imm; Mon, 8 Oct 2018 08:36:04 -0700 (PDT) X-Google-Smtp-Source: ACcGV60PcQ/EW9B0t7+p3RsKqtPDVC7V/ZPka+gjjuRsWF1ZIe8e70gkwk+CBU7Cbe6M1MOFMNeF X-Received: by 2002:a17:902:a5ca:: with SMTP id t10-v6mr24153436plq.113.1539012964568; Mon, 08 Oct 2018 08:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539012964; cv=none; d=google.com; s=arc-20160816; b=CdqwEtb29tkvVv16e/eZI7gOafQQlm2wls4OXyfL5Pv1D90mjYs6fhweYZb6CRSN5D SrLIRzn/agga0mNp6mPKyl4ssRO4lML1HXmhA86lQBM3p5Ez/5quiFMhfsa6uxC4tBaR bR7xQTt9OetQlZ7zWGHWRTqJ6cTUQv++FkJKDBjtozJBMN/m/Kz0isj3X1rVpdts8fR5 OxJmEU0ZIk6TtPn+Ghp1JSLg4FtWaUjoRyJBC/ZdC6Ja3VrtgS+S7i7gXjz9OAmafvqy O0zdei/G9Tvh0IAz0haKEJghXx8g3DB6Iyqdtvhzt25EVS1cTBBK/7pSTa8EsJtY41xU CE0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=l9KzuGjatNnXTJRiMiompVp6pCQEfcqqZBntM9BaIJE=; b=ZhGED1JqfqlY3v3vm9Daw/RDWXPBf6DSnds5Qa69Y6MGk34OqgqpeZurDkHnYdttuv AufFE1yIxuuQfIPuqi9S6mn6XjvuEjIX+LXmZtmCQQ3uT3pgyc4OiF26Z6TOywjpyvYd 8U6rfjFFSHRq/4xXwbQhP26AVOAsnFN/GllIJMSvZgTPZ2TGh1NxMy0vKbq/K9zog7Ut 1BX/u7urmzNJy9tS1g5JMST5vPISULas03fnwGeIITeweltT+zENYt+z9AR+/ADAGyzn PirmMMWB11t4X/vdePx15Pvwfjwj94+cNjhXNrLi9DSYFBk7l7b6UGdAuM7dipQgFruz Ts7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="JNP/E3Me"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b1-v6si14594848plc.237.2018.10.08.08.35.49; Mon, 08 Oct 2018 08:36:04 -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="JNP/E3Me"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728133AbeJHWie (ORCPT + 99 others); Mon, 8 Oct 2018 18:38:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:57210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727563AbeJHWid (ORCPT ); Mon, 8 Oct 2018 18:38:33 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BDBAF214FA; Mon, 8 Oct 2018 15:26:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539012378; bh=GGlYVnPuvyi5QZBDaABbJwN0ZJe4t2lRc3HreMt4M0U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JNP/E3MeXjJCjiWtG+xC4IFdC7ln6CimaVHoel8qDegUj+lo2soxhSRVgPtz5Cmqv D90oaqhHON2oCSjdPFYEdH/6hK+nL7phGUZHYqNYBVpFsQvLN4DOiAd7kAaS0S3LLp ePP9eQl7XSPs8kfJxBaut+zGrzcao8/fwAU6tIHo= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michael Neuling , Michael Ellerman , Sasha Levin Subject: [PATCH AUTOSEL 4.18 55/58] powerpc/tm: Avoid possible userspace r1 corruption on reclaim Date: Mon, 8 Oct 2018 11:25:20 -0400 Message-Id: <20181008152523.70705-55-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181008152523.70705-1-sashal@kernel.org> References: <20181008152523.70705-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/powerpc/kernel/tm.S | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/tm.S b/arch/powerpc/kernel/tm.S index 11a8f0b71422..09d347b61218 100644 --- a/arch/powerpc/kernel/tm.S +++ b/arch/powerpc/kernel/tm.S @@ -177,6 +177,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). @@ -213,7 +220,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 */ -- 2.17.1