Skip to contentSkip to conversation

efi/libstub/x86: Free EFI map buffer in allocate_e820()

PATCH Superseded Lenny Szubowicz 2 participants 3 messages May 5, 2020 – May 7, 2020 EFI

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 efi/libstub/x86: Free EFI map buffer in allocate_e820()

In allocate_e820(), free the EFI map buffer that has been returned by efi_get_memory_map(). The returned size of the EFI map buffer is used to allocate an adequately sized e820ext buffer, if it's needed. But the contents of that EFI map buffer is not used at all and the local pointer to it is gone on return from allocate_e820().

---
 drivers/firmware/efi/libstub/x86-stub.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/firmware/efi/libstub/x86-stub.c +3 -0
index 05ccb229fb45..4efe3e7a218d 100644
@@ -623,6 +623,9 @@ static efi_status_t allocate_e820(struct boot_params *params,
 	if (status != EFI_SUCCESS)
 		return status;
 
+	/* Allocated EFI map buf is not used here. Just need its size. */
+	efi_bs_call(free_pool, map);
+
 	nr_desc = buff_size / desc_size;
 
 	if (nr_desc > ARRAY_SIZE(params->e820_table)) {
Signature · 1 line
2.18.4
maintainer
#1 lore raw
Quoted 17 lines · Lenny Szubowicz

In allocate_e820(), free the EFI map buffer that has been returned by efi_get_memory_map(). The returned size of the EFI map buffer is used to allocate an adequately sized e820ext buffer, if it's needed. But the contents of that EFI map buffer is not used at all and the local pointer to it is gone on return from allocate_e820().

---
 drivers/firmware/efi/libstub/x86-stub.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/firmware/efi/libstub/x86-stub.c +0 -0
index 05ccb229fb45..4efe3e7a218d 100644

drivers/firmware/efi/libstub/x86-stub.c static efi_status_t allocate_e820(struct boot_params *params, · line 628

Quoted 6 lines
drivers/firmware/efi/libstub/x86-stub.c +3 -0
@@ -623,6 +623,9 @@ static efi_status_t allocate_e820(struct boot_params *params,
        if (status != EFI_SUCCESS)
                return status;
 
+       /* Allocated EFI map buf is not used here. Just need its size. */
+       efi_bs_call(free_pool, map);
+

Wouldn't it be better to call BS->GetMemoryMap() directly here, with a zero size for the input buffer?

Quoted 6 lines
drivers/firmware/efi/libstub/x86-stub.c +0 -1
        nr_desc = buff_size / desc_size;
 
        if (nr_desc > ARRAY_SIZE(params->e820_table)) {
--

2.18.4

#2 lore raw
Quoted 21 lines · Ard Biesheuvel
Quoted 20 lines · Lenny Szubowicz

In allocate_e820(), free the EFI map buffer that has been returned by efi_get_memory_map(). The returned size of the EFI map buffer is used to allocate an adequately sized e820ext buffer, if it's needed. But the contents of that EFI map buffer is not used at all and the local pointer to it is gone on return from allocate_e820().

---
  drivers/firmware/efi/libstub/x86-stub.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/firmware/efi/libstub/x86-stub.c +0 -0
index 05ccb229fb45..4efe3e7a218d 100644
@@ -623,6 +623,9 @@ static efi_status_t allocate_e820(struct boot_params *params,
         if (status != EFI_SUCCESS)
                 return status;
 
Quoted 6 lines

drivers/firmware/efi/libstub/x86-stub.c static efi_status_t allocate_e820(struct boot_params *params, · line 628

Quoted 3 lines
drivers/firmware/efi/libstub/x86-stub.c +3 -0
+       /* Allocated EFI map buf is not used here. Just need its size. */
+       efi_bs_call(free_pool, map);
+

Wouldn't it be better to call BS->GetMemoryMap() directly here, with a zero size for the input buffer?

I agree, that's a good suggestion. V2 coming shortly after testing.

Quoted 8 lines
Quoted 7 lines
drivers/firmware/efi/libstub/x86-stub.c +0 -1
         nr_desc = buff_size / desc_size;
 
         if (nr_desc > ARRAY_SIZE(params->e820_table)) {
--

2.18.4