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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKv+Gu-XAvYf8G+7Oi-XVM+DvR89_zkmETmou-2ftgC41tnvMw@mail.gmail.com>
Date:   Sat, 14 Dec 2019 20:40:57 +0000
From:   Ard Biesheuvel <ard.biesheuvel@...aro.org>
To:     Arvind Sankar <nivedita@...m.mit.edu>
Cc:     Ard Biesheuvel <ardb@...nel.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        linux-efi <linux-efi@...r.kernel.org>,
        Hans de Goede <hdegoede@...hat.com>,
        Matthew Garrett <matthewgarrett@...gle.com>,
        Ingo Molnar <mingo@...nel.org>,
        Andy Lutomirski <luto@...nel.org>,
        Thomas Gleixner <tglx@...utronix.de>
Subject: Re: [PATCH 03/10] efi/libstub: use a helper to iterate over a EFI
 handle array

On Sat, 14 Dec 2019 at 21:33, Arvind Sankar <nivedita@...m.mit.edu> wrote:
>
> On Sat, Dec 14, 2019 at 06:57:28PM +0100, Ard Biesheuvel wrote:
> > Iterating over a EFI handle array is a bit finicky, since we have
> > to take mixed mode into account, where handles are only 32-bit
> > while the native efi_handle_t type is 64-bit.
> >
> > So introduce a helper, and replace the various occurrences of
> > this pattern.
> >
> > Signed-off-by: Ard Biesheuvel <ardb@...nel.org>
> > ---
> >
> > +#define for_each_efi_handle(handle, array, size, i)                  \
> > +     for (i = 1, handle = efi_is_64bit()                             \
> > +             ? (efi_handle_t)(unsigned long)((u64 *)(array))[0]      \
> > +             : (efi_handle_t)(unsigned long)((u32 *)(array))[0];     \
> > +         i++ <= (size) / (efi_is_64bit() ? sizeof(efi_handle_t)      \
> > +                                          : sizeof(u32));            \
> > +         handle = efi_is_64bit()                                     \
> > +             ? (efi_handle_t)(unsigned long)((u64 *)(array))[i]      \
> > +             : (efi_handle_t)(unsigned long)((u32 *)(array))[i])
> > +
> >  /*
> >   * The UEFI spec and EDK2 reference implementation both define EFI_GUID as
> >   * struct { u32 a; u16; b; u16 c; u8 d[8]; }; and so the implied alignment
> > --
> > 2.17.1
> >
>
> This would access one past the array, no? Eg if the array has one
> handle, i is incremented to 2 the first time the condition is checked,
> then the loop increment will access array[2] before the condition is
> checked again. There seem to be at least a couple of other for_each
> macros that might have similar issues.
>

Indeed.

> How about the below instead?
>
> #define for_each_efi_handle(handle, array, size, i)                     \
>         for (i = 0;                                                     \
>             (i < (size) / (efi_is_64bit() ? sizeof(efi_handle_t)        \
>                                           : sizeof(u32))) &&            \
>             ((handle = efi_is_64bit()                                   \
>                 ? ((efi_handle_t *)(array))[i]                          \
>                 : (efi_handle_t)(unsigned long)((u32 *)(array))[i]), 1);\
>             i++)
>

Yeah, that looks correct to me, but perhaps we can come up with
something slightly more readable? :-)
(Not saying my code was better in that respect)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