Search code examples
language-agnosticcross-platformoperating-systemvirtualization

Can a executable behave differently when run on a Virtualized Server?


Let's say I have a piece of code that runs fine on an OS. Now, if I install that OS on a virtual machine (server virtualization), and run that code on that, is it possible that the code behaves differently?

If so, what are the prerequisites for that? For example, does it have to be compiled machine code (in other words, are interpreted languages safe?)? Does it have to be certain OS instructions? Specific virtualization technology (Xen, KVM, VMware..)?

Also, what are the possible different behaviors?


Solution

  • Yes. Like any machine, the virtual machine is just another computer (implemented in software instead of hardware).

    For one, lots of commercial apps will blow up when you run them on a VM due to:

    1. copy protection detecting the VM
    2. copy protection rigging your hardware, using undocumented features of BIOS/Kernel/hardware

    Secondly, a VM is just another computer consisting of hardware implemented in assembly instead of circuits/dye/microcode/magic. This means the VM must provide the emulated hardware either through pass-through or emulation. The fact that hardware is very diverse can cause all kinds of different behavior. Also note the possible lack of drivers for or acceleration of the emulated hardware.

    But of course a typical business application for example isn't nearly as likely to rely on any hardware details as all it does is call some GUI API.

    Interpreted languages are only safe from this to the extent that they are "interpreted", if the interpreted language calls out to some native code, all this is possible again.

    For an example of something detecting that it's running under a VM, check this, it's just one of the literally thousands of ways to detect the VM.