OcAppleKernelLib: Fix handling of unaligned kmod info in kext blocker
@@ -186,6 +186,7 @@ PatcherBlockKext (
)
{
UINT64 KmodOffset;
+ UINT64 KmodStartAddr;
UINT64 TmpOffset;
KMOD_INFO_64_V1 *KmodInfo;
UINT8 *PatchAddr;
@@ -200,16 +201,18 @@ PatcherBlockKext (
KmodOffset = Context->VirtualKmod - Context->VirtualBase;
KmodInfo = (KMOD_INFO_64_V1 *)((UINT8 *) MachoGetMachHeader64 (&Context->MachContext) + KmodOffset);
if (OcOverflowAddU64 (KmodOffset, sizeof (KMOD_INFO_64_V1), &TmpOffset)
- || KmodOffset > MachoGetFileSize (&Context->MachContext)
- || !OC_ALIGNED (KmodInfo)
- || KmodInfo->StartAddr == 0
- || Context->VirtualBase > KmodInfo->StartAddr) {
+ || KmodOffset > MachoGetFileSize (&Context->MachContext)) {
return RETURN_INVALID_PARAMETER;
}
- TmpOffset = KmodInfo->StartAddr - Context->VirtualBase;
+ CopyMem (&KmodStartAddr, &KmodInfo->StartAddr, sizeof (KmodStartAddr));
+ if (KmodStartAddr == 0 || Context->VirtualBase > KmodInfo->StartAddr) {
+ return RETURN_BAD_BUFFER_SIZE;
+ }
+
+ TmpOffset = KmodStartAddr - Context->VirtualBase;
if (TmpOffset > MachoGetFileSize (&Context->MachContext) - 6) {
- return RETURN_INVALID_PARAMETER;
+ return RETURN_BUFFER_TOO_SMALL;
}
PatchAddr = (UINT8 *)MachoGetMachHeader64 (&Context->MachContext) + TmpOffset;
