Re: [PATCH v2] x86/efi: defer freeing of boot services memory

Ard Biesheuvel
2026-03-20T14:32:18Z

On Fri, 20 Mar 2026, at 15:08, Mike Rapoport wrote:
> On Thu, Mar 19, 2026 at 09:06:52PM -0700, Guenter Roeck wrote:
>> Hi,
>>
>> > +void __init efi_unmap_boot_services(void)
>> > {
>> > struct efi_memory_map_data data = { 0 };
>> > efi_memory_desc_t *md;
>> > int num_entries = 0;
>> > + int idx = 0;
>> > + size_t sz;
>> > void *new, *new_md;
>> >
>> > /* Keep all regions for /sys/kernel/debug/efi */
>> > if (efi_enabled(EFI_DBG))
>> > return;
>> >
>> > + sz = sizeof(*ranges_to_free) * efi.memmap.nr_map + 1;
>>
>> Was this possibly supposed to be
>> sz = sizeof(*ranges_to_free) * (efi.memmap.nr_map + 1);
>> ^ ^
>> ?
>
> Yes, thanks for catching this.
>
> @Ard, can you please pick the fix:
>

Yep, queued up now.

Thanks for the fix.

> From 8fc5c5e828e7d127e6210bc9952451300591cdce Mon Sep 17 00:00:00 2001
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> Date: Fri, 20 Mar 2026 15:59:48 +0200
> Subject: [PATCH] x86/efi: efi_unmap_boot_services: fix calculation of
> ranges_to_free size
>
> ranges_to_free array should have enough room to store the entire EFI
> memmap plus an extra element for NULL entry.
> The calculation of this array size wrongly adds 1 to the overall size
> instead of adding 1 to the number of elements.
>
> Add parentheses to properly size the array.
>
> Reported-by: Guenter Roeck <linux@roeck-us.net>
> Fixes: a4b0bf6a40f3 ("x86/efi: defer freeing of boot services memory")
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> arch/x86/platform/efi/quirks.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c
> index 35caa5746115..79f0818131e8 100644
> --- a/arch/x86/platform/efi/quirks.c
> +++ b/arch/x86/platform/efi/quirks.c
> @@ -424,7 +424,7 @@ void __init efi_unmap_boot_services(void)
> if (efi_enabled(EFI_DBG))
> return;
>
> - sz = sizeof(*ranges_to_free) * efi.memmap.nr_map + 1;
> + sz = sizeof(*ranges_to_free) * (efi.memmap.nr_map + 1);
> ranges_to_free = kzalloc(sz, GFP_KERNEL);
> if (!ranges_to_free) {
> pr_err("Failed to allocate storage for freeable EFI regions\n");