Skip to content

Commit

Permalink
OcAppleKernelLib: Fix linking against injected kexts
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Jul 5, 2020
1 parent 0ff97ad commit ef8fdce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Library/OcAppleKernelLib/KernelCollection.c
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ KcKextApplyFileDelta (
//
// Rebase the segment itself.
//
if (Segment->FileOffset != 0) {
if (Segment->FileOffset != 0 || Segment->FileSize != 0) {
Segment->FileOffset += Delta;
}

Expand Down Expand Up @@ -741,5 +741,11 @@ KcKextApplyFileDelta (
}
}

//
// Update the container offset to make sure we can link against this
// kext later as well.
//
Context->ContainerOffset = Delta;

return EFI_SUCCESS;
}
6 changes: 4 additions & 2 deletions Library/OcAppleKernelLib/PrelinkedContext.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,11 @@ PrelinkedInjectKext (
//
// For KC, our KEXTs have their own segment - do not mod __PRELINK_INFO.
// Integrate the KEXT into KC by indexing its fixups and rebasing.
// Note, we are no longer using ExecutableContext here, as the context
// ownership was transferred by InternalLinkPrelinkedKext.
//
KcKextIndexFixups (Context, &ExecutableContext);
Status = KcKextApplyFileDelta (&ExecutableContext, KextOffset);
KcKextIndexFixups (Context, &PrelinkedKext->Context.MachContext);
Status = KcKextApplyFileDelta (&PrelinkedKext->Context.MachContext, KextOffset);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_WARN,
Expand Down
1 change: 1 addition & 0 deletions Library/OcAppleKernelLib/PrelinkedKext.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ InternalScanCurrentPrelinkedKextLinkInfo (
}

if (Kext->SymbolTable == NULL) {
DEBUG ((DEBUG_VERBOSE, "OCAK: Requesting SymbolTable for %a\n", Kext->Identifier));
Kext->NumberOfSymbols = MachoGetSymbolTable (
&Kext->Context.MachContext,
&Kext->SymbolTable,
Expand Down

0 comments on commit ef8fdce

Please sign in to comment.