Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp64824ybp; Thu, 3 Oct 2019 10:13:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUhxNbhib7T0HmDor6BFkvn9gS6NYPz924qmOqjfvHCaArIol+/f9hiPWrn+DonF9DTdmk X-Received: by 2002:a50:886d:: with SMTP id c42mr10706596edc.24.1570122830809; Thu, 03 Oct 2019 10:13:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570122830; cv=none; d=google.com; s=arc-20160816; b=PKJV3Fsu3ROnY0kB/+KVDzi7zk9yS0L3xzVgJ9OTn84hZQTnJKCw2eN2h43UNJ+aTv lBANGb7txKl5Iv4QGslYp0wJSqU67EN4fXFfGSLLVAg9lDoGZLjYh9mSOptPq9Omr0Gc NCRrPwX2AMfbej+pi8rCfv+wq/N86uBk8nDFZHmA8Jcx5KOtUD5B2idEuAD3ZEQaSy/o jGneYGbkLuhGxvkeS5LlW5V9pSnNluc4l4+XLv5qTIKUe4PHEWx/3p7YE+48Q9wL7TcX 0yGBexiIdRZGX9jRWqX8Z2JfCZl6Oz8WqMgayN7gWhSlUuPMgaZO+1mAqyOlnyxazVfY /tgw== 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=DLqJJounhdfcftV6O9nHbeZhACqsm8NU7fqVE2mEU7g=; b=IOB2ovrHyrZ3Xrya7J1KHE/tf8WlIRE5M/NZo0lOM8HCef+wg/6RfshctntkZTF5UE zjKX0bvuRsETBl80ylIQWVskOydSg5ZZLkCrqXGJjoQqKes9MXFpakMCdGZsC5tJSXmd V0iPLwQw2bhX7UScHfGRmJ7Z2/CkkrQJB/5PpEwEuLdyEgRV3v22mPGSs0upfyJUfuRF lbPaR5OfX9XoLGXJdk5aooULcDa/V/08UNiAWvnRP7eVJ4BNstXs3uBrotfsJmlWkFbm iVQR9F27W4js4JzpIaqinw35twS51Vrcvxfggcm7JveTEGCHtbTB3ydJF4vt1nYzT08b 2FEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n3Yz1a8B; 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 gg17si1507805ejb.294.2019.10.03.10.13.26; Thu, 03 Oct 2019 10:13:50 -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=n3Yz1a8B; 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 S2403799AbfJCQbC (ORCPT + 99 others); Thu, 3 Oct 2019 12:31:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:37568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403790AbfJCQbA (ORCPT ); Thu, 3 Oct 2019 12:31:00 -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 9ADF12054F; Thu, 3 Oct 2019 16:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570120260; bh=jFyrjGVt0cRFDQk6Fgliyx+XUAerjBChFSMocGjBCxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3Yz1a8BZiugnHDVZHE0rszeDztU33YLZXM/oXP1CAe1AF4GSR3i0nC08Pr5FIzKl FdYJR3zsIuilOCb3matsxXapsEhu1YhdA9EkrZjvkbGZ06R56FqCSgQHxq8PRyk7eh WqdkS90kzLJshF+8AE0miV5F+k7Vma1g63Uapu8k= 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 5.2 155/313] arm64: kpti: ensure patched kernel text is fetched from PoU Date: Thu, 3 Oct 2019 17:52:13 +0200 Message-Id: <20191003154548.190098694@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154533.590915454@linuxfoundation.org> References: <20191003154533.590915454@linuxfoundation.org> User-Agent: quilt/0.66 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 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(+) diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 7dbf2be470f6c..28a8f7b87ff06 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -286,6 +286,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 -- 2.20.1