linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
To: Ingo Molnar <mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: Matt Fleming
	<matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>,
	Thomas Gleixner <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
	"H. Peter Anvin" <hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>,
	Matt Fleming
	<matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
	"linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	"Lee, Chun-Yi" <jlee-IBi9RG/b67k@public.gmane.org>,
	Borislav Petkov <bp-l3A5Bk7waGM@public.gmane.org>,
	Leif Lindholm
	<leif.lindholm-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
	Peter Jones <pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	James Bottomley <JBottomley-wo1vFcy6AUs@public.gmane.org>,
	Matthew Garrett <mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>,
	Dave Young <dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	"stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
	<stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Linus Torvalds
	<torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	Borislav Petkov <bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org>,
	Andy Lutomirski <luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Denys Vlasenko <dvlasenk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Brian Gerst <brgerst-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>
Subject: Re: [PATCH 1/2] x86/efi: Map EFI memmap entries in-order at runtime
Date: Fri, 25 Sep 2015 23:44:18 -0700	[thread overview]
Message-ID: <CAKv+Gu_C-QxtMmpDsNtbFTqR+4X4bZ08L5+vNK8zsexUjvcvXg@mail.gmail.com> (raw)
In-Reply-To: <20150926055643.GA25877-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

On 25 September 2015 at 22:56, Ingo Molnar <mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> wrote:
>
> So this commit worries me.
>
> This bug is a good find, and the fix is obviously needed and urgent, but I'm not
> sure about the implementation at all. (I've Cc:-ed a few more x86 low level
> gents.)
>
> * Matt Fleming <matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org> wrote:
>
>>  /*
>> + * Iterate the EFI memory map in reverse order because the regions
>> + * will be mapped top-down. The end result is the same as if we had
>> + * mapped things forward, but doesn't require us to change the
>> + * existing implementation of efi_map_region().
>> + */
>> +static inline void *efi_map_next_entry_reverse(void *entry)
>> +{
>> +     /* Initial call */
>> +     if (!entry)
>> +             return memmap.map_end - memmap.desc_size;
>> +
>> +     entry -= memmap.desc_size;
>> +     if (entry < memmap.map)
>> +             return NULL;
>> +
>> +     return entry;
>> +}
>> +
>> +/*
>> + * efi_map_next_entry - Return the next EFI memory map descriptor
>> + * @entry: Previous EFI memory map descriptor
>> + *
>> + * This is a helper function to iterate over the EFI memory map, which
>> + * we do in different orders depending on the current configuration.
>> + *
>> + * To begin traversing the memory map @entry must be %NULL.
>> + *
>> + * Returns %NULL when we reach the end of the memory map.
>> + */
>> +static void *efi_map_next_entry(void *entry)
>> +{
>> +     if (!efi_enabled(EFI_OLD_MEMMAP) && efi_enabled(EFI_64BIT)) {
>> +             /*
>> +              * Starting in UEFI v2.5 the EFI_PROPERTIES_TABLE
>> +              * config table feature requires us to map all entries
>> +              * in the same order as they appear in the EFI memory
>> +              * map. That is to say, entry N must have a lower
>> +              * virtual address than entry N+1. This is because the
>> +              * firmware toolchain leaves relative references in
>> +              * the code/data sections, which are split and become
>> +              * separate EFI memory regions. Mapping things
>> +              * out-of-order leads to the firmware accessing
>> +              * unmapped addresses.
>> +              *
>> +              * Since we need to map things this way whether or not
>> +              * the kernel actually makes use of
>> +              * EFI_PROPERTIES_TABLE, let's just switch to this
>> +              * scheme by default for 64-bit.
>
> The thing is, if relative accesses between these 'sections' do happen then the
> requirement is much stronger than just 'ordered by addresses' - then we must map
> them continuously and as a single block!
>

The primary difference between pre-2.5 and 2.5 with this feature
enabled is that formerly, each PE/COFF image in memory would be
covered by at most a single EfiRuntimeServicesCode region, and now, a
single PE/COFF image may be split into different regions. It is only
relative references *inside* such a PE/COFF image that we are
concerned about, since no symbol references exist between separate
ones.

Also, it is not only relative references inside the PE/COFF image that
cause the problem. Another aspect is that the offset that is applied
to all absolute references at relocation time is derived from the
offset of the base of the PE/COFF image. If part of the PE/COFF image
(the .data section) is moved relatively to the code section, these
absolute references are fixed up incorrectly. This is actually a
problem that we could solve at the firmware side, but since PE/COFF
does not really tolerate being split up like that, the correct fix is
to keep all regions belonging to a single PE/COFF image adjacent.
Since we can't tell which those regions are, the next best approach is
to keep all adjacent regions with the EFI_MEMORY_RUNTIME attribute
adjacent in the VA mapping.

-- 
Ard.

  parent reply	other threads:[~2015-09-26  6:44 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-25 22:02 [GIT PULL 0/2] EFI urgent fixes Matt Fleming
2015-09-25 22:02 ` [PATCH 1/2] x86/efi: Map EFI memmap entries in-order at runtime Matt Fleming
     [not found]   ` <1443218539-7610-2-git-send-email-matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2015-09-26  5:56     ` Ingo Molnar
     [not found]       ` <20150926055643.GA25877-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-26  6:44         ` Ard Biesheuvel [this message]
2015-09-26 17:01         ` Andy Lutomirski
2015-09-26 17:20           ` H. Peter Anvin
     [not found]             ` <E40EBF14-FD9E-49C0-A7FB-951958F72F79-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>
2015-09-26 18:15               ` Ard Biesheuvel
2015-09-26 19:49                 ` H. Peter Anvin
2015-09-26 19:57                   ` Matt Fleming
     [not found]                     ` <20150926195755.GC3144-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2015-09-26 20:09                       ` Ard Biesheuvel
2015-09-26 20:19                         ` H. Peter Anvin
2015-09-27 16:30                           ` Andy Lutomirski
     [not found]                             ` <CALCETrUA6k-oHzuWA54VzEA1v63b5--JPCCuBoOxLisOtjUn+g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-09-27 18:06                               ` Matthew Garrett
     [not found]                                 ` <20150927180633.GA29466-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2015-09-28  6:16                                   ` Ingo Molnar
2015-09-28  6:41                                     ` Matthew Garrett
     [not found]                                       ` <20150928064143.GA7380-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org>
2015-09-29 21:58                                         ` Laszlo Ersek
2015-09-30  9:30                                           ` Ard Biesheuvel
     [not found]                                             ` <CAKv+Gu-enULj-OMRufB3OPSUVueM1843bD1CdFybaAS7xMUKgw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-09-30 16:43                                               ` Andy Lutomirski
2015-09-30 17:24                                                 ` James Bottomley
     [not found]                                     ` <20150928061646.GA21690-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-30  0:54                                       ` H. Peter Anvin
2015-09-26 19:55               ` Matt Fleming
2015-09-27  6:50           ` Ingo Molnar
2015-09-26 13:43       ` Matt Fleming
     [not found]         ` <20150926134329.GA3144-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2015-09-27  7:03           ` Ingo Molnar
2015-09-28  6:49             ` Ard Biesheuvel
     [not found]               ` <CAKv+Gu8M2pmzfeA=NT4c44E6-PQvRKHZjEJt78mryGcp6bBD8w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-09-28  8:22                 ` Ingo Molnar
     [not found]                   ` <20150928082245.GA28796-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-28  9:51                     ` Ard Biesheuvel
2015-09-29  9:12                       ` Ingo Molnar
2015-09-29 10:41                         ` Ard Biesheuvel
     [not found]                           ` <CAKv+Gu8GpaHRL8EZxJCs8dw8ngFVoYNP1Q=hqhZ=LOF+3vXPLw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-09-29 14:18                             ` Matt Fleming
     [not found]                         ` <20150929091230.GA2023-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-29 13:52                           ` Matt Fleming
2015-09-25 22:02 ` [PATCH 2/2] arm64/efi: Don't pad between EFI_MEMORY_RUNTIME regions Matt Fleming
     [not found]   ` <1443218539-7610-3-git-send-email-matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2015-09-26  6:01     ` Ingo Molnar
     [not found]       ` <20150926060159.GB25877-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-26  7:08         ` Ard Biesheuvel
     [not found]           ` <CAKv+Gu_JRCmx5qKq7SDDq73BegVs3LKZwe+OdvTKb4YD_CURyw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-09-27  7:06             ` Ingo Molnar
2015-09-27 10:40               ` Borislav Petkov
2015-09-28  6:20                 ` Ingo Molnar
2015-09-29  9:31                 ` Dave Young
2015-09-29 10:24                   ` Borislav Petkov
     [not found]                 ` <20150927104014.GA7631-fF5Pk5pvG8Y@public.gmane.org>
2015-09-29 14:36                   ` Matt Fleming
     [not found]                     ` <20150929143612.GC4401-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2015-09-30  0:56                       ` H. Peter Anvin
     [not found]                         ` <560B3327.9020801-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org>
2015-09-30  8:33                           ` Borislav Petkov
2015-09-30  1:03               ` H. Peter Anvin
2015-09-30  1:16                 ` Andy Lutomirski
2015-09-30  1:19                   ` H. Peter Anvin
     [not found]                   ` <CALCETrVvwxZN95swaUDG2fkz9brWV3BQkfMDtLJXZkTRpe8nRg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-09-30  4:24                     ` Ard Biesheuvel
2015-10-01 10:44                 ` Ingo Molnar

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=CAKv+Gu_C-QxtMmpDsNtbFTqR+4X4bZ08L5+vNK8zsexUjvcvXg@mail.gmail.com \
    --to=ard.biesheuvel-qsej5fyqhm4dnm+yrofe0a@public.gmane.org \
    --cc=JBottomley-wo1vFcy6AUs@public.gmane.org \
    --cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
    --cc=bp-Gina5bIWoIWzQB+pC5nmwQ@public.gmane.org \
    --cc=bp-l3A5Bk7waGM@public.gmane.org \
    --cc=brgerst-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=dvlasenk-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=dyoung-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=hpa-YMNOUZJC4hwAvxtiuMwx3w@public.gmane.org \
    --cc=jlee-IBi9RG/b67k@public.gmane.org \
    --cc=leif.lindholm-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-efi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=luto-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=matt-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org \
    --cc=matt.fleming-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=mjg59-1xO5oi07KQx4cg9Nei1l7Q@public.gmane.org \
    --cc=pjones-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
    --cc=torvalds-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@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 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).