OcAfterBootCompatLib: Add new KCG patch logging

This commit is contained in:
Marvin Häuser 2022-06-12 20:57:12 +02:00
parent c4792bb6aa
commit 714fc69f96

View File

@ -777,6 +777,13 @@ InternalIsEfiBootRt (
|| (SourceBuffer == NULL)
|| (EfiBootLoadedImage->FilePath == NULL))
{
DEBUG ((
DEBUG_INFO,
"OCABC: Cannot be EfiBootRt (DP %d, Buf %d, EfiBoot FP %d)\n",
(EfiBootRtDevicePath == NULL),
(SourceBuffer == NULL),
(EfiBootLoadedImage->FilePath == NULL)
));
return FALSE;
}
@ -787,9 +794,20 @@ InternalIsEfiBootRt (
//
EfiBootDevicePath = DevicePathFromHandle (EfiBootLoadedImage->DeviceHandle);
if (EfiBootDevicePath == NULL) {
DEBUG ((
DEBUG_INFO,
"OCABC: Failed to get EfiBoot DP from handle 0x%llx\n",
(UINT64)(UINTN)EfiBootLoadedImage->DeviceHandle
));
return FALSE;
}
DebugPrintDevicePath (
DEBUG_INFO,
"OCABC: Current EfiBoot",
EfiBootDevicePath
);
EfiBootRtDevicePathRemSize = GetDevicePathSize (EfiBootRtDevicePath);
DevicePathEnd = FindDevicePathEndNode (EfiBootDevicePath);
@ -801,6 +819,12 @@ InternalIsEfiBootRt (
&EfiBootRtDevicePathRemSize
);
if (Overflow) {
DEBUG ((
DEBUG_INFO,
"OCABC: EfiBootRt DP (0x%llx) is shorter than EfiBoot DP (0x%llx)\n",
(UINT64)EfiBootRtDevicePathRemSize,
(UINT64)ComponentSize
));
return FALSE;
}
@ -814,6 +838,7 @@ InternalIsEfiBootRt (
ComponentSize
);
if (CmpResult != 0) {
DEBUG ((DEBUG_INFO, "OCABC: EfiBoot DP is not a prefix of EfiBootRt DP\n"));
return FALSE;
}
@ -823,6 +848,12 @@ InternalIsEfiBootRt (
ComponentSize = (UINTN)DevicePathEnd - (UINTN)EfiBootLoadedImage->FilePath;
if (ComponentSize >= EfiBootRtDevicePathRemSize) {
DEBUG ((
DEBUG_INFO,
"OCABC: EfiBootRt FP (0x%llx) is shorter than EfiBoot FP (0x%llx)\n",
(UINT64)EfiBootRtDevicePathRemSize,
(UINT64)ComponentSize
));
return FALSE;
}
@ -832,6 +863,7 @@ InternalIsEfiBootRt (
ComponentSize
);
if (CmpResult != 0) {
DEBUG ((DEBUG_INFO, "OCABC: EfiBoot FP is not a prefix of EfiBootRt FP\n"));
return FALSE;
}
@ -843,6 +875,10 @@ InternalIsEfiBootRt (
if ( (DevicePathType (CurrentRtNode) != HARDWARE_DEVICE_PATH)
|| (DevicePathSubType (CurrentRtNode) != HW_MEMMAP_DP))
{
DEBUG ((
DEBUG_INFO,
"OCABC: EfiBootRt FP is not succeeded by a MemMap node\n"
));
return FALSE;
}
@ -851,6 +887,14 @@ InternalIsEfiBootRt (
if ( (MemMapNode->StartingAddress != (EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer)
|| (MemMapNode->EndingAddress != (EFI_PHYSICAL_ADDRESS)((UINTN)SourceBuffer + SourceSize)))
{
DEBUG ((
DEBUG_INFO,
"OCABC: MemMap [0x%llx, 0x%llx) mismatches EfiBootRt [0x%llx, 0x%llx)\n",
MemMapNode->StartingAddress,
MemMapNode->EndingAddress,
(EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer,
(EFI_PHYSICAL_ADDRESS)((UINTN)SourceBuffer + SourceSize)
));
return FALSE;
}
@ -902,6 +946,7 @@ InternalEfiBootRtGetKcgOffset (
&EfiBootRtCopyHandle
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCABC: KCG load - %r\n", Status));
return 0;
}
@ -915,6 +960,7 @@ InternalEfiBootRtGetKcgOffset (
(VOID **)&LoadedImage
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCABC: Handle KCG LoadedImage - %r\n", Status));
gBS->UnloadImage (EfiBootRtCopyHandle);
return 0;
}
@ -934,6 +980,7 @@ InternalEfiBootRtGetKcgOffset (
gBS->UnloadImage (EfiBootRtCopyHandle);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCABC: KCG start - %r\n", Status));
return 0;
}
@ -951,6 +998,13 @@ InternalEfiBootRtGetKcgOffset (
KcgSize
);
if (Overflow) {
DEBUG ((
DEBUG_INFO,
"OCABC: KCG OOB (0x%llx, [0x%llx, 0x%llx)\n",
(UINT64)(UINTN)EfiBootRtLoadOptions.KernelCallGate,
(UINT64)ImageBase,
(UINT64)(ImageBase + SourceSize)
));
return 0;
}
@ -982,6 +1036,9 @@ OcLoadImage (
UINTN KcgSize;
BootCompat = GetBootCompatContext ();
DebugPrintDevicePath (DEBUG_INFO, "OCABC: EfiBootRt candidate", DevicePath);
//
// Verify whether it's EfiBootRt that's being loaded. If it is, patch its
// kernel call gate. This is relevant as of macOS 13 Developer Beta 1, as
@ -998,6 +1055,14 @@ OcLoadImage (
);
}
DEBUG ((
DEBUG_INFO,
"OCABC: IsEfiBootRt %d (BP %d, Apple %d)\n",
IsEfiBootRt,
!BootPolicy,
BootCompat->ServiceState.AppleBootNestedCount > 0
));
//
// Anything but EfiBootRt can be loaded transparently. EfiBootRt must be
// loaded with the OpenCore image loader as it is not signed. This is not a
@ -1023,6 +1088,7 @@ OcLoadImage (
ImageHandle
);
if (EFI_ERROR (LoadImageStatus)) {
DEBUG ((DEBUG_INFO, "OCABC: EfiBootRt load - %r\n", LoadImageStatus));
return LoadImageStatus;
}
@ -1037,6 +1103,12 @@ OcLoadImage (
SourceSize
);
if ((KcgOffset == 0) || (KcgSize < CALL_GATE_MIN_SIZE)) {
DEBUG ((
DEBUG_INFO,
"OCABC: Invalid KCG [0x%llx, 0x%llx)\n",
(UINT64)KcgOffset,
(UINT64)KcgSize
));
return LoadImageStatus;
}
@ -1046,6 +1118,7 @@ OcLoadImage (
(VOID **)&LoadedImage
);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "OCABC: Handle EfiBootRt LoadedImage - %r\n", Status));
return LoadImageStatus;
}
@ -1058,6 +1131,12 @@ OcLoadImage (
(UINTN)AppleMapPrepareKernelStateNew
);
DEBUG ((
DEBUG_INFO,
"OCABC: Patched KCG at 0x%llx\n",
(UINTN)LoadedImage->ImageBase + KcgOffset
));
return LoadImageStatus;
}