From 1257274ad8eb0790bc3b56ba68b114c5e1e24713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Date: Mon, 3 Jul 2023 09:53:43 +0100 Subject: [PATCH] dbus: add 'ConfidentialVirtualization' property to manager object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This property reports whether the system is running inside a confidential virtual machine. Related: https://github.com/systemd/systemd/issues/27604 Signed-off-by: Daniel P. Berrangé --- man/org.freedesktop.systemd1.xml | 10 ++++++++++ src/core/dbus-manager.c | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/man/org.freedesktop.systemd1.xml b/man/org.freedesktop.systemd1.xml index 560ae252e35..793646360df 100644 --- a/man/org.freedesktop.systemd1.xml +++ b/man/org.freedesktop.systemd1.xml @@ -305,6 +305,8 @@ node /org/freedesktop/systemd1 { @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly s Virtualization = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") + readonly s ConfidentialVirtualization = '...'; + @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly s Architecture = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly s Tainted = '...'; @@ -1010,6 +1012,8 @@ node /org/freedesktop/systemd1 { + + @@ -1765,6 +1769,12 @@ node /org/freedesktop/systemd1 { Note that only the "innermost" virtualization technology is exported here. This detects both full-machine virtualizations (VMs) and shared-kernel virtualization (containers). + ConfidentialVirtualization contains a short ID string describing the confidential + virtualization technology the system runs in. On bare-metal hardware this is the empty string. Otherwise, + it contains an identifier such as sev, sev-es, sev-snp, + tdx and so on. For a full list of IDs see + systemd-detect-virt1. + Architecture contains a short ID string describing the architecture the systemd instance is running on. This follows the same vocabulary as ConditionArchitectures=. diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 6d813fd5743..1204b913c9e 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -12,6 +12,7 @@ #include "bus-get-properties.h" #include "bus-log-control-api.h" #include "chase.h" +#include "confidential-virt.h" #include "data-fd-util.h" #include "dbus-cgroup.h" #include "dbus-execute.h" @@ -91,6 +92,27 @@ static int property_get_virtualization( v == VIRTUALIZATION_NONE ? NULL : virtualization_to_string(v)); } +static int property_get_confidential_virtualization( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + ConfidentialVirtualization v; + + assert(bus); + assert(reply); + + v = detect_confidential_virtualization(); + + return sd_bus_message_append( + reply, "s", + v <= 0 ? NULL : confidential_virtualization_to_string(v)); +} + static int property_get_tainted( sd_bus *bus, const char *path, @@ -2920,6 +2942,7 @@ const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_PROPERTY("Version", "s", property_get_version, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Features", "s", property_get_features, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Virtualization", "s", property_get_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("ConfidentialVirtualization", "s", property_get_confidential_virtualization, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Architecture", "s", property_get_architecture, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Tainted", "s", property_get_tainted, 0, SD_BUS_VTABLE_PROPERTY_CONST), BUS_PROPERTY_DUAL_TIMESTAMP("FirmwareTimestamp", offsetof(Manager, timestamps[MANAGER_TIMESTAMP_FIRMWARE]), SD_BUS_VTABLE_PROPERTY_CONST),