Skip to contentSkip to conversation

Prohibit Windows from running in QEMU

Qemu-devel Peter Lieven 8 participants 25 messages Oct 29, 2013 – Aug 4, 2017

lore
Share & tools
lore
#0 lore raw

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Thanks,
Peter

#1 lore raw

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 9 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Patch QEMU to crash when Hyper-V extensions are enabled...

Paolo

#2 lore raw
Quoted 11 lines · Paolo Bonzini

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 9 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Patch QEMU to crash when Hyper-V extensions are enabled...

I was thinking about this, but wouldn't this mean the cpu signature would always be "Microsoft Hv" and not "KVMKVMKVM\0\0\0"?

Peter

#3 lore raw

Il 29/10/2013 11:11, Peter Lieven ha scritto:

Quoted 12 lines · Paolo Bonzini
Quoted 11 lines

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 10 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want
to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Quoted 5 lines
Quoted 1 line

Patch QEMU to crash when Hyper-V extensions are enabled...

I was thinking about this, but wouldn't this mean the cpu signature would always be "Microsoft Hv"
and not "KVMKVMKVM\0\0\0"?

The KVM signature should be at CPUID leaf 0x40000100.

Paolo

#4 lore raw
Quoted 13 lines · Paolo Bonzini

Il 29/10/2013 11:11, Peter Lieven ha scritto:

Quoted 12 lines · Paolo Bonzini
Quoted 11 lines

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 10 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want
to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Patch QEMU to crash when Hyper-V extensions are enabled...

I was thinking about this, but wouldn't this mean the cpu signature would always be "Microsoft Hv"
and not "KVMKVMKVM\0\0\0"?

The KVM signature should be at CPUID leaf 0x40000100.

But only recently Linux started to search for it there.

--
Gleb.

#5 lore raw
In reply to Paolo Bonzini
Quoted 13 lines · Paolo Bonzini

Il 29/10/2013 11:11, Peter Lieven ha scritto:

Quoted 12 lines · Paolo Bonzini
Quoted 11 lines

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 10 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want
to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Patch QEMU to crash when Hyper-V extensions are enabled...

I was thinking about this, but wouldn't this mean the cpu signature would always be "Microsoft Hv"
and not "KVMKVMKVM\0\0\0"?

The KVM signature should be at CPUID leaf 0x40000100.

If I enable hyperv for all vServers the signature is at KVM_CPUID_SIGNATURE_NEXT (0x40000100) otherwise at KVM_CPUID_SIGNATURE (0x0). Does this matter to Linux?

Peter

#6 lore raw

Il 29/10/2013 11:40, Peter Lieven ha scritto:

Quoted 5 lines
Quoted 2 lines
Quoted 1 line

The KVM signature should be at CPUID leaf 0x40000100.

If I enable hyperv for all vServers the signature is at KVM_CPUID_SIGNATURE_NEXT (0x40000100) otherwise at KVM_CPUID_SIGNATURE (0x0).

KVM_CPU_ID_SIGNATURE is 0x40000000.

Quoted 1 line

Does this matter to Linux?

For recent versions it doesn't. Older versions will not be able to use kvmclock (and other PV enhancements for KVM such as steal time or PV EOI).

Paolo

#7 lore raw
Quoted 10 lines · Paolo Bonzini

Il 29/10/2013 11:40, Peter Lieven ha scritto:

Quoted 4 lines
Quoted 1 line

The KVM signature should be at CPUID leaf 0x40000100.

If I enable hyperv for all vServers the signature is at KVM_CPUID_SIGNATURE_NEXT (0x40000100) otherwise at KVM_CPUID_SIGNATURE (0x0).

KVM_CPU_ID_SIGNATURE is 0x40000000.

Quoted 1 line

Does this matter to Linux?

For recent versions it doesn't. Older versions will not be able to use kvmclock (and other PV enhancements for KVM such as steal time or PV EOI).

Ok, so this is not an option today - maybe later...

Any other idea to detect Windows is running or trying to start?

Thanks,
Peter

#17 lore raw
In reply to Peter Lieven
Quoted 11 lines · Peter Lieven

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Thanks,
Peter

- create a device
- write a linux driver
- if driver is not enabled crash guest

Signature · 1 line
MST
#18 lore raw
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Peter Lieven

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Quoted 7 lines
Quoted 2 lines

