device-tree/kernel: Use memcpy in output_length()

Trying to boot a compressed kernel with UBSAN enabled, results in the
following warning:
(XEN) UBSAN: Undefined behaviour in common/device-tree/kernel.c:21:12
(XEN) load of misaligned address 00000a0040f89867 for type 'uint32_t'
(XEN) which requires 4 byte alignment
...
(XEN)    [<00000a0000529964>] kernel_decompress+0x2bc/0x5bc
(XEN)    [<00000a000052a354>] kernel_probe+0x6f0/0x734
(XEN)    [<00000a0000528714>] dom0less-build.c#construct_domU+0x188/0x9d8

If &image[image_len - 4] is not aligned to 4B boundary it causes
unaligned access which is undefined behavior on Arm. Use memcpy instead
to be safe.

Fixes: c1be0b102e ("xen/arm: support gzip compressed kernels")
Signed-off-by: Michal Orzel <michal.orzel@amd.com>
Acked-by: Bertrand Marquis <bertrand.marquis@arm.com>
This commit is contained in:
Michal Orzel authored and Stefano Stabellini committed 2025-07-23 12:39:50 -07:00
1 parent 5c798ac885
commit 384a399d21
1 file changed
+5 -1
+5 -1
View File
@@ -18,7 +18,11 @@
static uint32_t __init output_length(char *image, unsigned long image_len)
{
return *(uint32_t *)&image[image_len - 4];
uint32_t val;
memcpy(&val, &image[image_len - 4], sizeof(val));
return val;
}
int __init kernel_decompress(struct boot_module *mod, uint32_t offset)
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.