lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAMj1kXFKrD172-AU_45fd4UHXdxOKfjyy9R=teXxEAr9nFKP6w@mail.gmail.com>
Date:   Thu, 10 Sep 2020 13:03:19 +0300
From:   Ard Biesheuvel <ardb@...nel.org>
To:     Atish Patra <atishp@...shpatra.org>
Cc:     Heinrich Schuchardt <xypron.glpk@....de>,
        Atish Patra <atish.patra@....com>,
        Palmer Dabbelt <palmer@...belt.com>,
        Ingo Molnar <mingo@...nel.org>,
        Arvind Sankar <nivedita@...m.mit.edu>,
        linux-efi <linux-efi@...r.kernel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        Maxim Uvarov <maxim.uvarov@...aro.org>,
        Jens Wiklander <jens.wiklander@...aro.org>
Subject: Re: [PATCH 1/1] efi/libstub: DRAM base calculation

On Wed, 9 Sep 2020 at 23:37, Atish Patra <atishp@...shpatra.org> wrote:
>
> On Wed, Sep 9, 2020 at 1:17 AM Ard Biesheuvel <ardb@...nel.org> wrote:
> >
> > (+ Atish, Palmer)
> >
> > On Fri, 4 Sep 2020 at 18:50, Heinrich Schuchardt <xypron.glpk@....de> wrote:
> > >
> > > In the memory map the regions with the lowest addresses may be of type
> > > EFI_RESERVED_TYPE. The reserved areas may be discontinuous relative to the
> > > rest of the memory. So for calculating the maximum loading address for the
> > > device tree and the initial ramdisk image these reserved areas should not
> > > be taken into account.
> > >
> > > Signed-off-by: Heinrich Schuchardt <xypron.glpk@....de>
> > > ---
> > >  drivers/firmware/efi/libstub/efi-stub.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c
> > > index c2484bf75c5d..13058ac75765 100644
> > > --- a/drivers/firmware/efi/libstub/efi-stub.c
> > > +++ b/drivers/firmware/efi/libstub/efi-stub.c
> > > @@ -106,7 +106,8 @@ static unsigned long get_dram_base(void)
> > >         map.map_end = map.map + map_size;
> > >
> > >         for_each_efi_memory_desc_in_map(&map, md) {
> > > -               if (md->attribute & EFI_MEMORY_WB) {
> > > +               if (md->attribute & EFI_MEMORY_WB &&
> > > +                   md->type != EFI_RESERVED_TYPE) {
> > >                         if (membase > md->phys_addr)
> > >                                 membase = md->phys_addr;
> > >                 }
> > > --
> > > 2.28.0
> > >
> >
> > This is not the right fix - on RPi2, for instance, which has some
> > reserved memory at the base of DRAM, this change will result in the
> > first 16 MB of memory to be wasted.
> >
> > What I would prefer to do is get rid of get_dram_base() entirely -
> > arm64 does not use its return value in the first place, and for ARM,
> > the only reason we need it is so that we can place the uncompressed
> > kernel image as low in memory as possible, and there are probably
> > better ways to do that. RISC-V just started using it too, but only
> > passes it from handle_kernel_image() to efi_relocate_kernel(), and
> > afaict, passing 0x0 there instead would not cause any problems.
>
> Yes. Passing 0x0 to efi_relocate_kernel will result in a failure in
> efi_bs_call and it will fallback to
> efi_low_alloc_above which will try to assign the lowest possible
> available memory with 2MB alignment restriction.
> The only disadvantage is an extra unnecessary call to UEFI firmware
> which should be okay as it is not in the hotpath.
>

The point is really that get_dram_base() does a similar call to
GetMemoryMap() under the hood, so once we remove it, the worst case
still does that once (in efi_low_alloc_above() invoked from
efi_relocate_kernel) whereas the optimal case will no longer call it
at all.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