From: Takahiro Akashi <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/2] efi_loader: parameter checks in StartImage and Exit()
Date: Thu, 11 Apr 2019 14:38:45 +0900 [thread overview]
Message-ID: <20190411053843.GC7158@linaro.org> (raw)
In-Reply-To: <20190405015258.6780-3-xypron.glpk@gmx.de>
On Fri, Apr 05, 2019 at 03:52:58AM +0200, Heinrich Schuchardt wrote:
> Add parameter checks in the StartImage() and Exit() boottime services:
> - check that the image handle is valid and has the loaded image protocol
> installed
> - in StartImage() record the current image
> - in Exit() check that the image is the current image
Does this check logic work for a case of nested calls of StartImage() at all?
-Takahiro Akashi
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v2
> avoid `parent_image` may be used uninitialized
> ---
> lib/efi_loader/efi_boottime.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c
> index 6aac8391c5..970c01614e 100644
> --- a/lib/efi_loader/efi_boottime.c
> +++ b/lib/efi_loader/efi_boottime.c
> @@ -26,6 +26,9 @@ LIST_HEAD(efi_obj_list);
> /* List of all events */
> LIST_HEAD(efi_events);
>
> +/* Handle of the currently executing image */
> +static efi_handle_t current_image;
> +
> /*
> * If we're running on nasty systems (32bit ARM booting into non-EFI Linux)
> * we need to do trickery with caches. Since we don't want to break the EFI
> @@ -2631,9 +2634,18 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
> struct efi_loaded_image_obj *image_obj =
> (struct efi_loaded_image_obj *)image_handle;
> efi_status_t ret;
> + void *info;
> + efi_handle_t parent_image = current_image;
>
> EFI_ENTRY("%p, %p, %p", image_handle, exit_data_size, exit_data);
>
> + /* Check parameters */
> + ret = EFI_CALL(efi_open_protocol(image_handle, &efi_guid_loaded_image,
> + &info, NULL, NULL,
> + EFI_OPEN_PROTOCOL_GET_PROTOCOL));
> + if (ret != EFI_SUCCESS)
> + return EFI_EXIT(EFI_INVALID_PARAMETER);
> +
> efi_is_direct_boot = false;
>
> /* call the image! */
> @@ -2662,9 +2674,11 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle,
> __efi_nesting_dec(),
> (unsigned long)((uintptr_t)image_obj->exit_status &
> ~EFI_ERROR_MASK));
> + current_image = parent_image;
> return EFI_EXIT(image_obj->exit_status);
> }
>
> + current_image = image_handle;
> ret = EFI_CALL(image_obj->entry(image_handle, &systab));
>
> /*
> @@ -2699,12 +2713,23 @@ static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
> * TODO: We should call the unload procedure of the loaded
> * image protocol.
> */
> + efi_status_t ret;
> + void *info;
> struct efi_loaded_image_obj *image_obj =
> (struct efi_loaded_image_obj *)image_handle;
>
> EFI_ENTRY("%p, %ld, %zu, %p", image_handle, exit_status,
> exit_data_size, exit_data);
>
> + /* Check parameters */
> + if (image_handle != current_image)
> + goto out;
> + ret = EFI_CALL(efi_open_protocol(image_handle, &efi_guid_loaded_image,
> + &info, NULL, NULL,
> + EFI_OPEN_PROTOCOL_GET_PROTOCOL));
> + if (ret != EFI_SUCCESS)
> + goto out;
> +
> /* Make sure entry/exit counts for EFI world cross-overs match */
> EFI_EXIT(exit_status);
>
> @@ -2718,6 +2743,8 @@ static efi_status_t EFIAPI efi_exit(efi_handle_t image_handle,
> longjmp(&image_obj->exit_jmp, 1);
>
> panic("EFI application exited");
> +out:
> + return EFI_EXIT(EFI_INVALID_PARAMETER);
> }
>
> /**
> --
> 2.20.1
>
prev parent reply other threads:[~2019-04-11 5:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-05 1:52 [U-Boot] [PATCH v2 0/2] efi_loader: parameter checks in StartImage and Exit() Heinrich Schuchardt
2019-04-05 1:52 ` [U-Boot] [PATCH v2 1/2] efi_loader: rearrange boottime service functions Heinrich Schuchardt
2019-04-05 1:52 ` [U-Boot] [PATCH v2 2/2] efi_loader: parameter checks in StartImage and Exit() Heinrich Schuchardt
2019-04-09 1:40 ` Takahiro Akashi
2019-04-11 5:38 ` Takahiro Akashi [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=20190411053843.GC7158@linaro.org \
--to=takahiro.akashi@linaro.org \
--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.