anrieff / libcpuid

a small C library for x86 CPU detection and feature extraction

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New Feature Request - Detect Virtual Machine

advanpix opened this issue · comments

I would like to propose new and very natural feature to have in CPUID library - to provide information if software is running under virtual machine.

CPUID is one of the main approach to do that - we just need to check hypervisor present bit (31st bit of ECX):
https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1009458

I would love to have special field in "cpu_id_t" or any other means to have access to this information.

Hi!
This request can be handled in two very different ways, depending on whether the hypervisor cooperates or not. The easy one is what you said - if a system is running under a VM and the hypervisor is happy to let the guest know that, then yeah, it's easy to detect the situation with a cpuid bit. In this case we can expose those bit in just another flag in the cpu_it_t::flags array.

However, in the more convoluted case when somebody is doing shady things like trying to circumvent software copy protection measures by running a licensed software on many VMs (and he only paid for one license), that person would like the VM hypervisor make whatever possible to convince the software it's running on a real machine. The bit wouldn't be present and more elaborate measures would be needed to detect we're under a VM.

Let me know which scenario do you have in mind :)

Just another flag would be perfect (first scenario).

Of course, convoluted detection of VM is way out of scope of CPUID library.
But such informative flag would a very nice addition to whole picture.

confirm. for now have same problem with detect VM and much more..... not correct detect in VM presence AES flag...
Be nice to see this future work.
Thx.