OcAppleKernelLib: Fix LinkBuffer expansion for injected kexts past the first

This commit is contained in:
Download-Fritz 2019-04-10 18:05:51 +02:00
parent fb9216234f
commit 7b06cbe369

View File

@ -412,6 +412,34 @@ InternalScanBuildLinkedVtables (
return RETURN_SUCCESS;
}
STATIC
RETURN_STATUS
InternalUpdateLinkBuffer (
IN OUT PRELINKED_KEXT *Kext,
IN OUT PRELINKED_CONTEXT *Context
)
{
ASSERT (Kext != NULL);
ASSERT (Context != NULL);
if (Context->LinkBuffer == NULL) {
Context->LinkBuffer = AllocatePool (Context->LinkBufferSize);
if (Context->LinkBuffer == NULL) {
return RETURN_OUT_OF_RESOURCES;
}
} else if (Context->LinkBufferSize < Kext->LinkEditSegment->FileSize) {
FreePool (Context->LinkBuffer);
Context->LinkBufferSize = (UINT32)Kext->LinkEditSegment->FileSize;
Context->LinkBuffer = AllocatePool (Context->LinkBufferSize);
if (Context->LinkBuffer == NULL) {
return RETURN_OUT_OF_RESOURCES;
}
}
return RETURN_SUCCESS;
}
STATIC
RETURN_STATUS
InternalInsertPrelinkedKextDependency (
@ -437,24 +465,13 @@ InternalInsertPrelinkedKextDependency (
if (RETURN_ERROR (Status)) {
return Status;
}
if (Context->LinkBuffer == NULL) {
//
// Allocate the LinkBuffer from the size cached during the initial
// function recursion.
//
Context->LinkBuffer = AllocatePool (Context->LinkBufferSize);
if (Context->LinkBuffer == NULL) {
return RETURN_OUT_OF_RESOURCES;
}
} else if (Context->LinkBufferSize < DependencyKext->LinkEditSegment->FileSize) {
FreePool (Context->LinkBuffer);
Context->LinkBufferSize = (UINT32)DependencyKext->LinkEditSegment->FileSize;
Context->LinkBuffer = AllocatePool (Context->LinkBufferSize);
if (Context->LinkBuffer == NULL) {
return RETURN_OUT_OF_RESOURCES;
}
//
// Allocate the LinkBuffer from the size cached during the initial
// function recursion.
//
Status = InternalUpdateLinkBuffer (DependencyKext, Context);
if (RETURN_ERROR (Status)) {
return Status;
}
Status = InternalScanBuildLinkedVtables (DependencyKext, Context);
@ -698,14 +715,12 @@ InternalScanPrelinkedKext (
Kext->BundleLibraries = NULL;
}
if (Context->LinkBuffer == NULL) {
//
// Allocate the LinkBuffer in case there are no dependencies.
//
Context->LinkBuffer = AllocatePool (Context->LinkBufferSize);
if (Context->LinkBuffer == NULL) {
return RETURN_OUT_OF_RESOURCES;
}
//
// Extend or allocate LinkBuffer in case there are no dependencies (kernel).
//
Status = InternalUpdateLinkBuffer (Kext, Context);
if (RETURN_ERROR (Status)) {
return Status;
}
return RETURN_SUCCESS;