Skip to content

Commit ab03e91

Browse files
DemiMarieardbiesheuvel
authored andcommitted
efi: memmap: Disregard bogus entries instead of returning them
The ESRT code currently contains two consistency checks on the memory descriptor it obtains, but one of them is both incomplete and can only trigger on invalid descriptors. So let's drop these checks, and instead disregard descriptors entirely if the start address is misaligned, or if the number of pages reaches to or beyond the end of the address space. Note that the memory map as a whole could still be inconsistent: multiple entries might cover the same area, or the address could be outside of the addressable PA space, but validating that goes beyond the scope of these helpers. Also note that since the physical address space is never 64-bits wide, a descriptor that includes the last page of memory is not valid. This is fortunate, since it means that a valid physical address will never be an error pointer and that the length of a memory descriptor in bytes will fit in a 64-bit unsigned integer. Co-developed-by: Ard Biesheuvel <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Demi Marie Obenour <[email protected]> Tested-by: Marek Marczykowski-Górecki <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 2cf9e27 commit ab03e91

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

drivers/firmware/efi/efi.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md)
496496
u64 size;
497497
u64 end;
498498

499+
/* skip bogus entries (including empty ones) */
500+
if ((md->phys_addr & (EFI_PAGE_SIZE - 1)) ||
501+
(md->num_pages <= 0) ||
502+
(md->num_pages > (U64_MAX - md->phys_addr) >> EFI_PAGE_SHIFT))
503+
continue;
504+
499505
size = md->num_pages << EFI_PAGE_SHIFT;
500506
end = md->phys_addr + size;
501507
if (phys_addr >= md->phys_addr && phys_addr < end) {

drivers/firmware/efi/esrt.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,15 +263,8 @@ void __init efi_esrt_init(void)
263263
return;
264264
}
265265

266-
max = efi_mem_desc_end(&md);
267-
if (max < efi.esrt) {
268-
pr_err("EFI memory descriptor is invalid. (esrt: %p max: %p)\n",
269-
(void *)efi.esrt, (void *)max);
270-
return;
271-
}
272-
266+
max = efi_mem_desc_end(&md) - efi.esrt;
273267
size = sizeof(*esrt);
274-
max -= efi.esrt;
275268

276269
if (max < size) {
277270
pr_err("ESRT header doesn't fit on single memory map entry. (size: %zu max: %zu)\n",

0 commit comments

Comments
 (0)