kexec: Fix invalid field access
cover kexec: Fix invalid field access
The kexec_buf structure was previously declared without initialization. commit bf454ec31add ("kexec_file: allow to place kexec_buf randomly") added a field that is always read but not consistently populated by all architectures. This un-initialized field will contain garbage.
This is also triggering a UBSAN warning when the uninitialized data was accessed:
------------[ cut here ]------------ UBSAN: invalid-load in ./include/linux/kexec.h:210:10 load of value 252 is not a valid value for type '_Bool'
Zero-initializing kexec_buf at declaration ensures all fields are cleanly set, preventing future instances of uninitialized memory being used.
An initial fix was already landed for arm64[0], and this patchset fixes the problem on the remaining arm64 code and on riscv, as raised by Mark.
Discussions about this problem could be found at[1][2].
---
Breno Leitao (3):
arm64: kexec: Initialize kexec_buf struct in load_other_segments()
riscv: kexec: Initialize kexec_buf struct
s390: kexec: Initialize kexec_buf struct
arch/arm64/kernel/machine_kexec_file.c | 2 +- arch/riscv/kernel/kexec_elf.c | 4 ++-- arch/riscv/kernel/kexec_image.c | 2 +- arch/riscv/kernel/machine_kexec_file.c | 2 +- arch/s390/kernel/kexec_elf.c | 2 +- arch/s390/kernel/kexec_image.c | 2 +- arch/s390/kernel/machine_kexec_file.c | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-)
---
base-commit: 3c642997252eef4449cb6b6e02af3dc22515d817
change-id: 20250827-kbuf_all-b9d55c9291eb
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
PATCH 1/3 arm64: kexec: Initialize kexec_buf struct in load_other_segments()
The kexec_buf structure was previously declared without initialization. commit bf454ec31add ("kexec_file: allow to place kexec_buf randomly") added a field that is always read but not consistently populated by all architectures. This un-initialized field will contain garbage.
This is also triggering a UBSAN warning when the uninitialized data was accessed:
------------[ cut here ]------------ UBSAN: invalid-load in ./include/linux/kexec.h:210:10 load of value 252 is not a valid value for type '_Bool'
Zero-initializing kexec_buf at declaration ensures all fields are cleanly set, preventing future instances of uninitialized memory being used.
--- arch/arm64/kernel/machine_kexec_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/machine_kexec_file.c +1 -1
@@ -94,7 +94,7 @@ int load_other_segments(struct kimage *image, char *initrd, unsigned long initrd_len, char *cmdline) { - struct kexec_buf kbuf; + struct kexec_buf kbuf = {};void *dtb =NULL ;unsigned long initrd_load_addr =0 , dtb_len, orig_segments = image->nr_segments;
Signature · 1 line
2.47.3
PATCH 2/3 riscv: kexec: Initialize kexec_buf struct
In reply to Breno LeitaoThe kexec_buf structure was previously declared without initialization. commit bf454ec31add ("kexec_file: allow to place kexec_buf randomly") added a field that is always read but not consistently populated by all architectures. This un-initialized field will contain garbage.
This is also triggering a UBSAN warning when the uninitialized data was accessed:
------------[ cut here ]------------ UBSAN: invalid-load in ./include/linux/kexec.h:210:10 load of value 252 is not a valid value for type '_Bool'
Zero-initializing kexec_buf at declaration ensures all fields are cleanly set, preventing future instances of uninitialized memory being used.
--- arch/riscv/kernel/kexec_elf.c | 4 ++-- arch/riscv/kernel/kexec_image.c | 2 +- arch/riscv/kernel/machine_kexec_file.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
arch/riscv/kernel/kexec_elf.c +2 -2
@@ -28,7 +28,7 @@ static int riscv_kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,int i;int ret =0 ;size_t size; -struct kexec_buf kbuf; +struct kexec_buf kbuf = {};const struct elf_phdr *phdr; kbuf.image = image;
@@ -66,7 +66,7 @@ static int elf_find_pbase(struct kimage *image, unsigned long kernel_len, {int i;int ret; -struct kexec_buf kbuf; +struct kexec_buf kbuf = {};const struct elf_phdr *phdr;unsigned long lowest_paddr =ULONG_MAX ;unsigned long lowest_vaddr =ULONG_MAX ;
arch/riscv/kernel/kexec_image.c +1 -1
@@ -41,7 +41,7 @@ static void *image_load(struct kimage *image,struct riscv_image_header *h;u64 flags;bool be_image, be_kernel; -struct kexec_buf kbuf; +struct kexec_buf kbuf = {};int ret;/* Check Image header */
arch/riscv/kernel/machine_kexec_file.c +1 -1
@@ -261,7 +261,7 @@ int load_extra_segments(struct kimage *image, unsigned long kernel_start,int ret;void *fdt;unsigned long initrd_pbase =0UL ; -struct kexec_buf kbuf; +struct kexec_buf kbuf = {};char *modified_cmdline =NULL ; kbuf.image = image;
Signature · 1 line
2.47.3
PATCH 3/3 s390: kexec: Initialize kexec_buf struct
In reply to Breno LeitaoThe kexec_buf structure was previously declared without initialization. commit bf454ec31add ("kexec_file: allow to place kexec_buf randomly") added a field that is always read but not consistently populated by all architectures. This un-initialized field will contain garbage.
This is also triggering a UBSAN warning when the uninitialized data was accessed:
------------[ cut here ]------------ UBSAN: invalid-load in ./include/linux/kexec.h:210:10 load of value 252 is not a valid value for type '_Bool'
Zero-initializing kexec_buf at declaration ensures all fields are cleanly set, preventing future instances of uninitialized memory being used.
--- arch/s390/kernel/kexec_elf.c | 2 +- arch/s390/kernel/kexec_image.c | 2 +- arch/s390/kernel/machine_kexec_file.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
arch/s390/kernel/kexec_elf.c +1 -1
@@ -16,7 +16,7 @@static int kexec_file_add_kernel_elf (struct kimage *image,struct s390_load_data *data) { -struct kexec_buf buf; +struct kexec_buf buf = {};const Elf_Ehdr *ehdr;const Elf_Phdr *phdr;Elf_Addr entry;
arch/s390/kernel/kexec_image.c +1 -1
@@ -16,7 +16,7 @@static int kexec_file_add_kernel_image (struct kimage *image,struct s390_load_data *data) { -struct kexec_buf buf; +struct kexec_buf buf = {}; buf.image = image;
arch/s390/kernel/machine_kexec_file.c +3 -3
@@ -129,7 +129,7 @@ static int kexec_file_update_purgatory(struct kimage *image,static int kexec_file_add_purgatory (struct kimage *image,struct s390_load_data *data) { -struct kexec_buf buf; +struct kexec_buf buf = {};int ret; buf.image = image;
@@ -152,7 +152,7 @@ static int kexec_file_add_purgatory(struct kimage *image,static int kexec_file_add_initrd (struct kimage *image,struct s390_load_data *data) { -struct kexec_buf buf; +struct kexec_buf buf = {};int ret; buf.image = image;
@@ -184,7 +184,7 @@ static int kexec_file_add_ipl_report(struct kimage *image, {__u32 *lc_ipl_parmblock_ptr;unsigned int len, ncerts; -struct kexec_buf buf; +struct kexec_buf buf = {};unsigned long addr;void *ptr, *end;int ret;
Signature · 1 line
2.47.3
Quoted 25 lines · Breno Leitao
The
kexec_bufstructure was previously declared without initialization. commitbf454ec31add("kexec_file: allow to placekexec_bufrandomly") added a field that is always read but not consistently populated by all architectures. This un-initialized field will contain garbage.This is also triggering a UBSAN warning when the uninitialized data was accessed:
------------[ cut here ]------------ UBSAN: invalid-load in ./include/linux/kexec.h:210:10 load of value 252 is not a valid value for type '_Bool'Zero-initializing
kexec_bufat declaration ensures all fields are cleanly set, preventing future instances of uninitialized memory being used.An initial fix was already landed for arm64[0], and this patchset fixes the problem on the remaining arm64 code and on riscv, as raised by Mark.
Discussions about this problem could be found at[1][2].
Quoted 6 lines
Signed-off-by Breno Leitao <[email protected]>---
Breno Leitao (3):
arm64: kexec: Initializekexec_bufstruct inload_other_segments()
riscv: kexec: Initializekexec_bufstruct
s390: kexec: Initializekexec_bufstruct
Thanks for the fix, all looks good to me.
Alexandre Ghiti
reviewerHi Breno,
Quoted 40 lines · Breno Leitao
The
kexec_bufstructure was previously declared without initialization. commitbf454ec31add("kexec_file: allow to placekexec_bufrandomly") added a field that is always read but not consistently populated by all architectures. This un-initialized field will contain garbage.This is also triggering a UBSAN warning when the uninitialized data was accessed:
------------[ cut here ]------------ UBSAN: invalid-load in ./include/linux/kexec.h:210:10 load of value 252 is not a valid value for type '_Bool'Zero-initializing
kexec_bufat declaration ensures all fields are cleanly set, preventing future instances of uninitialized memory being used.An initial fix was already landed for arm64[0], and this patchset fixes the problem on the remaining arm64 code and on riscv, as raised by Mark.
Discussions about this problem could be found at[1][2].
Signed-off-by Breno Leitao <[email protected]>---
Breno Leitao (3):
arm64: kexec: Initializekexec_bufstruct inload_other_segments()
riscv: kexec: Initializekexec_bufstruct
s390: kexec: Initializekexec_bufstructarch/arm64/kernel/machine_kexec_file.c | 2 +- arch/riscv/kernel/kexec_elf.c | 4 ++-- arch/riscv/kernel/kexec_image.c | 2 +- arch/riscv/kernel/machine_kexec_file.c | 2 +- arch/s390/kernel/kexec_elf.c | 2 +- arch/s390/kernel/kexec_image.c | 2 +- arch/s390/kernel/machine_kexec_file.c | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-)
Quoted 7 lines
---
base-commit:3c642997252eef4449cb6b6e02af3dc22515d817
change-id: 20250827-kbuf_all-b9d55c9291ebBest regards,
--
Breno Leitao <[email protected]>
I see that the commit those patches fix is in 6.16 so we should add cc: stable.
And who should merge those patches? Should we do it on a per-arch basis?
Thanks,
Alex
Quoted 5 lines
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 3 lines · Alexandre Ghiti
Hi Breno,
On 8/27/25 12:42, Breno Leitao wrote:
.....snip...
Quoted 5 lines
I see that the commit those patches fix is in 6.16 so we should add cc:
stable.And who should merge those patches? Should we do it on a per-arch basis?
It's been in Andrew's akpm-mm/mm-hotfixes-unstable.
Alexandre Ghiti
reviewerHi Baoquan,
Quoted 10 lines · Baoquan He
Quoted 3 lines · Alexandre Ghiti
Hi Breno,
On 8/27/25 12:42, Breno Leitao wrote:
.....snip...
Quoted 4 lines
I see that the commit those patches fix is in 6.16 so we should add cc:
stable.And who should merge those patches? Should we do it on a per-arch basis?
It's been in Andrew's akpm-mm/mm-hotfixes-unstable.
Great, thanks for letting me know.
Alex
Quoted 1 line
This series was applied to riscv/linux.git (for-next) by Paul Walmsley <[email protected]>:
Hello:
This series was applied to riscv/linux.git (for-next) by Paul Walmsley <[email protected]>:
Quoted 9 lines · On Wed, 27 Aug 2025 03:42:20 -0700 you wrote:
The
kexec_bufstructure was previously declared without initialization. commitbf454ec31add("kexec_file: allow to placekexec_bufrandomly") added a field that is always read but not consistently populated by all architectures. This un-initialized field will contain garbage.This is also triggering a UBSAN warning when the uninitialized data was accessed:
[...]
Here is the summary with links:
- [1/3] arm64: kexec: Initialize kexec_buf struct in load_other_segments() (no matching commit)
- [2/3] riscv: kexec: Initialize kexec_buf struct
https://git.kernel.org/riscv/c/95c54cd9c769
- [3/3] s390: kexec: Initialize kexec_buf struct (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html