Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp18503743ybl; Fri, 3 Jan 2020 03:43:10 -0800 (PST) X-Google-Smtp-Source: APXvYqzj1MxPF7ZPjxpJ/e53lSWXe1l6KT6AuTiww6SFSECNtUt6DxZJkFXJsCuLUxLSMF1Vf+MH X-Received: by 2002:a05:6830:1149:: with SMTP id x9mr100076109otq.156.1578051790442; Fri, 03 Jan 2020 03:43:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578051790; cv=none; d=google.com; s=arc-20160816; b=AzoIVClttrwPb50KcE2Ezzoqlrb+GQl2CnSdk4h7b2XXkwHPhiQfhhn9xICLeYMrnn JL05t4Zxc+jMigFi9cUPDPi5NbUxLua0zJ/iYopqJWgsq+ClhqGsau/TFUsWNVTGoRjm XPxGQ9XWI8Xiw1OL6lMuN4Fv6Oh7WdBRIWGqu15VT9LodcaPgKYuTnk+ghBFvXE4jrTm LtM13xye1eDfjZySrV74s+9WNtSquCEDcTNtqbJ6t/0AHi3kf3iZs4iGZKoC3ZTabGfp xF4b13bnSQb+xPH67JU2RnJ6sAWlFkQLmDdJuJwcfRVsEzdLWiY8KpOxoHf7IsJhQ/uZ 5M/A== 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=FWE1vriBFA4IYiDlwiHpf55UNrxbeZqs6boKCxWYFLsZVFFrPXRmAZYArSnj/0t9EQ NBeDgkY2vNJlVNwQ9bfZZfOtnK/rA8kpH7wovMIKS8A7LANCj9Rq7favnCBh8yJI+2WM CmwyQ1iFTznYeLcG0tIXg8RQEx7O/fVuKeSrHDCLSXuPVxqACtkfxrAUzTtgpbSF9jsU sDlccfmXTtKIHjeh/j0wB03skwOq0tCcnSa/BLpYT2d5BDXGCTwrM7JkP0lTqevY2rGh dWc8rV2HxDwpG2jUWuVmyr/U3A9bvzoWYBnJ8N0nARjAcoqBydI7VBN8VYdcqYXJfuGq THDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Bn/D8Mff"; 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 e190si17692123oib.113.2020.01.03.03.42.58; Fri, 03 Jan 2020 03:43:10 -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="Bn/D8Mff"; 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 S1727918AbgACLk6 (ORCPT + 99 others); Fri, 3 Jan 2020 06:40:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:40902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727890AbgACLk4 (ORCPT ); Fri, 3 Jan 2020 06:40:56 -0500 Received: from localhost.localdomain (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 AF79824653; Fri, 3 Jan 2020 11:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578051655; bh=f7ymohb97S6b58KJNRXy0ZTCMS6AMDRFCM6vKzcZbSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bn/D8MffaovgfJrEgBR2/9qNzhjo27d/6t/OQ9z/zdLOm7PGiphRgUkP6ofpL0ZVd ZyL8zKpKiJnh0xix0u+tOhxRAtnrlPAPFiU4tyDIfEMacQZnJGcSIXyzMFMMCHU+dD 7TA9cBVdwd0ZyGgfaWcC8Zov07IJBQS2fq9Xf38A= From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , Ard Biesheuvel , linux-kernel@vger.kernel.org, Andy Lutomirski , Arvind Sankar , Matthew Garrett Subject: [PATCH 19/20] efi/x86: don't map the entire kernel text RW for mixed mode Date: Fri, 3 Jan 2020 12:39:52 +0100 Message-Id: <20200103113953.9571-20-ardb@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200103113953.9571-1-ardb@kernel.org> References: <20200103113953.9571-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