mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] efistub/x86: Use struct_size() for setup_data sizes
@ 2026-09-15 22:03 Thorsten Blum
  2026-09-15 22:03 ` [PATCH 2/2] x86/setup: " Thorsten Blum
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-09-15 22:03 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin, Ard Biesheuvel, Ilias Apalodimas,
	Mike Rapoport (Microsoft),
	Andrew Morton, Arnd Bergmann, Thomas Zimmermann,
	Pratyush Yadav (Google),
	Breno Leitao, Harshit Mogalapalli, Javier Martinez Canillas,
	Francesco Pompo, Lenny Szubowicz, Vincent Mailhol, Thorsten Blum
  Cc: linux-kernel, linux-efi, x86

Use struct_size(), which provides additional compile-time checks for
structures with flexible array members (e.g., __must_be_array()), to
calculate struct setup_data sizes.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 drivers/firmware/efi/libstub/x86-stub.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index dbfbe8a74ab2..d399ab9aa8f3 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -7,6 +7,7 @@
  * ----------------------------------------------------------------------- */
 
 #include <linux/efi.h>
+#include <linux/overflow.h>
 #include <linux/pci.h>
 #include <linux/stddef.h>
 
@@ -176,7 +177,7 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params)
 
 	do {
 		status = efi_bs_call(allocate_pool, EFI_LOADER_DATA,
-				     size + sizeof(struct setup_data),
+				     struct_size(new, data, size),
 				     (void **)&new);
 		if (status != EFI_SUCCESS) {
 			efi_err("Failed to allocate memory for 'properties'\n");
@@ -649,8 +650,8 @@ setup_e820(struct boot_params *params, struct setup_data *e820ext, u32 e820ext_s
 		}
 
 		if (nr_entries == ARRAY_SIZE(params->e820_table)) {
-			u32 need = (nr_desc - i) * sizeof(struct boot_e820_entry) +
-				   sizeof(struct setup_data);
+			u32 need = struct_size(e820ext, data,
+				(nr_desc - i) * sizeof(struct boot_e820_entry));
 
 			if (!e820ext || e820ext_size < need)
 				return EFI_BUFFER_TOO_SMALL;
@@ -684,8 +685,7 @@ static efi_status_t alloc_e820ext(u32 nr_desc, struct setup_data **e820ext,
 	efi_status_t status;
 	unsigned long size;
 
-	size = sizeof(struct setup_data) +
-		sizeof(struct boot_e820_entry) * nr_desc;
+	size = struct_size(*e820ext, data, nr_desc * sizeof(struct boot_e820_entry));
 
 	if (*e820ext) {
 		efi_bs_call(free_pool, *e820ext);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] x86/setup: Use struct_size() for setup_data sizes
  2026-09-15 22:03 [PATCH 1/2] efistub/x86: Use struct_size() for setup_data sizes Thorsten Blum
@ 2026-09-15 22:03 ` Thorsten Blum
  0 siblings, 0 replies; 2+ messages in thread
From: Thorsten Blum @ 2026-09-15 22:03 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
	H. Peter Anvin, Ard Biesheuvel, Ilias Apalodimas,
	Mike Rapoport (Microsoft),
	Andrew Morton, Arnd Bergmann, Thomas Zimmermann,
	Pratyush Yadav (Google),
	Breno Leitao, Harshit Mogalapalli, Javier Martinez Canillas,
	Francesco Pompo, Lenny Szubowicz, x86, Thorsten Blum
  Cc: linux-kernel, linux-efi, Ingo Molnar

Use struct_size(), which provides additional compile-time checks for
structures with flexible array members (e.g., __must_be_array()), to
calculate struct setup_data sizes.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 arch/x86/kernel/setup.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index cda6adb9f69c..20facddee922 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -19,6 +19,7 @@
 #include <linux/iscsi_ibft.h>
 #include <linux/kexec_handover.h>
 #include <linux/memblock.h>
+#include <linux/overflow.h>
 #include <linux/panic_notifier.h>
 #include <linux/pci.h>
 #include <linux/random.h>
@@ -487,7 +488,7 @@ static void __init parse_setup_data(void)
 		u32 data_len, data_type;
 
 		data = early_memremap(pa_data, sizeof(*data));
-		data_len = data->len + sizeof(struct setup_data);
+		data_len = struct_size(data, data, data->len);
 		data_type = data->type;
 		pa_next = data->next;
 		early_memunmap(data, sizeof(*data));
@@ -584,7 +585,7 @@ static void __init memblock_x86_reserve_range_setup_data(void)
 		len = sizeof(*data);
 		pa_next = data->next;
 
-		memblock_reserve_kern(pa_data, sizeof(*data) + data->len);
+		memblock_reserve_kern(pa_data, struct_size(data, data, data->len));
 
 		if (data->type == SETUP_INDIRECT) {
 			len += data->len;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-15 22:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-15 22:03 [PATCH 1/2] efistub/x86: Use struct_size() for setup_data sizes Thorsten Blum
2026-09-15 22:03 ` [PATCH 2/2] x86/setup: " Thorsten Blum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®