Skip to content

Commit

Permalink
OcAppleKernelLib: Zero trailing KC expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
mhaeuser committed Oct 25, 2020
1 parent 8e3b8f1 commit 7732a7b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Library/OcAppleKernelLib/PrelinkedContext.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,11 +531,25 @@ PrelinkedInjectPrepare (
}

ASSERT (Context->PrelinkedLastAddress == Context->PrelinkedLastLoadAddress);
//
// Ensured by PrelinkedContextInit().
//
ASSERT (Context->PrelinkedSize % MACHO_PAGE_SIZE == 0);
STATIC_ASSERT (
MACHO_PAGE_SIZE % OC_ALIGNOF (MACH_DYLD_CHAINED_STARTS_IN_SEGMENT) == 0,
"KextsFixupChains may be unaligned"
);

Context->KextsFixupChains = (VOID *) (Context->Prelinked +
Context->LinkEditSegment->Segment64.FileOffset + Context->LinkEditSegment->Segment64.FileSize);
Context->KextsFixupChains = (VOID *) (Context->Prelinked + Context->PrelinkedSize);

AlignedExpansion = MACHO_ALIGN (LinkedExpansion);
//
// Zero the expansion to account for padding.
//
ZeroMem (
Context->Prelinked + Context->PrelinkedSize,
AlignedExpansion
);

Context->PrelinkedSize += AlignedExpansion;
Context->PrelinkedLastAddress += AlignedExpansion;
Expand Down

0 comments on commit 7732a7b

Please sign in to comment.