Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dead Lock on DriverUnload #16

Open
sidaxx opened this issue Jan 27, 2018 · 1 comment
Open

Dead Lock on DriverUnload #16

sidaxx opened this issue Jan 27, 2018 · 1 comment

Comments

@sidaxx
Copy link

sidaxx commented Jan 27, 2018

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 ?

@DragonQuestHero
Copy link
Contributor

i got same problem.and i tryed u code on win10 1607.not works
if dont free memory on stopvm.dead lock not happen.
emmm are u solve now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants