WSL2-Linux-Kernel/arch/x86
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
..
boot arch: Introduce CONFIG_FUNCTION_ALIGNMENT 2024-04-10 16:18:49 +02:00
configs x86/kbuild: Enable CONFIG_KALLSYMS_ALL=y in the defconfigs 2022-01-27 11:04:56 +01:00
crypto crypto: x86/sha512-avx2 - add missing vzeroupper 2024-06-16 13:39:17 +02:00
entry syscalls: fix compat_sys_io_pgetevents_time64 usage 2024-07-05 09:14:50 +02:00
events perf/x86: Fix out of range data 2024-04-17 11:15:16 +02:00
hyperv x86/hyperv: Remove unregister syscore call from Hyper-V cleanup 2022-12-31 13:14:39 +01:00
ia32 binfmt: remove in-tree usage of MAP_DENYWRITE 2021-09-03 18:42:01 +02:00
include efi/x86: Free EFI memory map only when installing a new one. 2024-07-05 09:14:51 +02:00
kernel x86: stop playing stack games in profile_pc() 2024-07-05 09:14:45 +02:00
kvm KVM: x86: Always sync PIR to IRR prior to scanning I/O APIC routes 2024-07-05 09:14:34 +02:00
lib x86/insn: Fix PUSH instruction in x86 instruction decoder opcode map 2024-06-16 13:39:31 +02:00
math-emu x86: Prepare asm files for straight-line-speculation 2022-05-15 20:18:49 +02:00
mm x86/mm: Remove broken vsyscall emulation code from the page fault code 2024-06-16 13:39:15 +02:00
net x86/returnthunk: Allow different return thunks 2024-03-01 13:21:49 +01:00
pci x86/PCI: Add quirk for AMD XHCI controller that loses MSI-X state in D3hot 2023-04-20 12:13:55 +02:00
platform efi/x86: Free EFI memory map only when installing a new one. 2024-07-05 09:14:51 +02:00
power x86/pm: Add enumeration check before spec MSRs save/restore setup 2022-12-02 17:41:09 +01:00
purgatory x86/purgatory: Switch to the position-independent small code model 2024-06-16 13:39:22 +02:00
ras
realmode x86/mm: Flush global TLB when switching to trampoline page-table 2022-01-27 11:04:35 +01:00
tools x86/boot: Ignore relocations in .notes sections in walk_relocs() too 2024-06-16 13:39:18 +02:00
um x86: um: vdso: Add '%rcx' and '%r11' to the syscall clobber list 2023-03-11 13:57:26 +01:00
video
xen x86/xen: Add some null pointer checking to smp.c 2024-03-26 18:21:12 -04:00
.gitignore
Kbuild
Kconfig cpu: Re-enable CPU mitigations by default for !X86 architectures 2024-05-02 16:24:48 +02:00
Kconfig.assembler
Kconfig.cpu x86/Kconfig: Transmeta Crusoe is CPU family 5, not 6 2024-02-23 08:55:08 +01:00
Kconfig.debug x86/kconfig: Select ARCH_WANT_FRAME_POINTERS again when UNWINDER_FRAME_POINTER=y 2024-06-16 13:39:46 +02:00
Makefile x86/realmode: build with -D__DISABLE_EXPORTS 2022-07-23 12:53:56 +02:00
Makefile.um um: allow not setting extra rpaths in the linux binary 2021-06-17 21:54:15 +02:00
Makefile_32.cpu x86/build: Do not add -falign flags unconditionally for clang 2021-09-19 10:35:53 +09:00