Skip to content

Commit bd30dd1

Browse files
committed
Driver/MMap: fixed bug in VAD memory deallocation
1 parent f0b9bc9 commit bd30dd1

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/BlackBoneDrv/MMap.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ NTSTATUS BBFindOrMapModule(
502502
ALLOCATE_FREE_MEMORY request = { 0 };
503503
ALLOCATE_FREE_MEMORY_RESULT mapResult = { 0 };
504504

505+
request.pid = (ULONG)(ULONG_PTR)PsGetProcessId( pProcess );
505506
request.allocate = TRUE;
506507
request.physical = TRUE;
507508
request.protection = PAGE_EXECUTE_READWRITE;
@@ -649,8 +650,22 @@ NTSTATUS BBFindOrMapModule(
649650
// Delete remote image
650651
if (pLocalImage->baseAddress)
651652
{
652-
SIZE_T tmpSize = 0;
653-
ZwFreeVirtualMemory( ZwCurrentProcess(), &pLocalImage->baseAddress, &tmpSize, MEM_RELEASE );
653+
if (flags & KHideVAD)
654+
{
655+
ALLOCATE_FREE_MEMORY request = { 0 };
656+
ALLOCATE_FREE_MEMORY_RESULT mapResult = { 0 };
657+
658+
request.pid = (ULONG)(ULONG_PTR)PsGetProcessId( pProcess );
659+
request.allocate = FALSE;
660+
request.physical = TRUE;
661+
662+
BBAllocateFreePhysical( pProcess, &request, &mapResult );
663+
}
664+
else
665+
{
666+
SIZE_T tmpSize = 0;
667+
ZwFreeVirtualMemory( ZwCurrentProcess(), &pLocalImage->baseAddress, &tmpSize, MEM_RELEASE );
668+
}
654669
}
655670

656671
RtlFreeUnicodeString( &pLocalImage->fullPath );

0 commit comments

Comments
 (0)