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

systemd-detect-virt falsely detects "Microsoft" virtualisation #21468

Closed
mbiebl opened this issue Nov 22, 2021 · 7 comments · Fixed by #21475
Closed

systemd-detect-virt falsely detects "Microsoft" virtualisation #21468

mbiebl opened this issue Nov 22, 2021 · 7 comments · Fixed by #21475
Labels
bug 🐛 Programming errors, that need preferential fixing detect-virt
Milestone

Comments

@mbiebl
Copy link
Contributor

mbiebl commented Nov 22, 2021

Version: 249.7
Downstream bug report: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1000396

systemd-detect-virt checks /sys/class/dmi/id/sys_vendor as part of its
attempt to detect if the system is virtualised. I am using a Surface
Laptop so sys_vendor returns "Microsoft Corporation" which (as far as I
can tell) the program assumes indicates the presence of hyper-v rather
than Microsoft produced hardware. One of the consequences is that
systemd units that won't run in a VM fail, such as thermald.

Afaics, this is a result of PR #20998

506bbc8

@fbq ^

@mrc0mmand mrc0mmand added this to the v250 milestone Nov 22, 2021
@mrc0mmand mrc0mmand added bug 🐛 Programming errors, that need preferential fixing detect-virt labels Nov 22, 2021
@bluca
Copy link
Member

bluca commented Nov 22, 2021

Yep that's not quite right. @fbq please reopen, I guess your first version that checked for /dev/vmbus is a better alternative?

@poettering
Copy link
Member

I'd much prefer if we go by comparing strings, instead of relying on driver support. (i mean, it could be the kernel has vmbus support disabled, we still should be able to detect a microsoft virtualization)

Can't we make the strings check more precise? i.e. obviously "Microsoft" is very generic a check. But making the string check more precise should get us there, no? What are the strings reported by Surface and the VM environment?

@bluca
Copy link
Member

bluca commented Nov 22, 2021

I don't think vmbus can be disabled individually? It's enabled by building support for hyperv guest

@poettering
Copy link
Member

still, checking for devices sucks, since they might come late, think udev and so on. Also it requires special code and stuff. I much prefer identifying by strings.

(And who knows, maybe some other VM env implements /dev/vmbus one day too? At least Synology NAS devices support "hyperv-enlightened" VMs that are actually backed by kvm)

@bluca
Copy link
Member

bluca commented Nov 22, 2021

Sure, if there's an alternative it would be much better

@fbq
Copy link
Contributor

fbq commented Nov 23, 2021

Yep that's not quite right. @fbq please reopen, I guess your first version that checked for /dev/vmbus is a better alternative?

Checking for /dev/vmbus can solve the problem that @mbiebl hit, however, I agree with @poettering, comparing strings is better. And in theory a Hyper-V VM can "run" without any VMbus (it can run, but cannot interact with the outside world).

I just checked other fields in DMI, it turned out that we have string "Hyper-V" in the following fields /sys/class/dmi/id/{product,sys,board,bios}_version, more precisely it's

Hyper-V UEFI Release v4.0

In my environment. We can detect whether it's a Hyper-V VM by checking whether /sys/class/dmi/id/product_version starts with "Hyper-V". Should I send another PR or should I change my previous PR?

@poettering
Copy link
Member

Should I send another PR or should I change my previous PR?

Your PR already got merged. Please send a new follow-up PR!

fbq added a commit to fbq/systemd that referenced this issue Nov 23, 2021
Use product_version instead of product_name in DMI table and the string
"Hyper-V" to avoid misdetection.

Fixes: systemd#21468

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
poettering pushed a commit that referenced this issue Nov 23, 2021
Use product_version instead of product_name in DMI table and the string
"Hyper-V" to avoid misdetection.

Fixes: #21468

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
floppym pushed a commit to floppym/systemd that referenced this issue Jan 15, 2022
Use product_version instead of product_name in DMI table and the string
"Hyper-V" to avoid misdetection.

Fixes: systemd#21468

Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
(cherry picked from commit 76eec06)
landy2005 added a commit to observium/distroscript that referenced this issue Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Programming errors, that need preferential fixing detect-virt
5 participants