Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2227286imm; Thu, 18 Oct 2018 11:01:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV60X/e5yPlDwycWpRIhYR/rE8XJePzflMzjCFe7YwCYdzwIwjZ8sxMZeyzROXyNOMLHKj554 X-Received: by 2002:a62:3047:: with SMTP id w68-v6mr31396346pfw.19.1539885713360; Thu, 18 Oct 2018 11:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539885713; cv=none; d=google.com; s=arc-20160816; b=BPvxUZMX/4VzDO22+20qQ80IL3Gd7cfgp7TKkMabMNiaVTDQKAeDtYbJCOzWwuzugy NBG001mkYm+L4NcBtb8C53PZFR5ASD7GvbsGXALGkliOv9wTMn2w96Ji5xqfueBt8U/2 IhsNSl5AeRsxVNMC0vFe51C5HqFbu+iapuA/Z1nFRf0s9+gpk3hIT3VSztRY858marD8 MN5rF9Le02XBr9vx675VVxPaYJsN9C0Bf6oDErLFZj3q1yHG+FfgE/2qLs1aPsVPbESo xifMo6uCymeVBPYG57ebuJMYtSck3nl9XN5wdx1VOXXUtU6R9nAVCWsag3AZZxcfXaX8 kZuQ== 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=+Rfa3fOS3RtegAhHJG29P0BQsnn3hExcq4kOpbp8gz4=; b=GP/LJd7VDpiDKeenVuVmLZGS1K3zl5tKmfZBp7JslHETXLUD1cJpTWziTjFnJMwY9F RYHqxKQqHtq1dS77Nn7u2rSnXayo3jvojSebxYoBUUthjkreSmbr7oRfRs4GnYlzeiRe 9CHhxdwYsVj3IB8z94AW+rY7XUC5YVVR2mvodmcalEX8jGLoHeQ10L/m1lYhaqHqxz/E Ka2QMmOQbL0flR1m9nXtQE9OYon9R20mKtVCSlR5QdEvj5i6SN7zwptWD+AtRRDGaS3S ioOHX9fU/coF5I4GRnKDESVW4cZqLwvgEWEp44RidSBWMwmV1Z8vEu6kesL1BnA8O5UB wdIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QfJcPhPN; 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 s17-v6si19362794pgv.445.2018.10.18.11.01.37; Thu, 18 Oct 2018 11:01:53 -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=QfJcPhPN; 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 S1729174AbeJSCBQ (ORCPT + 99 others); Thu, 18 Oct 2018 22:01:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:48928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728438AbeJSCBQ (ORCPT ); Thu, 18 Oct 2018 22:01:16 -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 582F221473; Thu, 18 Oct 2018 17:59:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539885551; bh=zED3MtbRz54cBnxkZao/jWNT/pNYNd9VsJq4ED/7x0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QfJcPhPNJB1tyb8j81OIhMMqxjuwuVhVPf2it4a38LUL1xhsexlMZA4b2OIchQBz4 xy7U+9PeOSfVj9Ej7WQK/MXj/9Jm7m3xGsHpOrjhoU4BITr1kEPMWtzGTBgfB/eY04 mYLweH1DoeRyjzpVjGbrOdl9Rm9Hyufr+ny8JlRE= 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.18 45/53] powerpc/tm: Fix userspace r13 corruption Date: Thu, 18 Oct 2018 19:54:38 +0200 Message-Id: <20181018175424.240220832@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018175416.561567978@linuxfoundation.org> References: <20181018175416.561567978@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.18-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 @@ -175,13 +175,20 @@ _GLOBAL(tm_reclaim) 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 @@ -210,7 +217,7 @@ _GLOBAL(tm_reclaim) 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)