]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
efi: Replace efi_memory_attributes_table_t 0-sized array with flexible array
authorKees Cook <kees@kernel.org>
Thu, 11 Jul 2024 17:11:13 +0000 (10:11 -0700)
committerArd Biesheuvel <ardb@kernel.org>
Fri, 12 Jul 2024 08:06:01 +0000 (10:06 +0200)
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>
drivers/firmware/efi/memattr.c
include/linux/efi.h

index ab85bf8e165a357524bb970b9cadf9b4549c0872..164203429fa7a3e8759529c96941ce11e973742e 100644 (file)
@@ -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)
index 67b2fa80c8b95262eafb5c6de55840c75b9b4309..6bf3c4fe85117ec57db8a51c532a1a62beb72217 100644 (file)
@@ -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 {