Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2260513imm; Thu, 18 Oct 2018 11:34:34 -0700 (PDT) X-Google-Smtp-Source: ACcGV62koisBAiTPWiLYLi1P4PQa9ZvrSColXBxHtYPUr08gjKsP2mVmuQBw4TEu1uZaEZXptKF3 X-Received: by 2002:a63:1520:: with SMTP id v32-v6mr29916010pgl.150.1539887674569; Thu, 18 Oct 2018 11:34:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539887674; cv=none; d=google.com; s=arc-20160816; b=QkvGFB+07ADaduTlK3Q6kSC4Rx46G5WBtnZQC6goMUzXd0UQ3FOw2hyHGI6Hudzgeq qtZccKuyfp6pQrKFxKf/isCtlBB5DFh2g5emIMxG4PtluSVFQFNqtMIJhVDvq5925iJ6 5e/D1cc2ATDqGd62oHru9ejI5L8DS+UQjyJUmMeBJ2yOtdJdB28Mke0Rlkp4F798+W1v WgaGStiITEgq842wNfTx8MphVe5jy+rRv4RcQyMK+2g9fXSIyy8Q5Gibm/PNrJ0KE1ei oxpvzL/zbdDf5sp8ZU+LfBCj/9Zl5/fZuR8wIMC5zcL94KtOuG3Veedk4JgKTs3GDtcG 0cFw== 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=aZ6peDIVVzLOB/jxeQsOjfE2HM2j14ouhY2/L6sjewo=; b=HY/zjBBY0AimAEawtpPMrjex8Fv92TBii+pdfhdWBXr9Nq0XmVqM1TtHRArn1Mf8if vFwcbFKwI9LV6vswbKsgykFgNZv4mnb55a/o3DPX7X7Eiir2oJ2JAguVoX/I6/T1kPfM RLX+SamBS8AwLYwFRerX1bpEXhyOEHXqWXYmMtXbDcPeFynKkQ68t1Wpac3xnpJrvV9L Ff7S6eh/ypiWk6a8VVgIFobSeD0ivfryN792YG0OrXeyi1WaRrwSJX4bC4Ty5q4FsBjl qJG6iEFquuvlYqpIRFR+6QDCLQON/fwo5iA8XX0KOujUuT4oeB/9ZmhL9DBUqaDH1llA ADQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gGEDPQMN; 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 q4-v6si22755300pgj.417.2018.10.18.11.34.19; Thu, 18 Oct 2018 11:34:34 -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=gGEDPQMN; 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 S1730689AbeJSCJc (ORCPT + 99 others); Thu, 18 Oct 2018 22:09:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:59002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728851AbeJSCJc (ORCPT ); Thu, 18 Oct 2018 22:09:32 -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 C472B20658; Thu, 18 Oct 2018 18:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539886044; bh=1IlCrphBLd2ppfoYdkqdtmJNwEQBvrMip9VYqERm9Ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gGEDPQMNQ2KvT8apyf0HhUzdeyI5RlKeXaHE7ncmJRi+G4VQLW/1R1KefK27y/FnO TO9Y8O1W2ig4O9gj85nUTn9FvRooIJG1bdEWaGsczXCaO6WH782o7imV9sBQ/EuyoX /7wg3frF0hy3/0BVi6yPBHAKOAGEMAobrghOufjE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Neuling , Breno Leitao , Michael Ellerman , Sasha Levin Subject: [PATCH 4.4 41/48] powerpc/tm: Fix userspace r13 corruption Date: Thu, 18 Oct 2018 19:55:16 +0200 Message-Id: <20181018175430.101932836@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 cf13435b730a502e814c63c84d93db131e563f5f ] When we treclaim we store the userspace checkpointed r13 to a scratch SPR and then later save the scratch SPR to the user thread struct. Unfortunately, this doesn't work as accessing the user thread struct can take an SLB fault and the SLB fault handler will write the same scratch SPRG that now contains the userspace r13. To fix this, we store r13 to the kernel stack (which can't fault) before we access the user thread struct. Found by running P8 guest + powervm + disable_1tb_segments + TM. Seen as a random userspace segfault with r13 looking like a kernel address. Signed-off-by: Michael Neuling Reviewed-by: Breno Leitao Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/tm.S | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/arch/powerpc/kernel/tm.S +++ b/arch/powerpc/kernel/tm.S @@ -199,13 +199,20 @@ dont_backup_fp: std r1, PACATMSCRATCH(r13) ld r1, PACAR1(r13) - /* Store the PPR in r11 and reset to decent value */ std r11, GPR11(r1) /* Temporary stash */ + /* + * Store r13 away so we can free up the scratch SPR for the SLB fault + * handler (needed once we start accessing the thread_struct). + */ + GET_SCRATCH0(r11) + std r11, GPR13(r1) + /* Reset MSR RI so we can take SLB faults again */ li r11, MSR_RI mtmsrd r11, 1 + /* Store the PPR in r11 and reset to decent value */ mfspr r11, SPRN_PPR HMT_MEDIUM @@ -234,7 +241,7 @@ dont_backup_fp: ld r4, GPR7(r1) /* user r7 */ ld r5, GPR11(r1) /* user r11 */ ld r6, GPR12(r1) /* user r12 */ - GET_SCRATCH0(8) /* user r13 */ + ld r8, GPR13(r1) /* user r13 */ std r3, GPR1(r7) std r4, GPR7(r7) std r5, GPR11(r7)