From: Pranav Rajendran <pranavkasthuri@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: philippe.reynes@softathome.com, trini@konsulko.com,
Pranav Rajendran <pranavkasthuri@gmail.com>
Subject: [PATCH v1 3/3] lib: aes: reject an unciphered size larger than the ciphertext
Date: Sat, 15 Aug 2026 23:07:54 +0100 [thread overview]
Message-ID: <20260815220754.11724-4-pranavkasthuri@gmail.com> (raw)
In-Reply-To: <20260815220754.11724-1-pranavkasthuri@gmail.com>
image_aes_decrypt() allocates cipher_len bytes, decrypts into them, and
then reports the plaintext length to its caller as
info->size_unciphered, without relating the two. size_unciphered comes
from the image's 'data-size-unciphered' property, so an image can claim
a plaintext larger than the buffer that was allocated for it.
fit_image_uncipher() propagates that length as the image size, and
everything downstream - the load, the copy to the entry point - works
from it, reading up to 4 GiB past the end of the decrypted buffer.
Unlike the image data itself, 'data-size-unciphered' is not covered by
the per-image hash or signature, so this is reachable on a signed FIT
whose signature still verifies.
Decryption produces exactly cipher_len bytes, so require the claimed
size to fit within that.
Fixes: 4df3578119b0 ("u-boot: fit: add support to decrypt fit with aes")
Signed-off-by: Pranav Rajendran <pranavkasthuri@gmail.com>
---
lib/aes/aes-decrypt.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lib/aes/aes-decrypt.c b/lib/aes/aes-decrypt.c
index 85773a9c4f6..5d616983082 100644
--- a/lib/aes/aes-decrypt.c
+++ b/lib/aes/aes-decrypt.c
@@ -27,6 +27,15 @@ int image_aes_decrypt(struct image_cipher_info *info,
return -EINVAL;
}
+ /*
+ * Decryption produces exactly cipher_len bytes, so the unciphered
+ * size the image claims cannot be larger than that.
+ */
+ if (info->size_unciphered > cipher_len) {
+ printf("Invalid unciphered size\n");
+ return -EINVAL;
+ }
+
*data = malloc(cipher_len);
if (!*data) {
printf("Can't allocate memory to decrypt\n");
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-08-15 22:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 22:07 [PATCH v1 0/3] fit: cipher: bounds checks on the ciphered image path Pranav Rajendran
2026-08-15 22:07 ` [PATCH v1 1/3] lib: aes: reject a ciphertext length that is not a whole number of blocks Pranav Rajendran
2026-08-25 12:52 ` Simon Glass
2026-08-15 22:07 ` [PATCH v1 2/3] image-fit: check the length of the data-size-unciphered property Pranav Rajendran
2026-08-25 12:52 ` Simon Glass
2026-08-15 22:07 ` Pranav Rajendran [this message]
2026-08-25 12:52 ` [PATCH v1 3/3] lib: aes: reject an unciphered size larger than the ciphertext Simon Glass
2026-08-25 12:53 ` [v1,0/3] fit: cipher: bounds checks on the ciphered image path Simon Glass
2026-08-25 14:19 ` [PATCH v2 0/5] " Pranav Rajendran
2026-08-25 14:19 ` [PATCH v2 1/5] lib: aes: reject a ciphertext length that is not a whole number of blocks Pranav Rajendran
2026-08-25 14:19 ` [PATCH v2 2/5] image-fit: check the length of the data-size-unciphered property Pranav Rajendran
2026-08-25 14:19 ` [PATCH v2 3/5] lib: aes: reject an unciphered size larger than the ciphertext Pranav Rajendran
2026-08-25 14:19 ` [PATCH v2 4/5] include: u-boot: aes: make disabled cipher stubs static inline Pranav Rajendran
2026-08-25 14:19 ` [PATCH v2 5/5] test: boot: add regression tests for the FIT cipher bounds checks Pranav Rajendran
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=20260815220754.11724-4-pranavkasthuri@gmail.com \
--to=pranavkasthuri@gmail.com \
--cc=philippe.reynes@softathome.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/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.