All of lore.kernel.org
 help / color / mirror / Atom feed
From: AKASHI Takahiro <takahiro.akashi@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH 1/1] efi_loader: check for image truncation
Date: Fri, 28 Aug 2020 10:27:36 +0900	[thread overview]
Message-ID: <20200828012736.GA209121@laputa> (raw)
In-Reply-To: <20200827162435.58430-1-xypron.glpk@gmx.de>

On Thu, Aug 27, 2020 at 06:24:35PM +0200, Heinrich Schuchardt wrote:
> Check in efi_load_pe() that the image size parameter is at least as large
> as the image size indicated in the optional PE header.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  lib/efi_loader/efi_image_loader.c | 28 +++++++++++++++++++++++-----
>  1 file changed, 23 insertions(+), 5 deletions(-)
> 
> diff --git a/lib/efi_loader/efi_image_loader.c b/lib/efi_loader/efi_image_loader.c
> index 94f76ef6b8..e55ade3291 100644
> --- a/lib/efi_loader/efi_image_loader.c
> +++ b/lib/efi_loader/efi_image_loader.c
> @@ -761,6 +761,29 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
>  		goto err;
>  	}
> 
> +	if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
> +		IMAGE_NT_HEADERS64 *nt64 = (void *)nt;
> +
> +		if ((size_t)opt->SizeOfImage > efi_size) {
> +			log_err("Truncated Image\n");
> +			ret = EFI_LOAD_ERROR;
> +			goto err;
> +		}
> +	} else if (nt->OptionalHeader.Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
> +		IMAGE_OPTIONAL_HEADER32 *opt = &nt->OptionalHeader;
> +
> +		if ((size_t)opt->SizeOfImage > efi_size) {
> +			log_err("Truncated Image\n");
> +			ret = EFI_LOAD_ERROR;
> +			goto err;
> +		}
> +	} else {
> +		log_err("Invalid optional header magic %x\n",
> +			nt->OptionalHeader.Magic);
> +		ret = EFI_LOAD_ERROR;
> +		goto err;
> +	}

Please remove the same message, which is now redundant,
in efi_image_parse().

-Takahiro Akashi

> +
>  	/* Authenticate an image */
>  	if (efi_image_authenticate(efi, efi_size)) {
>  		handle->auth_status = EFI_IMAGE_AUTH_PASSED;
> @@ -810,11 +833,6 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
>  		rel_size = opt->DataDirectory[rel_idx].Size;
>  		rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress;
>  		virt_size = ALIGN(virt_size, opt->SectionAlignment);
> -	} else {
> -		log_err("Invalid optional header magic %x\n",
> -			nt->OptionalHeader.Magic);
> -		ret = EFI_LOAD_ERROR;
> -		goto err;
>  	}
> 
>  	/* Copy PE headers */
> --
> 2.28.0
> 

      reply	other threads:[~2020-08-28  1:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27 16:24 [PATCH 1/1] efi_loader: check for image truncation Heinrich Schuchardt
2020-08-28  1:27 ` AKASHI Takahiro [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=20200828012736.GA209121@laputa \
    --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.