Skip to content

Commit b89114c

Browse files
committed
efi: mokvar-table: fix some issues in new code
Fix a couple of issues in the new mokvar-table handling code, as pointed out by Arvind and Boris: - don't bother checking the end of the physical region against the start address of the mokvar table, - ensure that we enter the loop with err = -EINVAL, - replace size_t with unsigned long to appease pedantic type equality checks. Reviewed-by: Arvind Sankar <nivedita@alum.mit.edu> Reviewed-by: Lenny Szubowicz <lszubowi@redhat.com> Tested-by: Borislav Petkov <bp@suse.de> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 612b5d5 commit b89114c

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

drivers/firmware/efi/mokvar-table.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,14 @@ static struct kobject *mokvar_kobj;
9898
void __init efi_mokvar_table_init(void)
9999
{
100100
efi_memory_desc_t md;
101-
u64 end_pa;
102101
void *va = NULL;
103-
size_t cur_offset = 0;
104-
size_t offset_limit;
105-
size_t map_size = 0;
106-
size_t map_size_needed = 0;
107-
size_t size;
102+
unsigned long cur_offset = 0;
103+
unsigned long offset_limit;
104+
unsigned long map_size = 0;
105+
unsigned long map_size_needed = 0;
106+
unsigned long size;
108107
struct efi_mokvar_table_entry *mokvar_entry;
109-
int err = -EINVAL;
108+
int err;
110109

111110
if (!efi_enabled(EFI_MEMMAP))
112111
return;
@@ -122,18 +121,16 @@ void __init efi_mokvar_table_init(void)
122121
pr_warn("EFI MOKvar config table is not within the EFI memory map\n");
123122
return;
124123
}
125-
end_pa = efi_mem_desc_end(&md);
126-
if (efi.mokvar_table >= end_pa) {
127-
pr_err("EFI memory descriptor containing MOKvar config table is invalid\n");
128-
return;
129-
}
130-
offset_limit = end_pa - efi.mokvar_table;
124+
125+
offset_limit = efi_mem_desc_end(&md) - efi.mokvar_table;
126+
131127
/*
132128
* Validate the MOK config table. Since there is no table header
133129
* from which we could get the total size of the MOK config table,
134130
* we compute the total size as we validate each variably sized
135131
* entry, remapping as necessary.
136132
*/
133+
err = -EINVAL;
137134
while (cur_offset + sizeof(*mokvar_entry) <= offset_limit) {
138135
mokvar_entry = va + cur_offset;
139136
map_size_needed = cur_offset + sizeof(*mokvar_entry);
@@ -150,7 +147,7 @@ void __init efi_mokvar_table_init(void)
150147
offset_limit);
151148
va = early_memremap(efi.mokvar_table, map_size);
152149
if (!va) {
153-
pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%zu.\n",
150+
pr_err("Failed to map EFI MOKvar config table pa=0x%lx, size=%lu.\n",
154151
efi.mokvar_table, map_size);
155152
return;
156153
}

0 commit comments

Comments
 (0)