Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 4a2ebb0

Browse files
keesardbiesheuvel
authored andcommitted
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>
1 parent 887c4cf commit 4a2ebb0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

drivers/firmware/efi/memattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int __init efi_memattr_apply_permissions(struct mm_struct *mm,
164164
bool valid;
165165
char buf[64];
166166

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),
168168
&md);
169169
size = md.num_pages << EFI_PAGE_SHIFT;
170170
if (efi_enabled(EFI_DBG) || !valid)

include/linux/efi.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,11 @@ typedef struct {
608608
u32 num_entries;
609609
u32 desc_size;
610610
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[];
612616
} efi_memory_attributes_table_t;
613617

614618
typedef struct {

0 commit comments

Comments
 (0)