All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: Simon Glass <sjg@google.com>, Dan Carpenter <dan.carpenter@linaro.org>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>, u-boot@lists.denx.de
Subject: Re: [PATCH v2] efi_loader: Fix memory corruption on 32bit systems
Date: Fri, 28 Jul 2023 06:52:21 +0200	[thread overview]
Message-ID: <80C02131-0BA9-487B-ACB3-EBC41FC09090@gmx.de> (raw)
In-Reply-To: <CAPnjgZ0TkvJSXTLo8EjtPeM6BRRT-Ez87Ob2m1+LMB=Jvin84A@mail.gmail.com>



Am 28. Juli 2023 03:51:55 MESZ schrieb Simon Glass <sjg@google.com>:
>Hi,
>
>On Thu, 27 Jul 2023 at 08:36, Dan Carpenter <dan.carpenter@linaro.org> wrote:
>>
>> On Thu, Jul 27, 2023 at 11:22:15AM +0300, Ilias Apalodimas wrote:
>> > Hi Dan,
>> >
>> > [...]
>> >
>> > > @@ -313,7 +313,7 @@ static int cmp_pe_section(const void *arg1, const void *arg2)
>> > >   *
>> > >   * Return: valid pointer to a image, return NULL if allocation fails.
>> > >   */
>> > > -void *efi_prepare_aligned_image(void *efi, u64 *efi_size)
>> > > +void *efi_prepare_aligned_image(void *efi, size_t *efi_size)
>> > >  {
>> > >     size_t new_efi_size;
>> > >     void *new_efi;
>> > > @@ -600,7 +600,7 @@ static bool efi_image_authenticate(void *efi, size_t efi_size)
>> > >     if (!efi_secure_boot_enabled())
>> > >             return true;
>> > >
>> > > -   new_efi = efi_prepare_aligned_image(efi, (u64 *)&efi_size);
>> > > +   new_efi = efi_prepare_aligned_image(efi, &efi_size);
>> > >     if (!new_efi)
>> > >             return false;
>> > >
>> > > diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c
>> > > index 49f8a5e77cbf..d57afd0c498b 100644
>> > > --- a/lib/efi_loader/efi_tcg2.c
>> > > +++ b/lib/efi_loader/efi_tcg2.c
>> > > @@ -882,7 +882,7 @@ out:
>> > >   *
>> > >   * Return: status code
>> > >   */
>> > > -static efi_status_t tcg2_hash_pe_image(void *efi, u64 efi_size,
>> > > +static efi_status_t tcg2_hash_pe_image(void *efi, size_t efi_size,
>> > >                                    struct tpml_digest_values *digest_list)
>> >
>> > Unfortunately the rabbit hole is a bit deeper with this one.
>> > tcg2_hash_pe_image() is called in
>> > - tcg2_measure_pe_image(). This one is called in efi_load_pe() and the type
>> >   is indeed a size_t there, so that's fine
>> > - efi_tcg2_hash_log_extend_event(), this one is different...
>> > The function is described by the EFI spec [0] which mandates a u64... I
>> > think that was the reason efi_prepare_aligned_image() is using a u64 to
>> > begin with.  This one uses the size only though not the pointer, but in a
>> > 32bit platform it would truncate s size > UINT_MAX.
>> >
>> > [0] https://trustedcomputinggroup.org/wp-content/uploads/EFI-Protocol-Specification-rev13-160330final.pdf
>>
>> I have maybe misread something...  I don't think this is a real issue.
>> 32bit systems aren't going to be able to allocate that much memory
>> anyway.  Also there are a lot of size_t parameters already so it's not
>> a new issue.
>
>We should really use ulong for addresses and malloc() sizes.

Please, do not abuse long.

According to the C specification the size of long is independent of the size of pointers.

Addresses should be pointers and sizes should be size_t.

Best regards

Heinrich

      reply	other threads:[~2023-07-28  4:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27  7:11 [PATCH v2] efi_loader: Fix memory corruption on 32bit systems Dan Carpenter
2023-07-27  8:22 ` Ilias Apalodimas
2023-07-27  9:49   ` Dan Carpenter
2023-07-28  1:51     ` Simon Glass
2023-07-28  4:52       ` Heinrich Schuchardt [this message]

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=80C02131-0BA9-487B-ACB3-EBC41FC09090@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=dan.carpenter@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=sjg@google.com \
    --cc=u-boot@lists.denx.de \
    /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.