x86/efi: defer freeing of boot services memory
Linux
Affected versions
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
Linux
| Product | Affected | Fixed in |
|---|---|---|
| Linux Linux |
|
≥ 916f676f8dc016103f983c7ec54c18ecdbb6e349 · < 399da820ecfe6f4f10c143e5c453d3559a04db9c| No fix yet |
| Linux Linux |
|
|
In the Linux kernel, the following vulnerability has been resolved:
x86/efi: defer freeing of boot services memory
efi_free_boot_services() frees memory occupied by EFI_BOOT_SERVICES_CODE and EFI_BOOT_SERVICES_DATA using memblock_free_late().
There are two issue with that: memblock_free_late() should be used for memory allocated with memblock_alloc() while the memory reserved with memblock_reserve() should be freed with free_reserved_area().
More acutely, with CONFIG_DEFERRED_STRUCT_PAGE_INIT=y efi_free_boot_services() is called before deferred initialization of the memory map is complete.
Benjamin Herrenschmidt reports that this causes a leak of ~140MB of RAM on EC2 t3a.nano instances which only have 512MB or RAM.
If the freed memory resides in the areas that memory map for them is still uninitialized, they won't be actually freed because memblock_free_late() calls memblock_free_pages() and the latter skips uninitialized pages.
Using free_reserved_area() at this point is also problematic because __free_page() accesses the buddy of the freed page and that again might end up in uninitialized part of the memory map.
From the CVE record · Linux
On systems with deferred page initialization enabled, the Linux kernel may fail to free EFI boot services memory during boot. This can leak substantial RAM; the input does not describe an attacker-controlled path, authentication requirement, or user interaction.
Operators running the Linux kernel on x86 systems with EFI and CONFIG_DEFERRED_STRUCT_PAGE_INIT enabled should check their installations; affected versions are not specified.