From patchwork Thu Oct 3 15:53:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 175189 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp639103ill; Thu, 3 Oct 2019 10:36:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSfF1rURmMZbsL90OA/oMEezSQULqsdAj7kMHDRgZFr38UwjvSB6nOHWcxxxTWdN66y8mj X-Received: by 2002:aa7:c5c1:: with SMTP id h1mr10691307eds.10.1570124165637; Thu, 03 Oct 2019 10:36:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570124165; cv=none; d=google.com; s=arc-20160816; b=Mq31XLiHTaivqvqt065SoflazJ2bIj+ikYOBrrC5QjvU2B87P3CCMQnOaYjo9W+aZ0 Sbl+t22b0TfpsFhs+jNoLe1uyqcp0B7SSHwroKpE36Lh5/5e2JHfIJ4ZIhSk3qlM6236 4UZwssGQKI2s2w7Ms3J19k26GQ0Q9P6mJKB8GC3KPGGi9gTck7O7MFLNpT8IXn40gC7K 23wszZD+xKPSYhMOBDmyDQPNEgW7UXDZvn3mtmJ959HVtXrhY1USgpmCxiw1O6+pvwTC ZFf3pIEU3K3dhGVQG/nEyKQM3OpGvaXEE6dS4B7M46l2vNOKDBZm9GK2F6y/84DAZ+c3 F6+g== 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=sl/jv1gP6g3Q0ZNuR9Fr4UM6E+zQsECq8IsVxaU5XrY=; b=Eu7fp7v8ysTOIE1YYAiv3YeEMSbl109cjWDNXld066lEE7AcBgwNGpbFEpzI+E2d48 fJnKFEjDxtTlE08uisCzwTR4bxzT2eyMLRpl/kpJ2j4slUzbM5x99vCq/6fMc6+SLQO/ PIt5etxMZYntIl0n40Ezh74TvVN7fc3xtTrcEBAiCStBx9CvC/fBUlf3FjVCyRI1+POR aRdUc/6BHXQWgmlYqh0uDfEWXCwszNc26pJsHNG66zxMNc9XgY1Zo4xIrjVWAghYfCnU eqknlAi3K9HX8DoUOXjFWy9wju9V67L+fDDdlyA9G1vPf3mhuud5wGekMd3Bdg6S7RUm 4Tsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="x/HkxdFk"; 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 j9si1849172edt.32.2019.10.03.10.36.05; Thu, 03 Oct 2019 10:36:05 -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="x/HkxdFk"; 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 S2388555AbfJCRgD (ORCPT + 27 others); Thu, 3 Oct 2019 13:36:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:51884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732198AbfJCQFT (ORCPT ); Thu, 3 Oct 2019 12:05:19 -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 13A99215EA; Thu, 3 Oct 2019 16:05:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570118718; bh=8LVBhwOe9iKmTrHRY8JxBQfug0KuqOv9YxaYUxIzXu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x/HkxdFkFQ34TC4G88d40M2JcCAqesgXL4QxvstQUYqc6VDf2+FrixZ6Y0c5N8Ak2 Fa1VSPI6AynLy308Qc6MA7Iyb3OfFb3MjV+lWxAxsaFh1dXkrPFg8ynizSVtz16kBy 3LO2M1eSaXX0VzRLd6W7ovabxzAY8/9BQ9QmMvRA= 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.9 076/129] arm64: kpti: ensure patched kernel text is fetched from PoU Date: Thu, 3 Oct 2019 17:53:19 +0200 Message-Id: <20191003154353.011305485@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154318.081116689@linuxfoundation.org> References: <20191003154318.081116689@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 3ceec224d3d24..3b95e3126eebb 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -263,6 +263,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