U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ana Bobillo <anabobillo3@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Tom Rini <trini@konsulko.com>
Subject: [PATCH v2 4/7] efi_loader: capsule: check the certificate length of an image
Date: Wed, 28 Oct 2026 05:50:07 +0000	[thread overview]
Message-ID: <f8cc0827-166e-4bc5-89fa-2d160faf025c@gmail.com> (raw)
In-Reply-To: <ab256ba2-8572-4cda-b7da-45b2c0368beb@gmail.com>

From: Ana Bobillo <anabobillo3@gmail.com>

efi_remove_auth_hdr() skips the authentication header of an image by
the dwLength of its certificate without checking it against the image
size. A dwLength larger than the image makes the image size wrap
around:

- with CONFIG_EFI_CAPSULE_AUTHENTICATE, efi_capsule_authenticate()
  then parses dwLength bytes of certificate past the end of the image
  before the signature is checked;
- without it, efi_capsule_update_firmware() passes the wrapped image
  size on to the FMP driver.

Reject a certificate that does not fit in the image.

Fixes: 04be98bd6bcf ("efi: capsule: Add support for uefi capsule authentication")
Fixes: c2cc60c1f93b ("efi_loader: capsule: remove authentication data")
Signed-off-by: Ana Bobillo <anabobillo3@gmail.com>
---
 lib/efi_loader/efi_capsule.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index f57a7e60a5d..646428c7d8f 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -270,7 +270,9 @@ static efi_status_t efi_remove_auth_hdr(void **image, efi_uintn_t *image_size)
 		goto out;
 
 	if (auth_hdr->auth_info.hdr.dwLength <=
-	    offsetof(struct win_certificate_uefi_guid, cert_data))
+	    offsetof(struct win_certificate_uefi_guid, cert_data) ||
+	    auth_hdr->auth_info.hdr.dwLength >
+	    *image_size - sizeof(auth_hdr->monotonic_count))
 		goto out;
 
 	*image = (uint8_t *)*image + sizeof(auth_hdr->monotonic_count) +

  parent reply	other threads:[~2026-10-28  5:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28  5:49 [PATCH v2 0/7] efi_loader: capsule: check sizes against the capsule Ana Bobillo
2026-10-28  5:49 ` [PATCH v2 1/7] efi_loader: capsule: check the size of a capsule file Ana Bobillo
2026-10-28  5:49 ` [PATCH v2 2/7] efi_loader: capsule: check the capsule header size Ana Bobillo
2026-10-30 12:46   ` Ilias Apalodimas
2026-10-28  5:50 ` [PATCH v2 3/7] efi_loader: capsule: check the FMP capsule against its size Ana Bobillo
2026-10-28  5:50 ` Ana Bobillo [this message]
2026-10-28  5:50 ` [PATCH v2 5/7] efi_loader: firmware: check the FMP payload header size Ana Bobillo
2026-10-28  5:50 ` [PATCH v2 6/7] test: lib: add tests for the capsule size checks Ana Bobillo
2026-10-28  5:50 ` [PATCH v2 7/7] test: py: efi_capsule: test truncated capsules and FMP payload headers Ana Bobillo

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=f8cc0827-166e-4bc5-89fa-2d160faf025c@gmail.com \
    --to=anabobillo3@gmail.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.u-boot-project.org \
    --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