Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2236282imm; Thu, 18 Oct 2018 11:09:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV62RWNBHzr4jLaECdFaLKmcKB0q8KPSg8qsOG83ox4FigCA44noTTtwdLTNKblNCdKjdFzrn X-Received: by 2002:a63:df03:: with SMTP id u3-v6mr10513409pgg.362.1539886189596; Thu, 18 Oct 2018 11:09:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539886189; cv=none; d=google.com; s=arc-20160816; b=gW3EfUAIJKS9i5eE0/aiQYlKFV+kzLP6nieyGxuct/rnjVh40hXhFqCBEI1wMq3SQE A+bkl7RlnkoSZ6XdqF7LbpCNdvNQdfys6yXjOUBwVYrbtn3Qgnw6uQzwiDxe52aJ5aqS VeNTb3EHuWHeavOFyyNUF8d/Gf9oZEuzpoKsLK46X9jfldENLz00g/6y1LP2l67xrsS5 ygkUXHFT/mA1x9mOJ4sdrd/3f9jT3hKlDzCFa1HQQDt+Ulq2bOVJQvEUvG6LmdfbCylR 2CAPrOFDk4csGcAbbGAJucjE3Eq1NGKMgS38N2hE/7yTTpVT1zpJcz1v6NHxq1Y2LsOp GXzw== 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=RqUd3pJPN6jov7BPZSMIOXxJamilxWtUaz43DRDLAz0=; b=sq4OycSETzQOvS8B1eNCcbfnt+YsXRI2PMiLG7YDmCCtNDSoaJND+9ORLdt8VKyeET X+1cot7jPRMiGaR1kI0YsbfwKaYxitUe4GLPWDZRD+6VV4mSd+V4pb4NYJj/GXmeaEXF 8/AE1sqhsWDRtG5Qfx9CifUxlPU0HkMatEwL2GZTKVOEln6YjxffiVkdbcGMvga2wSqG kAAygEajWilxrZjbikD0C7AoUDK2LL2B/2cKT9m64slgbLEzOLZY2ksYLmcV3he3e+D/ Llxwc72SedYpI/Saz76fuYNqIbWbzdpjbpt5u7in6sdC272FkEeG+JHpVTVukTmPIF7q 4K7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v2+bLmLx; 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 v33-v6si21389458pga.450.2018.10.18.11.09.34; Thu, 18 Oct 2018 11:09:49 -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=v2+bLmLx; 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 S1730701AbeJSCJf (ORCPT + 99 others); Thu, 18 Oct 2018 22:09:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:59092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728851AbeJSCJf (ORCPT ); Thu, 18 Oct 2018 22:09:35 -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 4F500204FD; Thu, 18 Oct 2018 18:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539886047; bh=OfQW6qNd9PRGAYxWLxJVnzpuaq/nq7rTlxfSy1bQiNc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v2+bLmLxUsyqYq8g/X07yFMbOrBbwcEFLlGcR9wdI/izO7RMPZLjwGfeFL1i4sJuj wA/4V6rNDi1CUIGaDKWrMtS+dCTCRLdnL4/TxRfHqLueNHD3/LZji1MQ2C0X7TMhPj AgGGihG3m6BM+8THwTcqqga/AfTgmI3AL2w5WUMc= 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.4 42/48] powerpc/tm: Avoid possible userspace r1 corruption on reclaim Date: Thu, 18 Oct 2018 19:55:17 +0200 Message-Id: <20181018175430.154133456@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018175427.133690306@linuxfoundation.org> References: <20181018175427.133690306@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.4-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 @@ -202,6 +202,13 @@ dont_backup_fp: 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). */ @@ -237,7 +244,7 @@ dont_backup_fp: 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 */