Skip to content

Commit

Permalink
efi: Replace efi_memory_attributes_table_t 0-sized array with flexibl…
Browse files Browse the repository at this point in the history
…e 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>
  • Loading branch information
Kees Cook authored and Ard Biesheuvel committed Jul 12, 2024
1 parent 887c4cf commit 4a2ebb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/firmware/efi/memattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int __init efi_memattr_apply_permissions(struct mm_struct *mm,
bool valid;
char buf[64];

valid = entry_is_valid((void *)tbl->entry + i * tbl->desc_size,
valid = entry_is_valid(efi_memdesc_ptr(tbl->entry, tbl->desc_size, i),
&md);
size = md.num_pages << EFI_PAGE_SHIFT;
if (efi_enabled(EFI_DBG) || !valid)
Expand Down
6 changes: 5 additions & 1 deletion include/linux/efi.h
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,11 @@ typedef struct {
u32 num_entries;
u32 desc_size;
u32 flags;
efi_memory_desc_t entry[0];
/*
* There are @num_entries following, each of size @desc_size bytes,
* including an efi_memory_desc_t header. See efi_memdesc_ptr().
*/
efi_memory_desc_t entry[];
} efi_memory_attributes_table_t;

typedef struct {
Expand Down

0 comments on commit 4a2ebb0

Please sign in to comment.