Skip to contentSkip to conversation

efistub/x86: Use struct_size() in preserve_pci_rom_image()

PATCH In review Thorsten Blum 2 participants 2 messages Nov 8 – Nov 16 EFI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efistub/x86: Use struct_size() in preserve_pci_rom_image()

Use struct_size(), which provides additional compile-time checks for structures with flexible array members (e.g., __must_be_array()), to determine the ROM allocation size.

---
 drivers/firmware/efi/libstub/x86-stub.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/firmware/efi/libstub/x86-stub.c +2 -1
index 253dd3ba8fab..5d35cfe78775 100644
@@ -7,6 +7,7 @@
  * ----------------------------------------------------------------------- */
 
 #include <linux/efi.h>
+#include <linux/overflow.h>
 #include <linux/pci.h>
 #include <linux/stddef.h>
 
@@ -62,7 +63,7 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
 	if (!romimage || !romsize || romsize > SZ_16M)
 		return EFI_INVALID_PARAMETER;
 
-	size = romsize + sizeof(*rom);
+	size = struct_size(rom, romdata, romsize);
 
 	status = efi_bs_call(allocate_pool, EFI_LOADER_DATA, size,
 			     (void **)&rom);
Acked-by on v1 1/1
#1 lore raw

Thorsten Blum <[email protected]> writes:

Hello Thorsten,

Quoted 6 lines

Use struct_size(), which provides additional compile-time checks for structures with flexible array members (e.g., __must_be_array()), to determine the ROM allocation size.

---

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat