Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

efi: Replace efi_memory_attributes_table_t 0-sized array with flexible array

While efi_memory_attributes_table_t::entry isn't used directly as an
array, it is used as a base for pointer arithmetic. The type is wrong
as it's not technically an array of efi_memory_desc_t's; they could be
larger. Regardless, leave the type unchanged and remove the old style
"0" array size. Additionally replace the open-coded entry offset code
with the existing efi_memdesc_ptr() helper.

Signed-off-by: Kees Cook <kees@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

authored by

Kees Cook and committed by
Ard Biesheuvel
4a2ebb08 887c4cf5

+6 -2
+1 -1
drivers/firmware/efi/memattr.c
··· 164 164 bool valid; 165 165 char buf[64]; 166 166 167 - valid = entry_is_valid((void *)tbl->entry + i * tbl->desc_size, 167 + valid = entry_is_valid(efi_memdesc_ptr(tbl->entry, tbl->desc_size, i), 168 168 &md); 169 169 size = md.num_pages << EFI_PAGE_SHIFT; 170 170 if (efi_enabled(EFI_DBG) || !valid)
+5 -1
include/linux/efi.h
··· 608 608 u32 num_entries; 609 609 u32 desc_size; 610 610 u32 flags; 611 - efi_memory_desc_t entry[0]; 611 + /* 612 + * There are @num_entries following, each of size @desc_size bytes, 613 + * including an efi_memory_desc_t header. See efi_memdesc_ptr(). 614 + */ 615 + efi_memory_desc_t entry[]; 612 616 } efi_memory_attributes_table_t; 613 617 614 618 typedef struct {