efi: Replace efi_memory_attributes_table_t 0-sized array with flexible array
PATCH 1/1 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_early_memdesc_ptr() helper.
---
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]
--- drivers/firmware/efi/memattr.c | 2 +- include/linux/efi.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/firmware/efi/memattr.c +1 -1
@@ -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_early_memdesc_ptr (tbl->entry, tbl->desc_size, i), &md); size = md.num_pages <<EFI_PAGE_SHIFT ;if (efi_enabled (EFI_DBG ) || !valid)
include/linux/efi.h +5 -1
@@ -607,7 +607,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. +*/ +efi_memory_desc_t entry[]; } efi_memory_attributes_table_t; typedef struct {
Signature · 1 line
2.34.1
Quoted 34 lines · Kees Cook
While
efi_memory_attributes_table_t::entryisn'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 existingefi_early_memdesc_ptr()helper.Signed-off-by Kees Cook <[email protected]>---
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]--- drivers/firmware/efi/memattr.c | 2 +- include/linux/efi.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-)drivers/firmware/efi/memattr.c +1
-1@@ -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_early_memdesc_ptr (tbl->entry, tbl->desc_size, i), &md); size = md.num_pages <<EFI_PAGE_SHIFT ;if (efi_enabled (EFI_DBG ) || !valid)include/linux/efi.h +0
-0
include/linux/efi.h typedef struct { · line 614
Quoted 9 lines
include/linux/efi.h +5
-1@@ -607,7 +607,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. +*/ +efi_memory_desc_t entry[];
a candidate for future __counted_by(num_entries * desc_size) ? :p
Thanks
Signature · 1 line
Gustavo
Quoted 3 lines
include/linux/efi.h +0
-0} efi_memory_attributes_table_t; typedef struct {
Quoted 39 lines · Gustavo A. R. Silva
Quoted 36 lines · Kees Cook
While
efi_memory_attributes_table_t::entryisn'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 existingefi_early_memdesc_ptr()helper.Signed-off-by Kees Cook <[email protected]>---
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]
---
drivers/firmware/efi/memattr.c| 2 +-
include/linux/efi.h | 6 +++++-2 files changed, 6 insertions(+), 2 deletions(-)drivers/firmware/efi/memattr.c +1
-1@@ -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_early_memdesc_ptr(tbl->entry, tbl->desc_size, i), &md); size = md.num_pages << EFI_PAGE_SHIFT; if (efi_enabled(EFI_DBG) || !valid)include/linux/efi.h +0
-0@@ -607,7 +607,11 @@ typedef struct { u32 num_entries; u32 desc_size; u32 flags;
Quoted 8 lines
include/linux/efi.h typedef struct { · line 614
Quoted 6 lines
include/linux/efi.h +5
-1- efi_memory_desc_t entry[0]; + /* + * There are @num_entries following, each of size @desc_size bytes, + * including an efi_memory_desc_t header. + */ + efi_memory_desc_t entry[];a candidate for future
__counted_by(num_entries * desc_size)? :p
ah no, this rather be something more like __sized_by(num_entries * desc_size).
--
Gustavo
Quoted 4 lines
Reviewed-by Gustavo A. R. Silva <[email protected]>Thanks
Ard Biesheuvel
maintainerQuoted 52 lines · Gustavo A. R. Silva
Quoted 39 lines · Gustavo A. R. Silva
Quoted 36 lines · Kees Cook
While
efi_memory_attributes_table_t::entryisn'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 existingefi_early_memdesc_ptr()helper.Signed-off-by Kees Cook <[email protected]>---
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]--- drivers/firmware/efi/memattr.c | 2 +- include/linux/efi.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-)drivers/firmware/efi/memattr.c +1
-1@@ -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_early_memdesc_ptr (tbl->entry, tbl->desc_size, i), &md); size = md.num_pages <<EFI_PAGE_SHIFT ;if (efi_enabled (EFI_DBG ) || !valid)include/linux/efi.h +0
-0@@ -607,7 +607,11 @@ typedef struct {u32 num_entries;u32 desc_size;u32 flags;Quoted 8 lines
include/linux/efi.h typedef struct { · line 614
Quoted 6 lines
include/linux/efi.h +5
-1-efi_memory_desc_t entry[0 ]; +/* +* There are @num_entries following, each of size @desc_size bytes, +* including an efi_memory_desc_t header. +*/ +efi_memory_desc_t entry[];a candidate for future
__counted_by(num_entries * desc_size)? :p
Quoted 8 lines
ah no, this rather be something more like
__sized_by(num_entries * desc_size).--
GustavoQuoted 3 lines
Reviewed-by Gustavo A. R. Silva <[email protected]>
Thanks. I'll take this for the next cycle, but would you mind adding a preceding patch that drops the 'early' from the macro name and updates the existing users (not the ones in arch/x88/boot, which has its own private copy for some reason). The 'early' is kind of irrelevant, and no longer accurate now that we use the macro for the memory attributes table as well as the memory map.