Skip to content

Commit

Permalink
Driver/MMap: fixed bug in VAD memory deallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthTon committed Mar 6, 2019
1 parent f0b9bc9 commit bd30dd1
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/BlackBoneDrv/MMap.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ NTSTATUS BBFindOrMapModule(
ALLOCATE_FREE_MEMORY request = { 0 };
ALLOCATE_FREE_MEMORY_RESULT mapResult = { 0 };

request.pid = (ULONG)(ULONG_PTR)PsGetProcessId( pProcess );
request.allocate = TRUE;
request.physical = TRUE;
request.protection = PAGE_EXECUTE_READWRITE;
Expand Down Expand Up @@ -649,8 +650,22 @@ NTSTATUS BBFindOrMapModule(
// Delete remote image
if (pLocalImage->baseAddress)
{
SIZE_T tmpSize = 0;
ZwFreeVirtualMemory( ZwCurrentProcess(), &pLocalImage->baseAddress, &tmpSize, MEM_RELEASE );
if (flags & KHideVAD)
{
ALLOCATE_FREE_MEMORY request = { 0 };
ALLOCATE_FREE_MEMORY_RESULT mapResult = { 0 };

request.pid = (ULONG)(ULONG_PTR)PsGetProcessId( pProcess );
request.allocate = FALSE;
request.physical = TRUE;

BBAllocateFreePhysical( pProcess, &request, &mapResult );
}
else
{
SIZE_T tmpSize = 0;
ZwFreeVirtualMemory( ZwCurrentProcess(), &pLocalImage->baseAddress, &tmpSize, MEM_RELEASE );
}
}

RtlFreeUnicodeString( &pLocalImage->fullPath );
Expand Down

0 comments on commit bd30dd1

Please sign in to comment.