Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4195635ybl; Mon, 13 Jan 2020 09:25:45 -0800 (PST) X-Google-Smtp-Source: APXvYqx0Vv0Bb3EVlZDQaP9BFORQ6A+yvvahxm/d6jxBVaiyVdUEexsRwan3JpRchngXqNJfH+R6 X-Received: by 2002:aca:72d0:: with SMTP id p199mr14299827oic.40.1578936345604; Mon, 13 Jan 2020 09:25:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578936345; cv=none; d=google.com; s=arc-20160816; b=YK1nA7kfSzqZrI3oKgoH9zUbSV4Gny4/kPruSBqA+sZ/aDOS/nwEQlv5HNcDY2dtmy /DDxG6P9gH3FbRxWRANNZ9CkE1zbXGf4YNXVfm3IWz2vY1GFANXTCQFC5SH44uf7EkXP DbW+2TAC0VHYb4bwasL3ZzdVzcVLy1/CAQJOqAdYbfpWeHG+9PcDI5KR2wrssBXT4sKc jEUCaR1EQuTQbM652rjYbJ3cH/mLKBX2tarHuAG/UgQz2qOxBOiDe6mXlryFKTX4Ranq +MNC0CF1BIJ9+Y7+5qkTigVpyLr5oBGrT7mByNZ5L7hnaTvBOA70GP5+go9WkfLQLrIs dniw== 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=iUlqXF5qeP7l1qY0oc0AKlBcABsG/ELc4b4ByPW7di8=; b=qv3DAAysABhDrQ1KIZ+izzPnz0rB9AJatZIXWkRPzdSQsMUkk5Ro2x5oV0otjKd6mu 7TNOonvQrARAl18KTrFNSg7FFLq6CC1r6Flspn+ZLsC/Gd0s0AFa3Vhgz+kIx4PffE3y 04BBaM3S2cWkGkS+sC0/IgJ/4st86aq7PK4/SF6WzGIdHj1mlNLBsAiUD5Y/TK4wmBAD x+JLqV+zexSUBcT2ikt4XqEdHrYnBK0khp7h2BQfC1Qs++BeKzxArpaQmhehDzzc1Lvh hX0YaxpAM84wlaf8FFEpl3qvkMfxc3bVrdFO716LS0Mxe2eVkYW+c5rb8/dZm5vd3RPZ UWdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z2fLnfDj; 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 z2si5861810oix.100.2020.01.13.09.25.33; Mon, 13 Jan 2020 09:25:45 -0800 (PST) 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=z2fLnfDj; 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 S1729030AbgAMRYB (ORCPT + 99 others); Mon, 13 Jan 2020 12:24:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:41764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728850AbgAMRXS (ORCPT ); Mon, 13 Jan 2020 12:23:18 -0500 Received: from dogfood.home (amontpellier-657-1-18-247.w109-210.abo.wanadoo.fr [109.210.65.247]) (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 10C43206DA; Mon, 13 Jan 2020 17:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578936197; bh=f7ymohb97S6b58KJNRXy0ZTCMS6AMDRFCM6vKzcZbSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z2fLnfDjeLLXm+R00A0QgLFKw1e9CTcm2vmKN1TxwkXfNKHwDPibnlyE1BTgJF1rm IPl0O6ezRM94ccQvwNGFbeO6CcVDzVea5DCRo9a2RWXrjSNMDKh8NFWx26iCweqxm/ 3WZFHeKW88kbnS2nKpTEc7N8hseF+VEHS+UA0EOk= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Anshuman Khandual , Arnd Bergmann , Dan Williams , Dave Young , Saravana Kannan Subject: [PATCH 05/13] efi/x86: don't map the entire kernel text RW for mixed mode Date: Mon, 13 Jan 2020 18:22:37 +0100 Message-Id: <20200113172245.27925-6-ardb@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200113172245.27925-1-ardb@kernel.org> References: <20200113172245.27925-1-ardb@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The mixed mode thunking routine requires a part of it to be mapped 1:1, and for this reason, we currently map the entire kernel .text read/write in the EFI page tables, which is bad. In fact, the kernel_map_pages_in_pgd() invocation that installs this mapping is entirely redundant, since all of DRAM is already 1:1 mapped read/write in the EFI page tables when we reach this point, which means that .rodata is mapped read-write as well. So let's remap both .text and .rodata read-only in the EFI page tables. Signed-off-by: Ard Biesheuvel --- arch/x86/platform/efi/efi_64.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c index c13fa2150976..6ec58ff60b56 100644 --- a/arch/x86/platform/efi/efi_64.c +++ b/arch/x86/platform/efi/efi_64.c @@ -391,11 +391,11 @@ int __init efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages) efi_scratch.phys_stack = page_to_phys(page + 1); /* stack grows down */ - npages = (_etext - _text) >> PAGE_SHIFT; + npages = (__end_rodata_aligned - _text) >> PAGE_SHIFT; text = __pa(_text); pfn = text >> PAGE_SHIFT; - pf = _PAGE_RW | _PAGE_ENC; + pf = _PAGE_ENC; if (kernel_map_pages_in_pgd(pgd, pfn, text, npages, pf)) { pr_err("Failed to map kernel text 1:1\n"); return 1; -- 2.20.1