linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans de Goede <hdegoede@redhat.com>
To: Ard Biesheuvel <ardb@kernel.org>, linux-efi@vger.kernel.org
Cc: Arvind Sankar <nivedita@alum.mit.edu>,
	Andy Lutomirski <luto@amacapital.net>
Subject: Re: [PATCH 1/3] efi/x86: align GUIDs to their size in the mixed mode runtime wrapper
Date: Fri, 14 Feb 2020 13:55:53 +0100	[thread overview]
Message-ID: <116eb62a-8067-b4f1-171a-2659bcaa94bf@redhat.com> (raw)
In-Reply-To: <20200213102102.30170-2-ardb@kernel.org>

Hi,

On 2/13/20 11:21 AM, Ard Biesheuvel wrote:
> The mixed mode runtime wrappers are fragile when it comes to how the
> memory referred to by its pointer arguments are laid out in memory,
> due to the fact that it translates these addresses to physical addresses
> that the runtime services can dereference when running in 1:1 mode.
> 
> As a quick (i.e., backportable) fix, copy GUID pointer arguments to
> the local stack into a buffer that is naturally aligned to its size,
> so that is guaranteed to cover only one physical page.
> 
> Note that on x86, we cannot rely on the stack pointer being aligned
> the way the compiler expects, so we need to allocate an 8-byte aligned
> buffer of sufficient size, and copy the GUID into that buffer at an
> offset that is aligned to 16 bytes.
> 
> Reported-by: Hans de Goede <hdegoede@redhat.com>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

I can confirm that this fixes the WARN_ON triggering I was seeing,
thanks:

Tested-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> ---
>   arch/x86/platform/efi/efi_64.c | 25 ++++++++++++++++----
>   1 file changed, 21 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
> index fa8506e76bbe..543edfdcd1b9 100644
> --- a/arch/x86/platform/efi/efi_64.c
> +++ b/arch/x86/platform/efi/efi_64.c
> @@ -658,6 +658,8 @@ static efi_status_t
>   efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
>   		       u32 *attr, unsigned long *data_size, void *data)
>   {
> +	u8 buf[24] __aligned(8);
> +	efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
>   	efi_status_t status;
>   	u32 phys_name, phys_vendor, phys_attr;
>   	u32 phys_data_size, phys_data;
> @@ -665,8 +667,10 @@ efi_thunk_get_variable(efi_char16_t *name, efi_guid_t *vendor,
>   
>   	spin_lock_irqsave(&efi_runtime_lock, flags);
>   
> +	*vnd = *vendor;
> +
>   	phys_data_size = virt_to_phys_or_null(data_size);
> -	phys_vendor = virt_to_phys_or_null(vendor);
> +	phys_vendor = virt_to_phys_or_null(vnd);
>   	phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
>   	phys_attr = virt_to_phys_or_null(attr);
>   	phys_data = virt_to_phys_or_null_size(data, *data_size);
> @@ -683,14 +687,18 @@ static efi_status_t
>   efi_thunk_set_variable(efi_char16_t *name, efi_guid_t *vendor,
>   		       u32 attr, unsigned long data_size, void *data)
>   {
> +	u8 buf[24] __aligned(8);
> +	efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
>   	u32 phys_name, phys_vendor, phys_data;
>   	efi_status_t status;
>   	unsigned long flags;
>   
>   	spin_lock_irqsave(&efi_runtime_lock, flags);
>   
> +	*vnd = *vendor;
> +
>   	phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
> -	phys_vendor = virt_to_phys_or_null(vendor);
> +	phys_vendor = virt_to_phys_or_null(vnd);
>   	phys_data = virt_to_phys_or_null_size(data, data_size);
>   
>   	/* If data_size is > sizeof(u32) we've got problems */
> @@ -707,6 +715,8 @@ efi_thunk_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor,
>   				   u32 attr, unsigned long data_size,
>   				   void *data)
>   {
> +	u8 buf[24] __aligned(8);
> +	efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
>   	u32 phys_name, phys_vendor, phys_data;
>   	efi_status_t status;
>   	unsigned long flags;
> @@ -714,8 +724,10 @@ efi_thunk_set_variable_nonblocking(efi_char16_t *name, efi_guid_t *vendor,
>   	if (!spin_trylock_irqsave(&efi_runtime_lock, flags))
>   		return EFI_NOT_READY;
>   
> +	*vnd = *vendor;
> +
>   	phys_name = virt_to_phys_or_null_size(name, efi_name_size(name));
> -	phys_vendor = virt_to_phys_or_null(vendor);
> +	phys_vendor = virt_to_phys_or_null(vnd);
>   	phys_data = virt_to_phys_or_null_size(data, data_size);
>   
>   	/* If data_size is > sizeof(u32) we've got problems */
> @@ -732,14 +744,18 @@ efi_thunk_get_next_variable(unsigned long *name_size,
>   			    efi_char16_t *name,
>   			    efi_guid_t *vendor)
>   {
> +	u8 buf[24] __aligned(8);
> +	efi_guid_t *vnd = PTR_ALIGN((efi_guid_t *)buf, sizeof(*vnd));
>   	efi_status_t status;
>   	u32 phys_name_size, phys_name, phys_vendor;
>   	unsigned long flags;
>   
>   	spin_lock_irqsave(&efi_runtime_lock, flags);
>   
> +	*vnd = *vendor;
> +
>   	phys_name_size = virt_to_phys_or_null(name_size);
> -	phys_vendor = virt_to_phys_or_null(vendor);
> +	phys_vendor = virt_to_phys_or_null(vnd);
>   	phys_name = virt_to_phys_or_null_size(name, *name_size);
>   
>   	status = efi_thunk(get_next_variable, phys_name_size,
> @@ -747,6 +763,7 @@ efi_thunk_get_next_variable(unsigned long *name_size,
>   
>   	spin_unlock_irqrestore(&efi_runtime_lock, flags);
>   
> +	*vendor = *vnd;
>   	return status;
>   }
>   
> 


  reply	other threads:[~2020-02-14 12:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-13 10:20 [PATCH 0/3] efi/x86: Some mixed mode fixes Ard Biesheuvel
2020-02-13 10:21 ` [PATCH 1/3] efi/x86: align GUIDs to their size in the mixed mode runtime wrapper Ard Biesheuvel
2020-02-14 12:55   ` Hans de Goede [this message]
2020-02-14 13:35     ` Ard Biesheuvel
2020-02-13 10:21 ` [PATCH 2/3] efi/x86: remove support for EFI time and counter services in mixed mode Ard Biesheuvel
2020-02-13 10:21 ` [PATCH 3/3] efi/x86: Handle by-ref arguments covering multiple pages " 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=116eb62a-8067-b4f1-171a-2659bcaa94bf@redhat.com \
    --to=hdegoede@redhat.com \
    --cc=ardb@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=nivedita@alum.mit.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).