From patchwork Thu Oct 3 15:53:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 175110 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp534477ill; Thu, 3 Oct 2019 09:13:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwByl23gIdA6HhErF+7YlEdxsz0uHk+JRGvam7UaCGfNLxE6HZgb0Sjg8iJU6V1hzFhh07w X-Received: by 2002:a50:95c1:: with SMTP id x1mr10299867eda.180.1570119075126; Thu, 03 Oct 2019 09:11:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570119075; cv=none; d=google.com; s=arc-20160816; b=tBsIdTGGCRz22xxo+9ODe916uio1eRz0fqlO2O0Um+h3N3teoP6VV6/I6N2H0p7nAe tqX41FP55S91WjNDrXuWec+C02tO7qIblVi6Rk35TysWKRiJX/Dgguyc9l7v7rOnZh12 4MewSOCqjNxJhwNL6yTSpmoyIGWDrukz6AkLX841smV1V3/U1lVspUJp9BCeFATAPWQa 2c8grQ5GkTs1WxobbpfwYKPaDNr6SwrnSRzzFerhq6DbsA3aWmA+1EFNY6HhviOxH+39 ipteiTixxO0Go12igW+uqZYLlF3QtHw/IJUwTXKcrVp4AaGjVlsftDS9LRSGKQbtHuvi FM9g== 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=E3W8vCNdF/GOv6NjmiAbd7KtJvRt4G2fImedtxaRKZI=; b=sjYUmIegJlzp2HuLx/UHfIrdUp5maFiK+/33tDvNKRgeX5xA1Yp60T9R3Zx6Yx74FL QvYui2fM6V+YF6MUryd+uguJAMpiN+T+NGTfa+O3mKvm2sxd5YBlKbT4NyFCkIi+LG87 dxp06/mq+QU8CDQVRVVE4tIkzL460AnIs6xJeuCc+dOgiJYkyafP6uFAWlIrgnD0lTHU HMoSC6Ihw4TC1myX0+dZh9ZjQ5mEeaNvhJ9WAFo6r5DKOou0umLKIjROE/9iOEnidTr2 bxoE9pwlV9rN6c+Y7XfclXq8FQepudGZB61qpj+lXIm3yRd3I4GrU3CIMKsVVhEUAK74 VI7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J8iGZupt; 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 me23si1499594ejb.344.2019.10.03.09.11.14; Thu, 03 Oct 2019 09:11:15 -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=J8iGZupt; 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 S2387794AbfJCQLN (ORCPT + 27 others); Thu, 3 Oct 2019 12:11:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:60916 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387769AbfJCQLJ (ORCPT ); Thu, 3 Oct 2019 12:11:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 B35C120700; Thu, 3 Oct 2019 16:11:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119069; bh=/LpltrAgNejfjNwAl2+uhOAMJdYtq16InXFtN/oWKtc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J8iGZuptbkta6pFDD6mdZfXP8K40PHG9zdeoSpZ76QXXXdf6IYq8WIvyVQRZwHUrX Vg+FPOXcaJpD1A8AdLFZKQkqR8/QrLdi7engL6eaz9zbOE0hEd+NL85D2d9CAENnp7 yb6DpYmE26ke4iB6k4E6zLnychHPYLY0LaeKSqGU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Catalin Marinas , James Morse , Will Deacon , Sasha Levin Subject: [PATCH 4.14 113/185] arm64: kpti: ensure patched kernel text is fetched from PoU Date: Thu, 3 Oct 2019 17:53:11 +0200 Message-Id: <20191003154504.138415870@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154437.541662648@linuxfoundation.org> References: <20191003154437.541662648@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mark Rutland [ Upstream commit f32c7a8e45105bd0af76872bf6eef0438ff12fb2 ] While the MMUs is disabled, I-cache speculation can result in instructions being fetched from the PoC. During boot we may patch instructions (e.g. for alternatives and jump labels), and these may be dirty at the PoU (and stale at the PoC). Thus, while the MMU is disabled in the KPTI pagetable fixup code we may load stale instructions into the I-cache, potentially leading to subsequent crashes when executing regions of code which have been modified at runtime. Similarly to commit: 8ec41987436d566f ("arm64: mm: ensure patched kernel text is fetched from PoU") ... we can invalidate the I-cache after enabling the MMU to prevent such issues. The KPTI pagetable fixup code itself should be clean to the PoC per the boot protocol, so no maintenance is required for this code. Signed-off-by: Mark Rutland Cc: Catalin Marinas Reviewed-by: James Morse Signed-off-by: Will Deacon Signed-off-by: Sasha Levin --- arch/arm64/mm/proc.S | 9 +++++++++ 1 file changed, 9 insertions(+) -- 2.20.1 diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 034a3a2a38ee8..65b0401521846 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -280,6 +280,15 @@ skip_pgd: msr sctlr_el1, x18 isb + /* + * Invalidate the local I-cache so that any instructions fetched + * speculatively from the PoC are discarded, since they may have + * been dynamically patched at the PoU. + */ + ic iallu + dsb nsh + isb + /* Set the flag to zero to indicate that we're all done */ str wzr, [flag_ptr] ret