Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp3188320ybj; Mon, 23 Sep 2019 16:35:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoOe3Tg0CXXlqXizrzPmUpVcZGJY2BppRwKjwGluE1jKtKQBLu9TkD44dgVjl19JdU7zDj X-Received: by 2002:a17:906:d92c:: with SMTP id rn12mr55065ejb.16.1569281704661; Mon, 23 Sep 2019 16:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569281704; cv=none; d=google.com; s=arc-20160816; b=zhOMWWHsM/ISUiu09UZJO617/+a2jVymg0086per/Aj5SETLV8a6Bk7IgdDV9VUkBA ilM1Wvhs8vE+joS8LdPkd0NkYvrwAsEtihfVbSwjmR8WTpwhezZ8qDlhUTZ3l+1+v4lA ISOuQfa4gSCIKP8NDxP9NPNibcyP04U9I180qnGXkciVLsxQzrLSEZU6C6Q4uH0icktl oCu4tuGg9c0Nwx71+Boj9SxoOBgMLPckYsd857QyUrM4DmTrjAiqDNXOeurrmU2NRu7G pGwGFw37gMFKUDaX6FcdR4LLGyV0vWCrpDFJtGsJhu0lbOSafnxIViXrTj0TzrrXNWeJ cG0w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DLqJJounhdfcftV6O9nHbeZhACqsm8NU7fqVE2mEU7g=; b=NG2vaWdcN9UqWi+bVR7/N3oYCjp5ctpF3j4M57g4pOOT5GicOS5Ijp6WEJ9Z4tyY/b dZPLlrIerKKPaTOBuLl1mz/G6iMFAVTEO9RcRH2/X8elq1kLpIhVL2BJ4J0BPQEUh1cj 0EQRCE7LrQ9si4n+o4//70eHn8WuuR3OmnGbQh13p/abUoGpeYX0gOPhw6hhuvEzYPvo xtJCtg+L7dywQm9uYVsD0U0ckrRBBDqz5NBpHFHKmVogNL1aVjvPHHgPSVs6hlYTYvj7 wkn0rgWraOM+4U6KtR6CeyT6sTEILr/fvRyzCiH3Qi2RnM0eWCPSbWsKZRdonYEgwmk3 eUfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=osuxO+4F; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gz11si5713334ejb.341.2019.09.23.16.34.40; Mon, 23 Sep 2019 16:35:04 -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=osuxO+4F; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391178AbfIVSrt (ORCPT + 99 others); Sun, 22 Sep 2019 14:47:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:44216 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391123AbfIVSrn (ORCPT ); Sun, 22 Sep 2019 14:47:43 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 964D22186A; Sun, 22 Sep 2019 18:47:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569178063; bh=jFyrjGVt0cRFDQk6Fgliyx+XUAerjBChFSMocGjBCxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=osuxO+4FQ6DNhM/5lZg483VA4b36sz3M6NQ5VJBMXuT4kN4UI9TFNS0HZSd+i/CTq qsxY4VAjUdboO6Vg+UXRSWRRyhBCbmCRbmUlNYL5/F0q4z1XriDHcqLfDGaWOCHW4L W2TmY3AQruLfBFb4Fd69XXJqV2A5J5PsAaGhGFLg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mark Rutland , Catalin Marinas , James Morse , Will Deacon , Sasha Levin Subject: [PATCH AUTOSEL 5.3 138/203] arm64: kpti: ensure patched kernel text is fetched from PoU Date: Sun, 22 Sep 2019 14:42:44 -0400 Message-Id: <20190922184350.30563-138-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190922184350.30563-1-sashal@kernel.org> References: <20190922184350.30563-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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