From patchwork Mon Feb 22 14:25:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 62582 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1281192lbl; Mon, 22 Feb 2016 06:48:15 -0800 (PST) X-Received: by 10.66.150.170 with SMTP id uj10mr38209961pab.91.1456152494937; Mon, 22 Feb 2016 06:48:14 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id 134si40202797pfa.156.2016.02.22.06.48.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Feb 2016 06:48:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aXrlT-0006iV-IF; Mon, 22 Feb 2016 14:47:07 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aXrRc-0000Oj-IZ for linux-arm-kernel@lists.infradead.org; Mon, 22 Feb 2016 14:26:57 +0000 Received: by mail-wm0-x231.google.com with SMTP id a4so165144149wme.1 for ; Mon, 22 Feb 2016 06:26:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZXq4jsUdW8cVqAk7cvz9tSlsXEQYnwwu0aXRuQduAf4=; b=IWpQoIu0OSF2iiH5NqCQOl9FMXNoR2Y4LqfGcSoM4SLQa6usLPyGY9Eq8ypn0mZ0TB 1EtpPeAfS2X0YpcHFTc/qNIM+YMfV5VahrSB2eN74CWAosgbRre6AmyJQIHJhkRAaiol vs9HuiFnSftjBAfIH82Pqe2hgOyscveT1r18E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZXq4jsUdW8cVqAk7cvz9tSlsXEQYnwwu0aXRuQduAf4=; b=WzMzos+JuG6Mk/bmA8BffqiQY5RPxOxQWFF7VdvuKZyRE8+cGLWdrX3sjqWXyb8Oac xmc6PnVdCNLQTlIQ+mbOTYzmGPyDah7F2VUgReyCSN9R9fz6YEYW+TUxmpOOfnH9ytIa IOe7nP3yrk5Jw/WV42c9Sf9Bdb8QGgQI5o+iMLGfdWtevP5ba7QPPOWOU9KfDGU6IV9y kbTIWCQrSXYwOMhaqEgOSiNk/VNlJPOuTMUm6bH/cultLNz+E62hOJa0YLY0OvIjFv35 LPzbMhaiMinV23Ew9kjwFsTHGopuU94yk6WpwEo0dMvmonMPzQNq2mv/PHXxagT8ffW8 +fOw== X-Gm-Message-State: AG10YOSEbRRJpDgRNyfeEoIkY/RKbbNTZOnxwPqEj4vwVgrRdTGY0d3s5N0CzwwvRZZCFZec X-Received: by 10.28.184.78 with SMTP id i75mr13190033wmf.22.1456151174778; Mon, 22 Feb 2016 06:26:14 -0800 (PST) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id p125sm21377983wmd.16.2016.02.22.06.26.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 06:26:14 -0800 (PST) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, matt@codeblueprint.co.uk, sai.praneeth.prakhya@intel.com Subject: [PATCH 2/5] arm64: efi: apply strict permissons for UEFI Runtime Services regions Date: Mon, 22 Feb 2016 15:25:55 +0100 Message-Id: <1456151158-25849-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456151158-25849-1-git-send-email-ard.biesheuvel@linaro.org> References: <1456151158-25849-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160222_062637_495279_AAE1FDB0 X-CRM114-Status: GOOD ( 16.59 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:231 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, pjones@redhat.com, linux@arm.linux.org.uk, leif.lindholm@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Recent UEFI versions expose permission attributes for runtime services memory regions, either in the UEFI memory map or in the separate memory attributes table. This allows the kernel to map these regions with stricter permissions, rather than the RWX permissions that are used by default. So wire this up in our mapping routine. Note that in the absence of permission attributes, we still only map regions of type EFI_RUNTIME_SERVICE_CODE with the executable bit set. Also, we base the mapping attributes of EFI_MEMORY_MAPPED_IO on the type directly rather than on the absence of the EFI_MEMORY_WB attribute. This is more correct, but is also required for compatibility with the upcoming support for the Memory Attributes Table, which only carries permission attributes, not memory type attributes. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi.c | 27 ++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) -- 2.5.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c index b6abc852f2a1..3364408c154f 100644 --- a/arch/arm64/kernel/efi.c +++ b/arch/arm64/kernel/efi.c @@ -24,15 +24,32 @@ int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t *md) /* * Only regions of type EFI_RUNTIME_SERVICES_CODE need to be * executable, everything else can be mapped with the XN bits - * set. + * set. Also take the new (optional) RO/XP bits into account. */ - if ((md->attribute & EFI_MEMORY_WB) == 0) + if (md->type == EFI_MEMORY_MAPPED_IO) prot_val = PROT_DEVICE_nGnRE; - else if (md->type == EFI_RUNTIME_SERVICES_CODE || - !PAGE_ALIGNED(md->phys_addr)) + else if (WARN_ONCE(!PAGE_ALIGNED(md->phys_addr), + "UEFI Runtime regions are not aligned to 64 KB -- buggy firmware?")) + /* + * If the region is not aligned to the page size of the OS, we + * can not use strict permissions, since that would also affect + * the mapping attributes of the adjacent regions. + */ prot_val = pgprot_val(PAGE_KERNEL_EXEC); - else + else if ((md->attribute & (EFI_MEMORY_XP | EFI_MEMORY_RO)) == + (EFI_MEMORY_XP | EFI_MEMORY_RO)) + /* R-- */ + prot_val = pgprot_val(PAGE_KERNEL_RO); + else if (md->attribute & EFI_MEMORY_RO) + /* R-X */ + prot_val = pgprot_val(PAGE_KERNEL_ROX); + else if (md->attribute & EFI_MEMORY_XP || + md->type != EFI_RUNTIME_SERVICES_CODE) + /* RW- */ prot_val = pgprot_val(PAGE_KERNEL); + else + /* RWX */ + prot_val = pgprot_val(PAGE_KERNEL_EXEC); create_pgd_mapping(mm, md->phys_addr, md->virt_addr, md->num_pages << EFI_PAGE_SHIFT,