From: Shanker Donthineni <shankerd-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
To: Ard Biesheuvel
<ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org,
mark.rutland-5wv7dgnIgG8@public.gmane.org,
linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org
Cc: catalin.marinas-5wv7dgnIgG8@public.gmane.org,
will.deacon-5wv7dgnIgG8@public.gmane.org,
leif.lindholm-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
sai.praneeth.prakhya-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH v2 2/5] arm64: efi: apply strict permissons for UEFI Runtime Services regions
Date: Tue, 17 May 2016 19:40:30 -0500 [thread overview]
Message-ID: <573BB9FE.7050008@codeaurora.org> (raw)
In-Reply-To: <1459355933-13529-3-git-send-email-ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Hi Ard,
This patch causing the kernel boot fail using the UEFI firmware on
Qualcomm Technologies QDF2XXX server platforms.
+ /* RW- */
+ if (attr & EFI_MEMORY_XP || type != EFI_RUNTIME_SERVICES_CODE)
+ return pgprot_val(PAGE_KERNEL);
+
Changing above condition from 'or' to 'and' fixed the problem.Are we
missing something here or intentionally implemented this logic? At least
we need some pr_warn here if UEFI firmware passes EFI_RUNTIME_SEVRICE_CODE
region that has an attribute EFI_MEMORY_XP.
On 03/30/2016 11:38 AM, Ard Biesheuvel wrote:
> 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.
>
> Cc: Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
> ---
> arch/arm64/kernel/efi.c | 54 +++++++++++++++-----
> 1 file changed, 40 insertions(+), 14 deletions(-)
>
> diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
> index b6abc852f2a1..33a6da160a50 100644
> --- a/arch/arm64/kernel/efi.c
> +++ b/arch/arm64/kernel/efi.c
> @@ -17,22 +17,48 @@
>
> #include <asm/efi.h>
>
> -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. Also take the new (optional) RO/XP bits into account.
> + */
> +static __init pteval_t create_mapping_protection(efi_memory_desc_t *md)
> {
> - pteval_t prot_val;
> + u64 attr = md->attribute;
> + u32 type = md->type;
>
> - /*
> - * Only regions of type EFI_RUNTIME_SERVICES_CODE need to be
> - * executable, everything else can be mapped with the XN bits
> - * set.
> - */
> - if ((md->attribute & EFI_MEMORY_WB) == 0)
> - prot_val = PROT_DEVICE_nGnRE;
> - else if (md->type == EFI_RUNTIME_SERVICES_CODE ||
> - !PAGE_ALIGNED(md->phys_addr))
> - prot_val = pgprot_val(PAGE_KERNEL_EXEC);
> - else
> - prot_val = pgprot_val(PAGE_KERNEL);
> + if (type == EFI_MEMORY_MAPPED_IO)
> + return PROT_DEVICE_nGnRE;
> +
> + 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.
> + */
> + return pgprot_val(PAGE_KERNEL_EXEC);
> +
> + /* R-- */
> + if ((attr & (EFI_MEMORY_XP | EFI_MEMORY_RO)) ==
> + (EFI_MEMORY_XP | EFI_MEMORY_RO))
> + return pgprot_val(PAGE_KERNEL_RO);
> +
> + /* R-X */
> + if (attr & EFI_MEMORY_RO)
> + return pgprot_val(PAGE_KERNEL_ROX);
> +
> + /* RW- */
> + if (attr & EFI_MEMORY_XP || type != EFI_RUNTIME_SERVICES_CODE)
> + return pgprot_val(PAGE_KERNEL);
> +
> + /* RWX */
> + return pgprot_val(PAGE_KERNEL_EXEC);
> +}
> +
> +int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t
> *md)
> +{
> + pteval_t prot_val = create_mapping_protection(md);
>
> create_pgd_mapping(mm, md->phys_addr, md->virt_addr,
> md->num_pages << EFI_PAGE_SHIFT,
--
Shanker Donthineni
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
WARNING: multiple messages have this Message-ID (diff)
From: shankerd@codeaurora.org (Shanker Donthineni)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 2/5] arm64: efi: apply strict permissons for UEFI Runtime Services regions
Date: Tue, 17 May 2016 19:40:30 -0500 [thread overview]
Message-ID: <573BB9FE.7050008@codeaurora.org> (raw)
In-Reply-To: <1459355933-13529-3-git-send-email-ard.biesheuvel@linaro.org>
Hi Ard,
This patch causing the kernel boot fail using the UEFI firmware on
Qualcomm Technologies QDF2XXX server platforms.
+ /* RW- */
+ if (attr & EFI_MEMORY_XP || type != EFI_RUNTIME_SERVICES_CODE)
+ return pgprot_val(PAGE_KERNEL);
+
Changing above condition from 'or' to 'and' fixed the problem.Are we
missing something here or intentionally implemented this logic? At least
we need some pr_warn here if UEFI firmware passes EFI_RUNTIME_SEVRICE_CODE
region that has an attribute EFI_MEMORY_XP.
On 03/30/2016 11:38 AM, Ard Biesheuvel wrote:
> 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.
>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> arch/arm64/kernel/efi.c | 54 +++++++++++++++-----
> 1 file changed, 40 insertions(+), 14 deletions(-)
>
> diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
> index b6abc852f2a1..33a6da160a50 100644
> --- a/arch/arm64/kernel/efi.c
> +++ b/arch/arm64/kernel/efi.c
> @@ -17,22 +17,48 @@
>
> #include <asm/efi.h>
>
> -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. Also take the new (optional) RO/XP bits into account.
> + */
> +static __init pteval_t create_mapping_protection(efi_memory_desc_t *md)
> {
> - pteval_t prot_val;
> + u64 attr = md->attribute;
> + u32 type = md->type;
>
> - /*
> - * Only regions of type EFI_RUNTIME_SERVICES_CODE need to be
> - * executable, everything else can be mapped with the XN bits
> - * set.
> - */
> - if ((md->attribute & EFI_MEMORY_WB) == 0)
> - prot_val = PROT_DEVICE_nGnRE;
> - else if (md->type == EFI_RUNTIME_SERVICES_CODE ||
> - !PAGE_ALIGNED(md->phys_addr))
> - prot_val = pgprot_val(PAGE_KERNEL_EXEC);
> - else
> - prot_val = pgprot_val(PAGE_KERNEL);
> + if (type == EFI_MEMORY_MAPPED_IO)
> + return PROT_DEVICE_nGnRE;
> +
> + 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.
> + */
> + return pgprot_val(PAGE_KERNEL_EXEC);
> +
> + /* R-- */
> + if ((attr & (EFI_MEMORY_XP | EFI_MEMORY_RO)) ==
> + (EFI_MEMORY_XP | EFI_MEMORY_RO))
> + return pgprot_val(PAGE_KERNEL_RO);
> +
> + /* R-X */
> + if (attr & EFI_MEMORY_RO)
> + return pgprot_val(PAGE_KERNEL_ROX);
> +
> + /* RW- */
> + if (attr & EFI_MEMORY_XP || type != EFI_RUNTIME_SERVICES_CODE)
> + return pgprot_val(PAGE_KERNEL);
> +
> + /* RWX */
> + return pgprot_val(PAGE_KERNEL_EXEC);
> +}
> +
> +int __init efi_create_mapping(struct mm_struct *mm, efi_memory_desc_t
> *md)
> +{
> + pteval_t prot_val = create_mapping_protection(md);
>
> create_pgd_mapping(mm, md->phys_addr, md->virt_addr,
> md->num_pages << EFI_PAGE_SHIFT,
--
Shanker Donthineni
Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
next prev parent reply other threads:[~2016-05-18 0:40 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-30 16:38 [PATCH v2 0/5] UEFI: memory attribute table support Ard Biesheuvel
2016-03-30 16:38 ` Ard Biesheuvel
[not found] ` <1459355933-13529-1-git-send-email-ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-03-30 16:38 ` [PATCH v2 1/5] ARM: efi: apply strict permissons for UEFI Runtime Services regions Ard Biesheuvel
2016-03-30 16:38 ` Ard Biesheuvel
2016-03-30 16:38 ` [PATCH v2 2/5] arm64: " Ard Biesheuvel
2016-03-30 16:38 ` Ard Biesheuvel
[not found] ` <1459355933-13529-3-git-send-email-ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-05-18 0:40 ` Shanker Donthineni [this message]
2016-05-18 0:40 ` Shanker Donthineni
[not found] ` <573BB9FE.7050008-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-05-18 6:18 ` Ard Biesheuvel
2016-05-18 6:18 ` Ard Biesheuvel
[not found] ` <CAKv+Gu-Tam+QiXc_f0e+x8hNc4rxP_-59NdaCHkF9h=4Rd+XeA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-05-18 13:06 ` Shanker Donthineni
2016-05-18 13:06 ` Shanker Donthineni
[not found] ` <573C68DA.8080009-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-05-18 13:08 ` Ard Biesheuvel
2016-05-18 13:08 ` Ard Biesheuvel
2016-03-30 16:38 ` [PATCH v2 3/5] efi: add support for the EFI_MEMORY_ATTRIBUTES_TABLE config table Ard Biesheuvel
2016-03-30 16:38 ` Ard Biesheuvel
2016-03-30 16:38 ` [PATCH v2 4/5] efi: implement generic support for the Memory Attributes table Ard Biesheuvel
2016-03-30 16:38 ` Ard Biesheuvel
[not found] ` <1459355933-13529-5-git-send-email-ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2016-04-01 12:36 ` Ard Biesheuvel
2016-04-01 12:36 ` Ard Biesheuvel
2016-04-08 15:56 ` Matt Fleming
2016-04-08 15:56 ` Matt Fleming
[not found] ` <20160408155608.GQ2701-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-04-11 14:09 ` Ard Biesheuvel
2016-04-11 14:09 ` Ard Biesheuvel
[not found] ` <CAKv+Gu-TMb0MTnzXXjczvxaWvZphu7M1-MMdjCrZ7A2CvCc2WQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-12 19:57 ` Matt Fleming
2016-04-12 19:57 ` Matt Fleming
[not found] ` <20160412195727.GG2829-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-04-13 8:29 ` Ard Biesheuvel
2016-04-13 8:29 ` Ard Biesheuvel
[not found] ` <CAKv+Gu-bLN16YKei3togReQBNo+ScQVf7ek2NJEZAEyii2JEcw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-13 10:24 ` Matt Fleming
2016-04-13 10:24 ` Matt Fleming
[not found] ` <20160413102408.GL2829-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-04-13 10:24 ` Ard Biesheuvel
2016-04-13 10:24 ` Ard Biesheuvel
2016-03-30 16:38 ` [PATCH v2 5/5] arm*: efi: take the Memory Attributes table into account Ard Biesheuvel
2016-03-30 16:38 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=573BB9FE.7050008@codeaurora.org \
--to=shankerd-sgv2jx0feol9jmxxk+q4oq@public.gmane.org \
--cc=ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=catalin.marinas-5wv7dgnIgG8@public.gmane.org \
--cc=leif.lindholm-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org \
--cc=pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=sai.praneeth.prakhya-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.