提交 8069ce4f 编写于 作者: M mikebeaton 提交者: MikeBeaton

OcBootManagementLib: Extend ProtectUefiServices quirk to restore hooks...

OcBootManagementLib: Extend ProtectUefiServices quirk to restore hooks overwritten by GRUB2 shim as required
上级 9d5fc5f4
......@@ -14,6 +14,7 @@ OpenCore Changelog
- Added BiosVideo.efi driver to use with `ReconnectGraphicsOnConnect`
- Changed `FadtEnableReset` to avoid unreliable keyboard controller reset
- Added `EnableVmx` quirk to allow virtualization in other OS on some Macs
- Upgraded `ProtectUefiServices` to prevent GRUB shim overwriting service pointers when chainloading with Secure Boot enabled
#### v0.7.5
- Revised OpenLinuxBoot documentation
......
......@@ -1651,9 +1651,15 @@ To view their current state, use the \texttt{pmset -g} command in Terminal.
such as \texttt{DevirtualiseMmio}, \texttt{ProtectMemoryRegions}, or \texttt{RebuildAppleMemoryMap},
and may also obstruct other quirks depending on the scope of such.
\emph{Note}: On VMware, the need for this quirk may be determined by the appearance of the
GRUB shim makes similar on-the-fly changes to various UEFI image services,
which are also protected against by this quirk.
\emph{Note 1}: On VMware, the need for this quirk may be determined by the appearance of the
``Your Mac OS guest might run unreliably with more than one virtual core.'' message.
\emph{Note 2}: This quirk is needed for correct operation if OpenCore is chainloaded from GRUB
with BIOS Secure Boot enabled.
\item
\texttt{ProvideCustomSlide}\\
\textbf{Type}: \texttt{plist\ boolean}\\
......
......@@ -1741,7 +1741,7 @@ OcRegisterBootstrapBootOption (
**/
VOID
OcImageLoaderInit (
VOID
IN CONST BOOLEAN ProtectUefiServices
);
/**
......
......@@ -30,6 +30,7 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/OcAppleSecureBootLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcDevicePathLib.h>
#include <Library/OcFileLib.h>
#include <Library/OcMachoLib.h>
......@@ -78,6 +79,59 @@ STATIC OC_IMAGE_LOADER_CONFIGURE mImageLoaderConfigure;
STATIC UINT32 mImageLoaderCaps;
STATIC BOOLEAN mImageLoaderEnabled;
STATIC BOOLEAN mProtectUefiServices;
STATIC EFI_IMAGE_LOAD mPreservedLoadImage;
STATIC EFI_IMAGE_START mPreservedStartImage;
STATIC EFI_EXIT_BOOT_SERVICES mPreservedExitBootServices;
STATIC EFI_EXIT mPreservedExit;
STATIC
VOID
PreserveGrubShimHooks (
VOID
)
{
if (!mProtectUefiServices) {
return;
}
mPreservedLoadImage = gBS->LoadImage;
mPreservedStartImage = gBS->StartImage;
mPreservedExitBootServices = gBS->ExitBootServices;
mPreservedExit = gBS->Exit;
}
//
// REF: https://github.com/acidanthera/bugtracker/issues/1874
//
STATIC
VOID
RestoreGrubShimHooks (
IN CONST CHAR8 *Caller
)
{
if (!mProtectUefiServices) {
return;
}
if (gBS->LoadImage != mPreservedLoadImage ||
gBS->StartImage != mPreservedStartImage ||
gBS->ExitBootServices != mPreservedExitBootServices ||
gBS->Exit != mPreservedExit) {
DEBUG ((DEBUG_INFO, "OCB: Restoring trashed L:%u S:%u EBS:%u E:%u after %a\n",
gBS->LoadImage != mPreservedLoadImage,
gBS->StartImage != mPreservedStartImage,
gBS->ExitBootServices != mPreservedExitBootServices,
gBS->Exit != mPreservedExit,
Caller
));
gBS->LoadImage = mPreservedLoadImage;
gBS->StartImage = mPreservedStartImage;
gBS->ExitBootServices = mPreservedExitBootServices;
gBS->Exit = mPreservedExit;
}
}
STATIC
EFI_STATUS
InternalEfiLoadImageFile (
......@@ -446,7 +500,7 @@ InternalDirectExit (
// If the image has been started, verify this image can exit.
//
if (ImageHandle != mCurrentImageHandle) {
DEBUG ((DEBUG_LOAD|DEBUG_ERROR, "Exit: Image is not exitable image\n"));
DEBUG ((DEBUG_LOAD|DEBUG_ERROR, "OCB: Image is not exitable image\n"));
gBS->RestoreTPL (OldTpl);
return EFI_INVALID_PARAMETER;
}
......@@ -818,6 +872,7 @@ InternalEfiLoadImage (
Status = EFI_UNSUPPORTED;
}
} else {
PreserveGrubShimHooks ();
Status = mOriginalEfiLoadImage (
BootPolicy,
ParentImageHandle,
......@@ -826,6 +881,7 @@ InternalEfiLoadImage (
SourceSize,
ImageHandle
);
RestoreGrubShimHooks ("LoadImage");
}
if (AllocatedBuffer != NULL) {
......@@ -900,7 +956,11 @@ InternalEfiStartImage (
}
}
return mOriginalEfiStartImage (ImageHandle, ExitDataSize, ExitData);
PreserveGrubShimHooks ();
Status = mOriginalEfiStartImage (ImageHandle, ExitDataSize, ExitData);
RestoreGrubShimHooks ("StartImage");
return Status;
}
STATIC
......@@ -965,14 +1025,20 @@ InternalEfiExit (
);
}
return mOriginalEfiExit (ImageHandle, ExitStatus, ExitDataSize, ExitData);
PreserveGrubShimHooks ();
Status = mOriginalEfiExit (ImageHandle, ExitStatus, ExitDataSize, ExitData);
RestoreGrubShimHooks ("Exit");
return Status;
}
VOID
OcImageLoaderInit (
VOID
IN CONST BOOLEAN ProtectUefiServices
)
{
mProtectUefiServices = ProtectUefiServices;
mOriginalEfiLoadImage = gBS->LoadImage;
mOriginalEfiStartImage = gBS->StartImage;
mOriginalEfiUnloadImage = gBS->UnloadImage;
......
......@@ -823,7 +823,7 @@ OcLoadUefiSupport (
OcReinstallProtocols (Config);
OcImageLoaderInit ();
OcImageLoaderInit (Config->Booter.Quirks.ProtectUefiServices);
OcLoadAppleSecureBoot (Config);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册