Thanks,
Peter

- create a device
- write a linux driver
- if driver is not enabled crash guest

For how long to wait before a crash?

--
Gleb.

#19 lore raw
Quoted 11 lines · Gleb Natapov
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Peter Lieven

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

Thanks,
Peter

- create a device
- write a linux driver
- if driver is not enabled crash guest

For how long to wait before a crash?

I would not like to alter the software in the guest anyway. If this would be required I could force a Linux version that would search for the alternate KVM signature in the cpuid leaf.

Peter

#20 lore raw
Quoted 14 lines · Peter Lieven
Quoted 13 lines · Gleb Natapov
Quoted 12 lines · Michael S. Tsirkin
Quoted 11 lines · Peter Lieven

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Thanks,
Peter

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

- create a device
- write a linux driver
- if driver is not enabled crash guest

For how long to wait before a crash?

I would not like to alter the software in the guest anyway. If this would be required I could force a Linux version that would search for the alternate KVM signature in the cpuid leaf.

You can detect certain patterns of RTC usage (Linux does not use it usually), but it is fragile since Linux allows userspace to access RTC and it may create the same usage pattern.

--
Gleb.

#24 lore raw
In reply to Peter Lieven
Quoted 8 lines · Peter Lieven

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Do you have todo the check in QEMU itself, or is it possible to add a hook into your installation method ? If so, then you could use the virt-inspector tool that comes with libguestfs to probe the install media and/or disk image to detect the operating system type, and then avoid starting QEMU at all if not what was expected

Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#21 lore raw
In reply to Gleb Natapov
Quoted 11 lines · Gleb Natapov
Quoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Peter Lieven

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Quoted 8 lines
Quoted 7 lines
Quoted 2 lines

Thanks,
Peter

- create a device
- write a linux driver
- if driver is not enabled crash guest

For how long to wait before a crash?

Or don't crash, disable some other functionality, for example, you can keep all network links down until your driver is loaded.

Quoted 2 lines

--
Gleb.

#22 lore raw
Quoted 15 lines · Michael S. Tsirkin
Quoted 14 lines · Gleb Natapov
Quoted 13 lines · Michael S. Tsirkin
Quoted 11 lines · Peter Lieven

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Thanks,
Peter

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

- create a device
- write a linux driver
- if driver is not enabled crash guest

For how long to wait before a crash?

Or don't crash, disable some other functionality, for example, you can keep all network links down until your driver is loaded.

Unless your root is on nfs and driver is in a module :). Anyway if you need to write guest code there are easier ways to do it than writing new device/driver. In ideal world you could have used ACPI _OS(?) function, but since most bioses are broken for anything but Windows Linux reports that it is Windows too.

--
Gleb.

#8 lore raw
In reply to Peter Lieven
Quoted 8 lines · Peter Lieven
Quoted 7 lines · Paolo Bonzini

Il 29/10/2013 11:40, Peter Lieven ha scritto:

Quoted 4 lines
Quoted 1 line

The KVM signature should be at CPUID leaf 0x40000100.

If I enable hyperv for all vServers the signature is at KVM_CPUID_SIGNATURE_NEXT (0x40000100) otherwise at KVM_CPUID_SIGNATURE (0x0).

KVM_CPU_ID_SIGNATURE is 0x40000000.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Does this matter to Linux?

For recent versions it doesn't. Older versions will not be able to use kvmclock (and other PV enhancements for KVM such as steal time or PV EOI).

Ok, so this is not an option today - maybe later...

Any other idea to detect Windows is running or trying to start?

I don't know what I'm talking about. But:

- Maybe tracing MSR accesses could give you a "profile".

- Windows' ACPI parser is super cranky. You could pass in a custom (but standardized) ACPI table on the command line (-acpitable) that only triggers some warnings in Linux's port of ACPICA, but crashes Windows (BSOD). Like, write & compile a simple table to AML, then mess it up (eg. Package encoding or some such) with a hex editor. This would take some experimentation as well, but searching existing bug reports could help.

Laszlo

#10 lore raw
In reply to BALATON Zoltan

Il 29/10/2013 16:55, BALATON Zoltan ha scritto:

Quoted 13 lines · Laszlo Ersek
Quoted 1 line

I don't know what I'm talking about. But:

Neither do I but...

Quoted 7 lines

