On Tue, 26 Aug 2025 05:08:51 -0700 Breno Leitao <[email protected]> wrote:
> The kexec_buf structure was previously declared without initialization > in image_load(). This led to a UBSAN warning when the structure was > expanded and uninitialized fields were accessed [1]. > > Zero-initializing kexec_buf at declaration ensures all fields are > cleanly set, preventing future instances of uninitialized memory being > used. > > Andrew Morton suggested that this function is only called 3x a week[2], > thus, the memset() cost is inexpressive. > Thanks, I queued this as a replacement for your eralier "kexec/arm64: initialize the random field of kbuf to zero in the image loader". I added cc:stable, a mention of the UBSAN failure and I added thie Fixes: From: Breno Leitao <[email protected]> Subject: arm64: kexec: Initialize kexec_buf struct in image_load() Date: Tue, 26 Aug 2025 05:08:51 -0700 The kexec_buf structure was previously declared without initialization in image_load(). This led to a UBSAN warning when the structure was expanded and uninitialized fields were accessed [1]. Zero-initializing kexec_buf at declaration ensures all fields are cleanly set, preventing future instances of uninitialized memory being used. Fixes this UBSAN warning: [ 32.362488] UBSAN: invalid-load in ./include/linux/kexec.h:210:10 [ 32.362649] load of value 252 is not a valid value for type '_Bool' Andrew Morton suggested that this function is only called 3x a week[2], thus, the memset() cost is inexpensive. Link: https://lore.kernel.org/all/oninomspajhxp4omtdapxnckxydbk2nzmrix7rggmpukpnzadw@c67o7njgdgm3/ [1] Link: https://lore.kernel.org/all/[email protected]/ [2] Link: https://lkml.kernel.org/r/[email protected] Fixes: bf454ec31add ("kexec_file: allow to place kexec_buf randomly") Signed-off-by: Breno Leitao <[email protected]> Suggested-by: Andrew Morton <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Baoquan He <[email protected]> Cc: Coiby Xu <[email protected]> Cc: "Daniel P. Berrange" <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dave Young <[email protected]> Cc: Kairui Song <[email protected]> Cc: Liu Pingfan <[email protected]> Cc: Milan Broz <[email protected]> Cc: Ondrej Kozina <[email protected]> Cc: Vitaly Kuznetsov <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> --- arch/arm64/kernel/kexec_image.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/arm64/kernel/kexec_image.c~arm64-kexec-initialize-kexec_buf-struct-in-image_load +++ a/arch/arm64/kernel/kexec_image.c @@ -41,7 +41,7 @@ static void *image_load(struct kimage *i struct arm64_image_header *h; u64 flags, value; bool be_image, be_kernel; - struct kexec_buf kbuf; + struct kexec_buf kbuf = {}; unsigned long text_offset, kernel_segment_number; struct kexec_segment *kernel_segment; int ret; _
