Commit Graph

67 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
Marc Zyngier 6a34fdb76a arm: Fix 32-bit ARM handling of the CTR register
When booting on an ARMv8 core that implements either CTR.IDC or CTR.DIC
(indicating that some of the cache maintenance operations can be
removed when dealing with I/D-cache coherency, GRUB dies with a
"Unsupported cache type 0x........" message.

This is pretty likely to happen when running in a virtual machine
hosted on an arm64 machine (I've triggered it on a system built around
a bunch of Cortex-A55 cores, which implements CTR.IDC).

It turns out that the way GRUB deals with the CTR register is a bit
harsh for anything from ARMv7 onwards. The layout of the register is
backward compatible, meaning that nothing that gets added is allowed to
break earlier behaviour. In this case, ignoring IDC is completely fine,
and only results in unnecessary cache maintenance.

We can thus avoid being paranoid, and align the 32bit behaviour with
its 64bit equivalent.

This patch has the added benefit that it gets rid of a (gnu-specific)
case range too.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2020-05-25 15:02:51 +02:00
Leif Lindholm 77808dd66b arm: Delete unused efi support from loader/arm
The 32-bit arm efi port now shares the 64-bit linux loader, so delete
the now unused bits from the 32-bit linux loader.

This in turn leaves the grub-core/kern/arm/efi/misc.c unused, so
delete that too.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
2018-07-25 14:18:11 +02:00
Vladimir Serbinenko 4bc909bf89 Remove grub_efi_allocate_pages.
grub_efi_allocate_pages Essentially does 2 unrelated things:
* Allocate at fixed address.
* Allocate at any address.

To switch between 2 different functions it uses address == 0 as magic
value which is wrong as 0 is a perfectly valid fixed adress to allocate at.
2017-08-07 18:33:29 +02:00
Vladimir Serbinenko c6eaa982d1 Missing parts of previous commit 2017-05-09 09:02:15 +02:00
Vladimir Serbinenko b0b1b81a11 rk3288_spi: Add SPI driver 2017-05-09 08:44:23 +02:00
Vladimir Serbinenko 265292f2b0 arm_coreboot: Support DMA.
This is needed to support USB and some other busses.
2017-05-08 22:06:04 +02:00
Vladimir Serbinenko 848bed9d92 arm_coreboot: Support keyboard for vexpress. 2017-05-08 21:42:37 +02:00
Vladimir Serbinenko 5a865b3786 arm-coreboot: Support for vexpress timer. 2017-05-08 21:26:36 +02:00
Vladimir Serbinenko fcbb723d4b Add support for device-tree-based drivers. 2017-05-08 21:19:59 +02:00
Vladimir Serbinenko 24e37a8852 arm-coreboot: Start new port. 2017-05-08 20:53:28 +02:00
Vladimir Serbinenko d08c968514 Refactor arm-uboot code to make it genereic.
arm-coreboot startup code can be very similar to arm-uboot but current code has
U-Boot specific references. So split U-Boot part from generic part.
2017-05-08 17:47:57 +02:00
Vladimir Serbinenko 42e24b6006 Fix thumb compilation with clang.
According to EABI only STT_FUNC has convention of lowest bit indicating
execution mode. R_THM_{JUMP,CALL}* relocations are assumed to be pointing
to thumb mode unless they use STT_FUNC.
2017-02-02 00:59:49 +01:00
Vladimir Serbinenko 3d173955f0 arm: Fix trampoline generation.
We used the wrong pointer in this case. It worked only by accident.
2017-02-01 15:58:36 +01:00
Vladimir Serbinenko 86ef66d977 arm-uboot: Make self-relocatable to allow loading at any address 2016-02-27 13:40:52 +01:00
Mark Salter 7eb27a49e9 arm-efi: Reduce timer event frequency by 10
Timer event to keep grub msec counter was running at 1000HZ. This was too
fast for UEFI timer driver and resulted in a 10x slowdown in grub time
versus wallclock. Reduce the timer event frequency and increase tick
increment accordingly to keep better time.
2016-01-07 20:54:20 +01:00
Mark Salter c945ca75c3 Fix exit to EFI firmware
The current code for EFI grub_exit() calls grub_efi_fini() before
returning to firmware. In the case of ARM, this leaves a timer
event running which could lead to a firmware crash. This patch
changes this so that grub_machine_fini() is called with a NORETURN
flag. This allows machine-specific shutdown to happen as well
as the shutdown done by grub_efi_fini().

Signed-off-by: Mark Salter <msalter@redhat.com>
2015-06-12 13:08:36 +03:00
Leif Lindholm d47e8ab4b9 dl_helper: Cleanup
Use the new thumb_get_instruction_word/thumb_set_instruction_word
helpers throughout.

Style cleanup (missing spaces).

Move Thumb MOVW/MOVT handlers into Thumb relocation section of file.
2015-03-27 14:37:16 +01:00
Vladimir Serbinenko 064360e667 Remove libgcc dependency.
libgcc for boot environment isn't always present and compatible.
libgcc is often absent if endianness or bit-size at boot is different
from running OS.
libgcc may use optimised opcodes that aren't available on boot time.
So instead of relying on libgcc shipped with the compiler, supply
the functions in GRUB directly.
Tests are present to ensure that those replacement functions behave the
way compiler expects them to.
2015-03-03 20:50:37 +01:00
Vladimir Serbinenko 38b7a30269 arm/dl: Fix handling of nonstandard relocation sizes 2015-02-26 22:10:29 +01:00
Vladimir Serbinenko f034fab620 Supply signed division to fix ARM compilation.
Previously we supplied only unsigned divisions on platforms that need software
division.
Yet compiler may itself use a signed division. A typical example would be a
difference between 2 pointers which involves division by object size.
2015-02-23 04:12:04 +01:00
Leif Lindholm c0f529ea67 arm: implement additional relocations generated by gcc 4.9 at -O3
GCC 4.9 also generates R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_ABS,
as an alternative to ABS32.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
2015-02-03 22:50:08 +00:00
David Kozub 17328db3b3 grub-core/kern/arm/misc.S: fix unaligned grub_uint64_t local variable
The unaligned local in __aeabi_uidivmod leads to a store to a 64bit
value at an address that is not divisible by 8 (in grub_divmod64).
The compiler most likely generates a STRD instruction to store it and
this causes an exception.

Fixes Savannah bug #43632.

This includes improvements done by Leif Lindholm.
2014-12-07 20:16:29 +03:00
Vladimir Serbinenko 5bda44d7f9 * grub-core/kern/arm/cache_armv6.S: Remove .arch directive.
As these functions are used on pre-ARMv6 CPUs as well we don't want
	to make assembler assume that architecture is higher than default one.
2013-12-25 23:31:42 +01:00
Vladimir Serbinenko bbc52c228f Enable cache on ARM U-Boot port.
Without it the port is reidiculously slow.
2013-12-23 05:01:58 +01:00
Vladimir Serbinenko 943981ff65 Fix ARM cache maintainance.
More code was converted from ASM to C for easier handling.
2013-12-23 04:27:53 +01:00
Vladimir Serbinenko adabfb5418 * grub-core/kern/arm/cache.c (grub_arm_disable_caches_mmu): Use v6
algorithm on v5.

	Suggested by: Leif Lindholm.
2013-12-22 22:33:35 +01:00
Vladimir Serbinenko 74fa9417e5 * grub-core/kern/arm/dl.c: Remove unnecessarry execution mode check. 2013-12-18 07:06:23 +01:00
Vladimir Serbinenko d45067a290 Add explicit thumb interwork bx in asm files.
Shouldn't matter for armv >= 5 but let's be safe.
2013-12-17 14:50:44 +01:00
Vladimir Serbinenko 8c534b85f1 Revamp relocation handling.
Move more code to common dl.c. Add missing veneers for arm and arm64.
	Decreases kernel size by 70 bytes on i386-pc (40-50 compressed)
2013-12-06 09:18:55 +01:00
Vladimir Serbinenko 9ef81064a3 * grub-core/kern/arm/cache.S: Don't switch back to ARM mode when
compiling to thumb2.
	* grub-core/kern/arm/cache_armv7.S: Likewise.
	* grub-core/lib/arm/setjmp.S: Likewise.
2013-11-16 17:37:06 +01:00
Leif Lindholm 11a7793221 arm: delete superflouous save of r8 in grub_uboot_syscall 2013-11-16 15:56:09 +00:00
Leif Lindholm 593865b907 arm: fix u-boot port syscall interface va_arg handling
Commit c9cd02c broke the u-boot syscall API for va_args that spill over
to the stack, causing the disk support to stop working. This patch
resolves the problem, while keeping the new, cleaner transition_space
handling.
2013-11-16 14:12:12 +00:00
Vladimir Serbinenko 57ffe93485 * grub-core/kern/arm/cache_armv6.S: Remove special handling for
clang (not necessarry with -no-integrated-as).
	* include/grub/symbol.h [__arm__]: Likewise.
2013-11-14 10:05:19 +01:00
Leif Lindholm 035a26c16a * grub-core/kern/arm/misc.S: Make thumb2-compatible. 2013-11-14 01:33:06 +01:00
Vladimir Serbinenko 2bdd07195c * grub-core/kern/arm/cache.c (probe_caches): Move asm part to ...
* grub-core/kern/arm/cache_armv6.S: ... here. This allows this
	asm to stay in arm even if surrounding is thumb.
2013-11-13 09:58:52 +01:00
Vladimir Serbinenko 5e77d9cfc1 * grub-core/kern/arm/misc.S: Add __muldi3 and __aeabi_lmul. Those
helper functions are needed for thumb.
2013-11-13 09:52:33 +01:00
Vladimir Serbinenko c9cd02c965 * grub-core/kern/arm/uboot/startup.S: Remove = by replacing with
literal load.
	(grub_uboot_syscall): Save/restore r9 and align stack.
2013-11-13 06:27:03 +01:00
Vladimir Serbinenko 8149861554 * grub-core/kern/arm/cache.S: Replace = with explicit litteral load. 2013-11-13 06:23:32 +01:00
Vladimir Serbinenko ea57de18f8 * include/grub/symbol.h (END) [__arm__]: New macros. Replace all .end
occurencies with END.
2013-11-13 05:19:30 +01:00
Vladimir Serbinenko c773faf05e Revert " * include/grub/symbol.h (ADDR): New macro. Replace all occurences of"
This reverts commit 286551b4eb.
2013-11-13 02:17:20 +01:00
Vladimir Serbinenko 513eeb61dd * grub-core/kern/arm/cache_armv6.S [__clang__]: Don't add .armv6 when
compiling with clang.
2013-11-13 01:08:47 +01:00
Vladimir Serbinenko bc379c1aa1 * grub-core/kern/arm/uboot/startup.S: Use .org rather than assigning
".".
2013-11-13 01:06:30 +01:00
Vladimir Serbinenko 286551b4eb * include/grub/symbol.h (ADDR): New macro. Replace all occurences of
=x with ADDR(x) in arm assembly.
	(END): New macro. Replace all .end with END.
2013-11-13 01:04:56 +01:00
Vladimir Serbinenko 16057d6bbb Redirect all divisions to grub_divmod64. 2013-11-13 00:53:53 +01:00
Vladimir Serbinenko ef28ee8bc1 Add missing includes of loader.h. 2013-11-13 00:43:03 +01:00
Vladimir Serbinenko 33690255c5 Fix grub_machine_fini bitrot.
Reported by: Glenn Washburn.
2013-11-10 13:33:26 +01:00
Vladimir Serbinenko e0a7bffa1e * grub-core/kern/arm/misc.S (__aeabi_unwind_cpp_pr0): Add dummy to
link with libgcc.
2013-11-08 07:35:13 +01:00
Vladimir 'phcoder' Serbinenko ff2d4dc41c * grub-core/kern/arm/dl_helper.c: Use more proper %p for pointer. 2013-10-12 07:50:26 +02:00
Vladimir 'phcoder' Serbinenko 29072e994e * grub-core/kern/arm/misc.S: Remove leftover ARM and THUMB. 2013-10-08 17:03:19 +02:00