- Windows' ACPI parser is super cranky. You could pass in a custom (but standardized) ACPI table on the command line (-acpitable) that only triggers some warnings in Linux's port of ACPICA, but crashes Windows (BSOD). Like, write & compile a simple table to AML, then mess it up (eg. Package encoding or some such) with a hex editor. This would take some experimentation as well, but searching existing bug reports could help.

Quoted 5 lines

This seems evil and fragile (although this can be done without patches with a command line option only). But instead why not remove/disable some BIOS functions that Linux doesn't need but Windows relies on? This seems to be less fragile (although requiring a patch) if it's possible at all.

Subtly crippling the HPET might work, since Linux will prefer kvmclock.
Good luck when users come screaming for support though.

Paolo

#9 lore raw
In reply to Laszlo Ersek
Quoted 1 line · Laszlo Ersek

I don't know what I'm talking about. But:

Neither do I but...

Quoted 6 lines

- Windows' ACPI parser is super cranky. You could pass in a custom (but standardized) ACPI table on the command line (-acpitable) that only triggers some warnings in Linux's port of ACPICA, but crashes Windows (BSOD). Like, write & compile a simple table to AML, then mess it up (eg. Package encoding or some such) with a hex editor. This would take some experimentation as well, but searching existing bug reports could help.

This seems evil and fragile (although this can be done without patches with a command line option only). But instead why not remove/disable some BIOS functions that Linux doesn't need but Windows relies on? This seems to be less fragile (although requiring a patch) if it's possible at all.

Regards,
BALATON Zoltan

#11 lore raw
In reply to Paolo Bonzini
Quoted 17 lines

Am 29.10.2013 um 17:00 schrieb Paolo Bonzini <[email protected]>:

Il 29/10/2013 16:55, BALATON Zoltan ha scritto:

Quoted 13 lines
Quoted 2 lines · Laszlo Ersek

I don't know what I'm talking about. But:

Neither do I but...

Quoted 7 lines

- Windows' ACPI parser is super cranky. You could pass in a custom (but standardized) ACPI table on the command line (-acpitable) that only triggers some warnings in Linux's port of ACPICA, but crashes Windows (BSOD). Like, write & compile a simple table to AML, then mess it up (eg. Package encoding or some such) with a hex editor. This would take some experimentation as well, but searching existing bug reports could help.

Quoted 9 lines
Quoted 5 lines

This seems evil and fragile (although this can be done without patches with a command line option only). But instead why not remove/disable some BIOS functions that Linux doesn't need but Windows relies on? This seems to be less fragile (although requiring a patch) if it's possible at all.

Subtly crippling the HPET might work, since Linux will prefer kvmclock. Good luck when users come screaming for support though.

I think without hyper-v Windows will prefer the pmtimer. I will look at this it might work.

Thanks for your ideas.

Peter

Quoted 1 line

Paolo

#23 lore raw
In reply to Michael S. Tsirkin
Quoted 11 lines · Michael S. Tsirkin
Quoted 9 lines · Peter Lieven

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Quoted 8 lines
Quoted 3 lines

Thanks,
Peter

- create a device
- write a linux driver
- if driver is not enabled crash guest

another option:
_OSI() in ACPI, for ACPI compatible cases.

#12 lore raw
In reply to Paolo Bonzini

Am 29.10.2013 um 10:59 schrieb Paolo Bonzini:

Quoted 11 lines

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 9 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Patch QEMU to crash when Hyper-V extensions are enabled...

Hi all,

this is an old topic that has become important for me again recently. Now all Linux versions should be able to detect KVM even if Hyper-V is enabled.

But how do I detect from Qemu userspace that Hyper-V is enabled?

Thanks,
Peter

#13 lore raw
Quoted 11 lines · Peter Lieven

Am 29.10.2013 um 10:59 schrieb Paolo Bonzini:

Quoted 10 lines

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 9 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Quoted 8 lines
Quoted 1 line

Patch QEMU to crash when Hyper-V extensions are enabled...

Hi all,

this is an old topic that has become important for me again recently. Now all Linux versions should be able to detect KVM even if Hyper-V is enabled.

But how do I detect from Qemu userspace that Hyper-V is enabled?

Maybe a better one: make KVM crash the guest if CR8 is nonzero on a vmexit. Linux doesn't use it, Windows should not survive long. Warning, I don't know if UEFI firmware uses CR8.

