[PATCH kexec-tools 3/3] pe-zboot: fix integer overflow in payload bounds check in pez_prepare()
Simon Horman
horms at kernel.org
Tue Nov 10 03:35:18 PST 2026
In pez_prepare(), z->payload_offset and z->payload_size are uint32_t
values read from the untrusted file header. The validation check:
if (buf_sz < z->payload_offset + z->payload_size)
performs 32-bit unsigned addition. If the sum wraps around, the bounds
check succeeds, causing a subsequent out-of-bounds heap access when
writing the payload to the temporary decompression file.
Also, ensure buf_sz is large enough to contain the zboot header before
dereferencing its fields.
Prevent the overflow by checking that z->payload_offset does not exceed
buf_sz and that the remaining buffer (buf_sz - z->payload_offset) is at
least z->payload_size.
Patch written with LLM assistance.
Reported-by: Tristan <TristanInSec at gmail.com>
Signed-off-by: Simon Horman <horms at kernel.org>
---
kexec/kexec-pe-zboot.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/kexec/kexec-pe-zboot.c b/kexec/kexec-pe-zboot.c
index c09f2ae7714b..c60e543b68e3 100644
--- a/kexec/kexec-pe-zboot.c
+++ b/kexec/kexec-pe-zboot.c
@@ -51,6 +51,9 @@ int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd,
struct pe32plus_opt_hdr *opt_hdr;
struct data_directory *dir;
+ if (buf_sz < (off_t)sizeof(*z))
+ return -1;
+
z = (const struct linux_pe_zboot_header *)(crude_buf);
if (memcmp(&z->image_type, "zimg", sizeof(z->image_type))) {
@@ -69,7 +72,8 @@ int pez_prepare(const char *crude_buf, off_t buf_sz, int *kernel_fd,
return -1;
}
- if (buf_sz < z->payload_offset + z->payload_size) {
+ if ((uint64_t)buf_sz < z->payload_offset ||
+ (uint64_t)buf_sz - z->payload_offset < z->payload_size) {
dbgprintf("%s: PE too small to contain complete payload.\n", __func__);
return -1;
}
--
2.56.0
More information about the kexec
mailing list