mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	Barebox List <barebox@lists.infradead.org>
Cc: Sascha Hauer <sascha@saschahauer.de>,
	"Claude Opus 4.6 (1M context)" <noreply@anthropic.com>
Subject: Re: [PATCH 2/4] efi: loader: validate section raw data bounds against image size
Date: Tue, 14 Apr 2026 10:46:38 +0200	[thread overview]
Message-ID: <d3963e44-2b2c-45ff-9bd0-cbe71180ebac@pengutronix.de> (raw)
In-Reply-To: <20260413123646.3552086-2-s.hauer@pengutronix.de>



On 4/13/26 2:36 PM, Sascha Hauer wrote:
> From: Sascha Hauer <sascha@saschahauer.de>
> 
> When loading PE sections, PointerToRawData and SizeOfRawData from the
> section header are used to memcpy from the input image without checking
> that the source region fits within the image buffer. A crafted PE with
> PointerToRawData pointing near the end of the file causes a read past
> the input buffer.
> 
> Use size_add() for the bounds check so that the addition saturates to
> SIZE_MAX on overflow instead of wrapping, which would bypass the check
> on 32-bit architectures where unsigned long is 32 bits.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> 
> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Reviewed-by: Ahmad Fatoum <a.fatoum@pengutronix.de>

> ---
>  efi/loader/pe.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/efi/loader/pe.c b/efi/loader/pe.c
> index 7c5aaa1f91..3190718df5 100644
> --- a/efi/loader/pe.c
> +++ b/efi/loader/pe.c
> @@ -706,6 +706,11 @@ efi_status_t efi_load_pe(struct efi_loaded_image_obj *handle,
>  			memset(efi_reloc + sec->VirtualAddress, 0,
>  			       sec->Misc.VirtualSize);
>  		}
> +		if (size_add(sec->PointerToRawData, copy_size) > efi_size) {
> +			pr_err("Section %d exceeds image size\n", i);
> +			ret = EFI_LOAD_ERROR;
> +			goto err;
> +		}
>  		memcpy(efi_reloc + sec->VirtualAddress,
>  		       efi + sec->PointerToRawData,
>  		       copy_size);

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |




  reply	other threads:[~2026-04-14  8:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13 12:36 [PATCH 1/4] efi: loader: fix integer overflow in PE virt_size calculation Sascha Hauer
2026-04-13 12:36 ` [PATCH 2/4] efi: loader: validate section raw data bounds against image size Sascha Hauer
2026-04-14  8:46   ` Ahmad Fatoum [this message]
2026-04-13 12:36 ` [PATCH 3/4] efi: loader: fix SizeOfBlock underflow in relocation processing Sascha Hauer
2026-04-14  8:47   ` Ahmad Fatoum
2026-04-13 12:36 ` [PATCH 4/4] efi: loader: bounds-check relocation offsets against image size Sascha Hauer
2026-04-14  8:52   ` Ahmad Fatoum
2026-04-14  8:41 ` [PATCH 1/4] efi: loader: fix integer overflow in PE virt_size calculation Ahmad Fatoum
2026-04-14 10:06 ` Sascha Hauer

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=d3963e44-2b2c-45ff-9bd0-cbe71180ebac@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=noreply@anthropic.com \
    --cc=s.hauer@pengutronix.de \
    --cc=sascha@saschahauer.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