Skip to content

Dead Lock on DriverUnload #16

@sidyhe

Description

@sidyhe

Hi!
I found that a dead-lock happen on my Windows7 (VMWare)
via debug, it is mybe locked at EptFreeIdentityMap
so, try to this:

NTSTATUS EptFreeIdentityMap( IN PEPT_DATA pEPT )
{
	if (pEPT->PML4Ptr == NULL)
		return STATUS_SUCCESS;

	pEPT->PML4Ptr = NULL;

	// Reset used preallocations
	pEPT->Preallocations = 0;
	return STATUS_SUCCESS;
}

and free memory at FreeGlobalData

VOID FreeGlobalData( IN PGLOBAL_DATA pData )
{
	if (pData == NULL)
		return;

	ULONG cpu_count = KeQueryActiveProcessorCountEx(ALL_PROCESSOR_GROUPS);
	for (ULONG i = 0; i < cpu_count; i++)
	{
		PVCPU Vcpu = &pData->cpu_data[i];
		PLIST_ENTRY ListHead = &Vcpu->EPT.PageList;

		if (Vcpu->VMXON)
			MmFreeContiguousMemory(Vcpu->VMXON);
		if (Vcpu->VMCS)
			MmFreeContiguousMemory(Vcpu->VMCS);
		if (Vcpu->VMMStack)
			MmFreeContiguousMemory(Vcpu->VMMStack);

		for (ULONG j = 0; j < EPT_PREALLOC_PAGES; j++)
		{
			PVOID Ptr = Vcpu->EPT.Pages[j];

			if (Ptr != NULL)
				MmFreeContiguousMemory(Ptr);
		}

		// free here
		while (!IsListEmpty(ListHead))
		{
			PLIST_ENTRY pListEntry = RemoveHeadList(ListHead);
			PEPT_PAGES_ENTRY pEntry = CONTAINING_RECORD(pListEntry, EPT_PAGES_ENTRY, link);

			for (ULONG64 k = 0; k < pEntry->count; k++)
			{
				PVOID Ptr = pEntry->pages[k];

				if (Ptr != NULL)
					MmFreeContiguousMemory(Ptr);
			}

			ExFreePoolWithTag(pListEntry, HB_POOL_TAG);
		}
	}

	if (pData->Memory)
		ExFreePoolWithTag(pData->Memory, HB_POOL_TAG);
	if (pData->MSRBitmap)
		ExFreePoolWithTag(pData->MSRBitmap, HB_POOL_TAG);

	ExFreePoolWithTag(pData, HB_POOL_TAG);
}

now it is worked fine, is that right ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions