Commit Graph

10 Commits

Author SHA1 Message Date
Alexey Makhalov f7bd9986f6 efi: Fix use-after-free in halt/reboot path
commit 92bfc33db9 ("efi: Free malloc regions on exit")
introduced memory freeing in grub_efi_fini(), which is
used not only by exit path but by halt/reboot one as well.
As result of memory freeing, code and data regions used by
modules, such as halt, reboot, acpi (used by halt) also got
freed. After return to module code, CPU executes, filled
by UEFI firmware (tested with edk2), 0xAFAFAFAF pattern as
a code. Which leads to #UD exception later.

grub> halt
!!!! X64 Exception Type - 06(#UD - Invalid Opcode)  CPU Apic ID - 00000000 !!!!
RIP  - 0000000003F4EC28, CS  - 0000000000000038, RFLAGS - 0000000000200246
RAX  - 0000000000000000, RCX - 00000000061DA188, RDX - 0A74C0854DC35D41
RBX  - 0000000003E10E08, RSP - 0000000007F0F860, RBP - 0000000000000000
RSI  - 00000000064DB768, RDI - 000000000832C5C3
R8   - 0000000000000002, R9  - 0000000000000000, R10 - 00000000061E2E52
R11  - 0000000000000020, R12 - 0000000003EE5C1F, R13 - 00000000061E0FF4
R14  - 0000000003E10D80, R15 - 00000000061E2F60
DS   - 0000000000000030, ES  - 0000000000000030, FS  - 0000000000000030
GS   - 0000000000000030, SS  - 0000000000000030
CR0  - 0000000080010033, CR2 - 0000000000000000, CR3 - 0000000007C01000
CR4  - 0000000000000668, CR8 - 0000000000000000
DR0  - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
DR3  - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
GDTR - 00000000079EEA98 0000000000000047, LDTR - 0000000000000000
IDTR - 0000000007598018 0000000000000FFF,   TR - 0000000000000000
FXSAVE_STATE - 0000000007F0F4C0

Proposal here is to continue to free allocated memory for
exit boot services path but keep it for halt/reboot path
as it won't be much security concern here.
Introduced GRUB_LOADER_FLAG_EFI_KEEP_ALLOCATED_MEMORY
loader flag to be used by efi halt/reboot path.

Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2020-07-29 16:55:48 +02:00
Vladimir Serbinenko 78b2b0a1a0 * grub-core/kern/ia64/efi/init.c (grub_arch_sync_caches): Move to ...
* grub-core/kern/ia64/cache.c (grub_arch_sync_caches): ... here.
2013-12-08 18:27:40 +01:00
Vladimir Serbinenko fbbfb6ab11 * grub-core/kern/ia64/efi/init.c: Fix alignment code so it doesn't
truncate incomplete lines but instead flushes them.
2013-12-08 18:10:05 +01:00
Vladimir Serbinenko 631187be8c Add missing includes of loader.h. 2013-11-11 02:30:09 +01:00
Vladimir Serbinenko 9612ebc00e Add new ports: i386-xen and x86_64-xen. This allows running GRUB in
XEN PV environment and load kernels.
2013-11-09 21:29:11 +01:00
Vladimir 'phcoder' Serbinenko 9e5e66d15e Use ITC on IA64 rather than broken routine based on daytime.
* grub-core/kern/efi/efi.c (grub_rtc_get_time_ms) [__ia64__]: Remove on
	ia64.
	(grub_get_rtc) [__ia64__]: Likewise.
	* grub-core/kern/ia64/efi/init.c (divisor): New variable.
	(get_itc): New function.
	(grub_rtc_get_time_ms): Likewise.
	(grub_machine_init): Calibrate ITC.
	* include/grub/efi/time.h (grub_get_rtc), (GRUB_TICKS_PER_SECOND):
	Keep only on non-ia64. Don't export since it's broken and used only
	if TSC is unavailable.
2012-06-09 10:52:39 +02:00
Vladimir 'phcoder' Serbinenko 574618a2e9 unify prefix handling across platforms 2011-07-02 14:09:36 +02:00
Vladimir 'phcoder' Serbinenko fa610088ba Add missing time installation 2011-05-08 17:06:28 +02:00
phcoder c18271ed00 Fix compilation errors 2011-01-03 02:28:14 +01:00
Vladimir 'phcoder' Serbinenko 6585de4c0c merge mainline into ia64 2010-08-31 21:47:26 +02:00