Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp86437ybp; Thu, 3 Oct 2019 10:32:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXGatIWUG4PryJ7J31KM9s8YzVuoLsQJx40Pg6ylL+GLx+gT1/J84B22LHYOg3ecVNlbJp X-Received: by 2002:aa7:d803:: with SMTP id v3mr10850041edq.146.1570123952012; Thu, 03 Oct 2019 10:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570123952; cv=none; d=google.com; s=arc-20160816; b=VorBZO4pNcOAmxQp6sYvCqask1XaurTnrWBWJjyW3WRFCFYPsIOBLUdGMKtEDI5bNu 2ZM3lD4aQ+9ECy6HRhHI7lYYolKm1QatBJGTFeJjVHjrVpW0JVsnu3qjk4LA/T64AdSs IKwDSGD6mziQC9kZ5LeHCcWxhDF6wzr6Ibzbu19MPXF7IM/itVenpTAkmPEcvrZZ5K0n it9DItSD3ZPqxX7/n5AL8K5uKW3yNGvyeaq05PvUCNtW3tpenP1iHOxbIW+GxSk7HYo2 HQxh56dxihDhWOaMLmkQhQ/CFOsOYv9Dhs3gZ/TZeMKFBesARJGwRwe5rbF7bJYFtF2L y4qQ== 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=9pUp8RyE+XXL5os/Cu61Mh8Sq3I3VsACfPOYVMs9tZ8=; b=xKaT7gNv3zprZTf/Re08C440UnpIy/beuxGKlcBiRcFQCCyztH/u8FdljIKr/ymBMX iX0gXKjIVOHkEbx7/KdIufR1zU6ehSxvm4qhjbK0nEfOGl6WKXFBNWA4x42DvIEnsgGk Pks3Lgy6ApmeDsPT3dJ1XqyZI5+DgPRfglhPmUml+vU2vxYntRDmwZt9TFiiNkwlGNzp qnhT6B/F1Gpi+3d2I9E6PAYRJr8TnmBHRNHdDpnLxGSL1801nC0uBSbGtVMR6V8aUYCj +kwZ6cPQt8I1H64S9lzp4hJRIeIH5H+b8lWLiBEgaL/wnL7NPTllTpuvM9HXUZSDluNl S3zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LjMnI3+n; 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 c20si1663021ejs.197.2019.10.03.10.32.07; Thu, 03 Oct 2019 10:32:32 -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=LjMnI3+n; 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 S2389511AbfJCQTZ (ORCPT + 99 others); Thu, 3 Oct 2019 12:19:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:46324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387497AbfJCQTV (ORCPT ); Thu, 3 Oct 2019 12:19:21 -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 BD0EB2054F; Thu, 3 Oct 2019 16:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119561; bh=URUZzsuEtvmqgS69CvYyDYYGVRNJ0Jzif+eoUQ1PBvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LjMnI3+nj6LVEp5O7KAsMdqFeFfecUu2MUy9oz5tTd2KfdJpPdlhYcUxub48IE8xd fopLl8IQxUo7FGoZfshKM6OfDVYIMcqw0YX7lLMJhGomsS7OOofjhRAOJZsOpNv8Ji WIM2V0wfe7wvpcsG4il79QXb8Oizf/bzXsLmNKd4= 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.19 109/211] arm64: kpti: ensure patched kernel text is fetched from PoU Date: Thu, 3 Oct 2019 17:52:55 +0200 Message-Id: <20191003154512.244293884@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@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 8cce091b6c21e..ec6aa18633162 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -294,6 +294,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