Skip to content

Commit d28187a

Browse files
val4osskeentux
authored andcommitted
detect-virt: add bare-metal support for GCE
Google Compute Engine are not only virtual but can be also physical machines. Therefore checking only the dmi is not enough to detect if it is a virtual machine. Therefore systemd-detect-virt return "google" instead of "none" in c3-highcpu-metal machine. SMBIOS will not help us to make the difference as for EC2 machines. However, GCE use KVM hypervisor for these VM, we can use this information to detect virtualization. [0] Issue and changes has been tested on SUSE SLE-15-SP7 images with systemd-254 for both GCE, bare-metal and VM. [0] - https://cloud.google.com/blog/products/gcp/7-ways-we-harden-our-kvm-hypervisor-at-google-cloud-security-in-plaintext (cherry picked from commit fb71571) [val4oss: fixes bsc#1244449]
1 parent aa12f50 commit d28187a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/basic/virt.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,7 @@ Virtualization detect_vm(void) {
470470
VIRTUALIZATION_ORACLE,
471471
VIRTUALIZATION_XEN,
472472
VIRTUALIZATION_AMAZON,
473-
VIRTUALIZATION_PARALLELS,
474-
VIRTUALIZATION_GOOGLE)) {
473+
VIRTUALIZATION_PARALLELS)) {
475474
v = dmi;
476475
goto finish;
477476
}
@@ -505,6 +504,10 @@ Virtualization detect_vm(void) {
505504
return v;
506505
if (v == VIRTUALIZATION_VM_OTHER)
507506
other = true;
507+
else if (v == VIRTUALIZATION_KVM && dmi == VIRTUALIZATION_GOOGLE)
508+
/* The DMI vendor tables in /sys/class/dmi/id don't help us distinguish between GCE
509+
* virtual machines and bare-metal instances, so we need to look at hypervisor. */
510+
return VIRTUALIZATION_GOOGLE;
508511
else if (v != VIRTUALIZATION_NONE)
509512
goto finish;
510513

@@ -517,7 +520,9 @@ Virtualization detect_vm(void) {
517520
return dmi;
518521
if (dmi == VIRTUALIZATION_VM_OTHER)
519522
other = true;
520-
else if (dmi != VIRTUALIZATION_NONE) {
523+
else if (!IN_SET(dmi, VIRTUALIZATION_NONE, VIRTUALIZATION_GOOGLE)) {
524+
/* At this point if GCE has been detected in dmi, do not report as a VM. It should
525+
* be a bare-metal machine */
521526
v = dmi;
522527
goto finish;
523528
}

0 commit comments

Comments
 (0)