WSL2-Linux-Kernel/drivers/firmware/efi
Ard Biesheuvel da38b55cd5 efi/x86: Free EFI memory map only when installing a new one.
[ Commit 75dde792d6f6c2d0af50278bd374bf0c512fe196 upstream ]

The logic in __efi_memmap_init() is shared between two different
execution flows:
- mapping the EFI memory map early or late into the kernel VA space, so
  that its entries can be accessed;
- the x86 specific cloning of the EFI memory map in order to insert new
  entries that are created as a result of making a memory reservation
  via a call to efi_mem_reserve().

In the former case, the underlying memory containing the kernel's view
of the EFI memory map (which may be heavily modified by the kernel
itself on x86) is not modified at all, and the only thing that changes
is the virtual mapping of this memory, which is different between early
and late boot.

In the latter case, an entirely new allocation is created that carries a
new, updated version of the kernel's view of the EFI memory map. When
installing this new version, the old version will no longer be
referenced, and if the memory was allocated by the kernel, it will leak
unless it gets freed.

The logic that implements this freeing currently lives on the code path
that is shared between these two use cases, but it should only apply to
the latter. So move it to the correct spot.

While at it, drop the dummy definition for non-x86 architectures, as
that is no longer needed.

Cc: <stable@vger.kernel.org>
Fixes: f0ef652347 ("efi: Fix efi_memmap_alloc() leaks")
Tested-by: Ashish Kalra <Ashish.Kalra@amd.com>
Link: https://lore.kernel.org/all/36ad5079-4326-45ed-85f6-928ff76483d3@amd.com
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-07-05 09:14:51 +02:00
..
libstub x86/efistub: Fix PCI ROM preservation in mixed mode 2023-09-19 12:22:31 +02:00
test
Kconfig
Makefile
apple-properties.c
arm-runtime.c efi: runtime: Fix potential overflow of soft-reserved region size 2024-03-01 13:21:47 +01:00
capsule-loader.c efi/capsule-loader: fix incorrect allocation size 2024-03-06 14:38:48 +00:00
capsule.c
cper-arm.c
cper-x86.c
cper.c
dev-path-parser.c
earlycon.c
efi-bgrt.c
efi-init.c efi: Don't add memblocks for soft-reserved memory 2024-03-01 13:21:47 +01:00
efi-pstore.c
efi.c efi: fix potential NULL deref in efi_mem_reserve_persistent 2023-02-09 11:26:38 +01:00
efibc.c
efivars.c
embedded-firmware.c
esrt.c
fake_mem.c
fake_mem.h
fdtparams.c efi: xen: Set EFI_PARAVIRT for Xen dom0 boot on all architectures 2024-07-05 09:14:51 +02:00
memattr.c efi: Accept version 2 of memory attributes table 2023-02-09 11:26:41 +01:00
memmap.c efi/x86: Free EFI memory map only when installing a new one. 2024-07-05 09:14:51 +02:00
mokvar-table.c
rci2-table.c
reboot.c
riscv-runtime.c efi: runtime: Fix potential overflow of soft-reserved region size 2024-03-01 13:21:47 +01:00
runtime-map.c
runtime-wrappers.c efi: fix userspace infinite retry read efivars after EFI runtime services page fault 2023-01-24 07:22:42 +01:00
sysfb_efi.c efi: sysfb_efi: Add quirk for Lenovo Yoga Book X91F/L 2023-04-20 12:13:54 +02:00
tpm.c efi/tpm: Pass correct address to memblock_reserve 2022-11-10 18:15:35 +01:00
vars.c efivarfs: Request at most 512 bytes for variable names 2024-04-10 16:19:30 +02:00
x86_fake_mem.c