Paolo

#14 lore raw

Am 04.08.2017 um 12:23 schrieb Paolo Bonzini:

Quoted 13 lines · Peter Lieven
Quoted 12 lines

Am 29.10.2013 um 10:59 schrieb Paolo Bonzini:

Quoted 11 lines

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 9 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Patch QEMU to crash when Hyper-V extensions are enabled...

Quoted 8 lines
Quoted 6 lines

Hi all,

this is an old topic that has become important for me again recently. Now all Linux versions should be able to detect KVM even if Hyper-V is enabled.

But how do I detect from Qemu userspace that Hyper-V is enabled?

Maybe a better one: make KVM crash the guest if CR8 is nonzero on a vmexit. Linux doesn't use it, Windows should not survive long.

You mean the kvm kernel module? Or can I access this register also from Qemu on any call that is handled in userspace? It would be easier to have a cmdline option to Qemu than an option to a kernel module.

Quoted 1 line

Warning, I don't know if UEFI firmware uses CR8.

UEFI firmware is not important in this case.
Do you know if FreeBSD, OpenBSD or NetBSD use it?

Thank for your ideas,
Peter

#15 lore raw
Quoted 19 lines · Peter Lieven

Am 04.08.2017 um 12:23 schrieb Paolo Bonzini:

Quoted 18 lines · Peter Lieven
Quoted 17 lines

Am 29.10.2013 um 10:59 schrieb Paolo Bonzini:

Quoted 11 lines

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 9 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Patch QEMU to crash when Hyper-V extensions are enabled...

Hi all,

this is an old topic that has become important for me again recently. Now all Linux versions should be able to detect KVM even if Hyper-V is enabled.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

But how do I detect from Qemu userspace that Hyper-V is enabled?

Maybe a better one: make KVM crash the guest if CR8 is nonzero on a vmexit. Linux doesn't use it, Windows should not survive long.

You mean the kvm kernel module? Or can I access this register also from Qemu on any call that is handled in userspace? It would be easier to have a cmdline option to Qemu than an option to a kernel module.

Yes, the kernel module. Accessing it in QEMU requires cpu_synchronize_state so it's slow. However, you could piggyback on some other functionality that is never used by Linux to do the check, for example the RTC I/O port.

That is, in the RTC I/O port code you call cpu_synchronize_state and check CR8.

Paolo

Quoted 9 lines
Quoted 1 line

Warning, I don't know if UEFI firmware uses CR8.

UEFI firmware is not important in this case.
Do you know if FreeBSD, OpenBSD or NetBSD use it?

Thank for your ideas,
Peter

#16 lore raw

Am 04.08.2017 um 12:43 schrieb Paolo Bonzini:

Quoted 26 lines · Peter Lieven
Quoted 19 lines

Am 04.08.2017 um 12:23 schrieb Paolo Bonzini:

Quoted 18 lines · Peter Lieven
Quoted 17 lines

Am 29.10.2013 um 10:59 schrieb Paolo Bonzini:

Quoted 11 lines

Il 29/10/2013 10:48, Peter Lieven ha scritto:

Quoted 9 lines

Hi all,

this question might seem a bit weird, but does anyone see a good way to avoid
that Windows is able to boot inside qemu?

We have defined several profiles for different operation systems and I want to avoid that someone chooses Linux and then installs Windows within a VM. Reason is licensing.

Patch QEMU to crash when Hyper-V extensions are enabled...

Hi all,

this is an old topic that has become important for me again recently. Now all Linux versions should be able to detect KVM even if Hyper-V is enabled.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

But how do I detect from Qemu userspace that Hyper-V is enabled?

Maybe a better one: make KVM crash the guest if CR8 is nonzero on a vmexit. Linux doesn't use it, Windows should not survive long.

You mean the kvm kernel module? Or can I access this register also from Qemu on any call that is handled in userspace? It would be easier to have a cmdline option to Qemu than an option to a kernel module.

Quoted 7 lines

Yes, the kernel module. Accessing it in QEMU requires cpu_synchronize_state so it's slow. However, you could piggyback on some other functionality that is never used by Linux to do the check, for example the RTC I/O port.

That is, in the RTC I/O port code you call cpu_synchronize_state and check CR8.

Thanks, I will try that out and let you know.

Peter