U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Simon Glass <sjg@chromium.org>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Matthew Garrett <mjg59@srcf.ucam.org>,
	Janis Danisevskis <jdanisevskis@aurora.tech>,
	Matthew Garrett <mgarrett@aurora.tech>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	u-boot@lists.denx.de
Subject: Re: [PATCH 09/10] Fix efi_bind_block.
Date: Tue, 10 Dec 2024 11:11:13 -0600	[thread overview]
Message-ID: <20241210171113.GD2457179@bill-the-cat> (raw)
In-Reply-To: <CAFLszThHxSt7-8QScz8+d96PwrZy--MKYsnrhfdCw8TK0c8rLA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3929 bytes --]

On Tue, Dec 10, 2024 at 09:17:26AM -0700, Simon Glass wrote:
> Hi Heinrich,
> 
> On Tue, 10 Dec 2024 at 01:50, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >
> > On 23.11.24 20:55, Matthew Garrett wrote:
> > > From: Janis Danisevskis <jdanisevskis@aurora.tech>
> > >
> > > efi_bind_block had two issues.
> > > 1. A pointer to a the stack was inserted as plat structure and thus used
> > > beyond its life time.
> > > 2. Only the first segment of the device path was copied into the
> > > platfom data structure resulting in an unterminated device path.
> > >
> > > Signed-off-by: Janis Danisevskis <jdanisevskis@aurora.tech>
> > > Signed-off-by: Matthew Garrett <mgarrett@aurora.tech>
> > > ---
> > >
> > >   lib/efi/efi_app_init.c | 29 +++++++++++++++++++++--------
> > >   1 file changed, 21 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/lib/efi/efi_app_init.c b/lib/efi/efi_app_init.c
> > > index 9704020b749..cc91e1d74b8 100644
> > > --- a/lib/efi/efi_app_init.c
> > > +++ b/lib/efi/efi_app_init.c
> > > @@ -19,6 +19,15 @@
> > >
> > >   DECLARE_GLOBAL_DATA_PTR;
> > >
> > > +static size_t device_path_length(const struct efi_device_path *device_path)
> > > +{
> > > +     const struct efi_device_path *d;
> > > +
> > > +     for (d = device_path; d->type != DEVICE_PATH_TYPE_END; d = (void *)d + d->length) {
> > > +     }
> > > +     return (void *)d - (void *)device_path + d->length;
> > > +}
> > > +
> > >   /**
> > >    * efi_bind_block() - bind a new block device to an EFI device
> > >    *
> > > @@ -39,19 +48,23 @@ int efi_bind_block(efi_handle_t handle, struct efi_block_io *blkio,
> > >                  struct efi_device_path *device_path, int len,
> > >                  struct udevice **devp)
> > >   {
> > > -     struct efi_media_plat plat;
> > > +     struct efi_media_plat *plat;
> > >       struct udevice *dev;
> > >       char name[18];
> > >       int ret;
> > > -
> > > -     plat.handle = handle;
> > > -     plat.blkio = blkio;
> > > -     plat.device_path = malloc(device_path->length);
> > > -     if (!plat.device_path)
> > > +     size_t device_path_len = device_path_length(device_path);
> > > +
> > > +     plat = malloc(sizeof(struct efi_media_plat));
> > > +     if (!plat)
> > > +             return log_msg_ret("plat", -ENOMEM);
> > > +     plat->handle = handle;
> > > +     plat->blkio = blkio;
> > > +     plat->device_path = malloc(device_path_len);
> > > +     if (!plat->device_path)
> > >               return log_msg_ret("path", -ENOMEM);
> > > -     memcpy(plat.device_path, device_path, device_path->length);
> > > +     memcpy(plat->device_path, device_path, device_path_len);
> > >       ret = device_bind(dm_root(), DM_DRIVER_GET(efi_media), "efi_media",
> > > -                       &plat, ofnode_null(), &dev);
> > > +                       plat, ofnode_null(), &dev);
> > >       if (ret)
> > >               return log_msg_ret("bind", ret);
> >
> > Here you have a memory leak for pointer plat if ret != 0.
> >
> > Simon suggested a follow up patch. Instead we should fix it in this patch.
> >
> > @Simon
> > The logic in the caller setup_block() looks wrong.
> >
> > LocateHandle() does not ensure that when you try to read from the block
> > device the same still does exist. E.g. if a USB device is removed the
> > block IO protocol could be uninstalled and the handle deleted and the
> > EFI app may crash. Please, call OpenProtocol() with attribute BY_DRIVER.
> >
> > HandleProtocol() is considered deprecated. Please, use OpenProtocol()
> > instead.
> 
> Can you please send a follow-up with your ideas on this?

Simon, it's in your tree. The normal path here would be that the
submitter would correct this in v2. But you're trying to short-circuit
that path for your own reasons. No one should be making work on top of
your tree except for you.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

  reply	other threads:[~2024-12-10 17:11 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-23 19:54 [PATCH 00/10] Improve UEFI app support Matthew Garrett
2024-11-23 19:55 ` [PATCH 01/10] Add EFI handover support to bootm Matthew Garrett
2024-11-24 14:43   ` Heinrich Schuchardt
2024-11-24 19:29     ` Matthew Garrett
2024-11-24 19:51       ` Heinrich Schuchardt
2024-12-08 23:06         ` Simon Glass
2024-11-25 13:46       ` Ilias Apalodimas
2024-12-01 16:12   ` Simon Glass
2024-12-08 15:29     ` Simon Glass
2024-11-23 19:55 ` [PATCH 02/10] Add part_find command Matthew Garrett
2024-12-01 16:12   ` Simon Glass
2024-12-08 15:29     ` Simon Glass
2024-12-10  8:21   ` Heinrich Schuchardt
2024-12-10 16:16     ` Simon Glass
2024-11-23 19:55 ` [PATCH 03/10] Add a command to find a load address Matthew Garrett
2024-11-24 15:56   ` Tom Rini
2024-12-01 16:12   ` Simon Glass
2024-12-08 15:29     ` Simon Glass
2024-11-23 19:55 ` [PATCH 04/10] Hook up EFI env variable support in the EFI app Matthew Garrett
2024-12-01 16:12   ` Simon Glass
2024-12-08 15:29     ` Simon Glass
2024-11-23 19:55 ` [PATCH 05/10] Add EFI network driver Matthew Garrett
2024-12-01 16:12   ` Simon Glass
2024-12-08 15:29     ` Simon Glass
2024-11-23 19:55 ` [PATCH 06/10] Add UEFI TPM2 driver Matthew Garrett
2024-12-01 16:12   ` Simon Glass
2024-12-08 15:29     ` Simon Glass
2024-11-23 19:55 ` [PATCH 07/10] Support separate DTB files with the UEFI app Matthew Garrett
2024-11-25 13:55   ` Ilias Apalodimas
2024-12-01 16:14   ` Simon Glass
2024-12-08 15:29     ` Simon Glass
2024-11-23 19:55 ` [PATCH 08/10] Use the correct ramdisk address Matthew Garrett
2024-12-01 16:14   ` Simon Glass
2024-12-08 15:29     ` Simon Glass
2024-11-23 19:55 ` [PATCH 09/10] Fix efi_bind_block Matthew Garrett
2024-11-25 13:40   ` Ilias Apalodimas
2024-12-09  2:28     ` Simon Glass
2024-12-01 16:14   ` Simon Glass
2024-12-08 15:29     ` Simon Glass
2024-12-10  8:45   ` Heinrich Schuchardt
2024-12-10 16:17     ` Simon Glass
2024-12-10 17:11       ` Tom Rini [this message]
2024-12-11 17:50         ` Janis Danisevskis
2024-12-11 17:59           ` Ilias Apalodimas
2024-12-11 20:23           ` Simon Glass
2024-12-11 22:28             ` Janis Danisevskis
2024-11-23 19:55 ` [PATCH 10/10] Add command to set an environment variable to an EFI variable Matthew Garrett
2024-11-24 14:58   ` Heinrich Schuchardt
2024-12-01 16:14     ` Simon Glass
2024-12-08 15:29       ` Simon Glass
2024-12-09  2:28     ` Simon Glass
2024-11-24 14:40 ` [PATCH 00/10] Improve UEFI app support Heinrich Schuchardt
2024-12-01 16:15 ` Simon Glass
2024-12-08 15:28   ` Simon Glass
2024-12-08 15:51     ` Tom Rini
2024-12-08 18:50       ` Tom Rini
2024-12-08 23:07       ` Simon Glass

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=20241210171113.GD2457179@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jdanisevskis@aurora.tech \
    --cc=mgarrett@aurora.tech \
    --cc=mjg59@srcf.ucam.org \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox