public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>, edk2-devel@lists.01.org
Cc: leif.lindholm@linaro.org, thomas.abraham@arm.com,
	nariman.poushin@linaro.org, philmd@redhat.com
Subject: Re: [PATCH edk2-platforms 3/4] Platform/ARM/BdsLib: don't clobber BdsLoadImage() DevicePath IN param
Date: Thu, 22 Nov 2018 19:09:30 +0100	[thread overview]
Message-ID: <55c8b463-2b30-300f-85e4-5364f96c77c5@redhat.com> (raw)
In-Reply-To: <20181122172645.20819-4-ard.biesheuvel@linaro.org>

On 11/22/18 18:26, Ard Biesheuvel wrote:
> BdsLoadImage () is part of the BdsLib library API and is not documented
> as modifying its DevicePath argument, but does so nonetheless. So take
> a copy instead, and free it after use.
> 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  Platform/ARM/Library/BdsLib/BdsFilePath.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/Platform/ARM/Library/BdsLib/BdsFilePath.c b/Platform/ARM/Library/BdsLib/BdsFilePath.c
> index 67dafa4f3651..74fdbbee773d 100644
> --- a/Platform/ARM/Library/BdsLib/BdsFilePath.c
> +++ b/Platform/ARM/Library/BdsLib/BdsFilePath.c
> @@ -1351,5 +1351,16 @@ BdsLoadImage (
>    OUT    UINTN                 *FileSize
>    )
>  {
> -  return BdsLoadImageAndUpdateDevicePath (&DevicePath, Type, Image, FileSize);
> +  EFI_DEVICE_PATH       *Path;
> +  EFI_STATUS            Status;
> +
> +  Path = DuplicateDevicePath (DevicePath);
> +  if (Path == NULL) {
> +    return EFI_OUT_OF_RESOURCES;
> +  }

This introduces a minor change in behavior.

Previously, if BdsLoadImage() got DevicePath==NULL, then
BdsLoadImageAndUpdateDevicePath() -> BdsConnectAndUpdateDevicePath()
would hit (*DevicePath == NULL), and return EFI_INVALID_PARAMETER.

Now, (DevicePath==NULL) causes DuplicateDevicePath() to return NULL, and
we translate that to EFI_OUT_OF_RESOURCES.

Can you check for (DevicePath==NULL) first, and preserve
EFI_INVALID_PARAMETER?

> +
> +  Status = BdsLoadImageAndUpdateDevicePath (&Path, Type, Image, FileSize);
> +  FreePool (Path);

This is not safe; BdsLoadImageAndUpdateDevicePath() may change Path.
Namely, in BdsConnectAndUpdateDevicePath(), we have at one location,

      *DevicePath = NewDevicePath;

... Which, in fact, makes me wonder whether we need this patch at all. I
believe BdsLoadImageAndUpdateDevicePath() -- and
BdsConnectAndUpdateDevicePath() -- are supposed to update the caller's
*pointer* to the device path, and not the pointed-to device path itself.

Do you agree?

Thanks,
Laszlo

> +
> +  return Status;
>  }
> 



  reply	other threads:[~2018-11-22 18:09 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-22 17:26 [PATCH edk2-platforms 0/4] Platform/ARM: fix DevicePath mishandling in BdsLib Ard Biesheuvel
2018-11-22 17:26 ` [PATCH edk2-platforms 1/4] Platform/ARM: import ARM platform specific BdsLib header Ard Biesheuvel
2018-11-22 17:36   ` Laszlo Ersek
2018-11-22 17:26 ` [PATCH edk2-platforms 2/4] Platform/ARM/BdsLid: drop unused BdsStartEfiApplication () Ard Biesheuvel
2018-11-22 17:55   ` Laszlo Ersek
2018-11-22 17:26 ` [PATCH edk2-platforms 3/4] Platform/ARM/BdsLib: don't clobber BdsLoadImage() DevicePath IN param Ard Biesheuvel
2018-11-22 18:09   ` Laszlo Ersek [this message]
2018-11-22 18:14     ` Ard Biesheuvel
2018-11-22 18:23       ` Laszlo Ersek
2018-11-22 17:26 ` [PATCH edk2-platforms 4/4] Platform/ARM/BdsLib: maintain alignment for DevicePaths Ard Biesheuvel
2018-11-22 18:35   ` Laszlo Ersek
2018-11-23  8:35     ` Ard Biesheuvel
2018-11-23  9:39       ` Laszlo Ersek
2018-11-23  4:20 ` [PATCH edk2-platforms 0/4] Platform/ARM: fix DevicePath mishandling in BdsLib Thomas Abraham
2018-11-23  8:44   ` Ard Biesheuvel

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-list 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=55c8b463-2b30-300f-85e4-5364f96c77c5@redhat.com \
    --to=devel@edk2.groups.io \
    /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