qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jean-Philippe Brucker <jean-philippe@linaro.org>
To: peter.maydell@linaro.org, richard.henderson@linaro.org
Cc: philmd@linaro.org, pbonzini@redhat.com, alex.bennee@linaro.org,
	qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	Jean-Philippe Brucker <jean-philippe@linaro.org>
Subject: [PATCH v2 06/22] hw/arm/virt: Disable DTB randomness for confidential VMs
Date: Fri, 19 Apr 2024 16:56:54 +0100	[thread overview]
Message-ID: <20240419155709.318866-8-jean-philippe@linaro.org> (raw)
In-Reply-To: <20240419155709.318866-2-jean-philippe@linaro.org>

The dtb-randomness feature, which adds random seeds to the DTB, isn't
really compatible with confidential VMs since it randomizes the Realm
Initial Measurement. Enabling it is not an error, but it prevents
attestation. It also isn't useful to a Realm, which doesn't trust host
input.

Currently the feature is automatically enabled, unless the user disables
it on the command-line. Change it to OnOffAuto, and automatically
disable it for confidential VMs, unless the user explicitly enables it.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
v1->v2: separate patch, use OnOffAuto
---
 docs/system/arm/virt.rst |  9 +++++----
 include/hw/arm/virt.h    |  2 +-
 hw/arm/virt.c            | 41 +++++++++++++++++++++++++---------------
 3 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst
index 26fcba00b7..e4bbfec662 100644
--- a/docs/system/arm/virt.rst
+++ b/docs/system/arm/virt.rst
@@ -172,10 +172,11 @@ dtb-randomness
   rng-seed and kaslr-seed nodes (in both "/chosen" and
   "/secure-chosen") to use for features like the random number
   generator and address space randomisation. The default is
-  ``on``. You will want to disable it if your trusted boot chain
-  will verify the DTB it is passed, since this option causes the
-  DTB to be non-deterministic. It would be the responsibility of
-  the firmware to come up with a seed and pass it on if it wants to.
+  ``off`` for confidential VMs, and ``on`` otherwise. You will want
+  to disable it if your trusted boot chain will verify the DTB it is
+  passed, since this option causes the DTB to be non-deterministic.
+  It would be the responsibility of the firmware to come up with a
+  seed and pass it on if it wants to.
 
 dtb-kaslr-seed
   A deprecated synonym for dtb-randomness.
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
index bb486d36b1..90a148dac2 100644
--- a/include/hw/arm/virt.h
+++ b/include/hw/arm/virt.h
@@ -150,7 +150,7 @@ struct VirtMachineState {
     bool virt;
     bool ras;
     bool mte;
-    bool dtb_randomness;
+    OnOffAuto dtb_randomness;
     OnOffAuto acpi;
     VirtGICType gic_version;
     VirtIOMMUType iommu;
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 07ad31876e..f300f100b5 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -259,6 +259,7 @@ static bool ns_el2_virt_timer_present(void)
 
 static void create_fdt(VirtMachineState *vms)
 {
+    bool dtb_randomness = true;
     MachineState *ms = MACHINE(vms);
     int nb_numa_nodes = ms->numa_state->num_nodes;
     void *fdt = create_device_tree(&vms->fdt_size);
@@ -268,6 +269,16 @@ static void create_fdt(VirtMachineState *vms)
         exit(1);
     }
 
+    /*
+     * Including random data in the DTB causes random intial measurement on CCA,
+     * so disable it for confidential VMs.
+     */
+    if (vms->dtb_randomness == ON_OFF_AUTO_OFF ||
+        (vms->dtb_randomness == ON_OFF_AUTO_AUTO &&
+         virt_machine_is_confidential(vms))) {
+        dtb_randomness = false;
+    }
+
     ms->fdt = fdt;
 
     /* Header */
@@ -278,13 +289,13 @@ static void create_fdt(VirtMachineState *vms)
 
     /* /chosen must exist for load_dtb to fill in necessary properties later */
     qemu_fdt_add_subnode(fdt, "/chosen");
-    if (vms->dtb_randomness) {
+    if (dtb_randomness) {
         create_randomness(ms, "/chosen");
     }
 
     if (vms->secure) {
         qemu_fdt_add_subnode(fdt, "/secure-chosen");
-        if (vms->dtb_randomness) {
+        if (dtb_randomness) {
             create_randomness(ms, "/secure-chosen");
         }
     }
@@ -2474,18 +2485,21 @@ static void virt_set_its(Object *obj, bool value, Error **errp)
     vms->its = value;
 }
 
-static bool virt_get_dtb_randomness(Object *obj, Error **errp)
+static void virt_get_dtb_randomness(Object *obj, Visitor *v, const char *name,
+                                    void *opaque, Error **errp)
 {
     VirtMachineState *vms = VIRT_MACHINE(obj);
+    OnOffAuto dtb_randomness = vms->dtb_randomness;
 
-    return vms->dtb_randomness;
+    visit_type_OnOffAuto(v, name, &dtb_randomness, errp);
 }
 
-static void virt_set_dtb_randomness(Object *obj, bool value, Error **errp)
+static void virt_set_dtb_randomness(Object *obj, Visitor *v, const char *name,
+                                    void *opaque, Error **errp)
 {
     VirtMachineState *vms = VIRT_MACHINE(obj);
 
-    vms->dtb_randomness = value;
+    visit_type_OnOffAuto(v, name, &vms->dtb_randomness, errp);
 }
 
 static char *virt_get_oem_id(Object *obj, Error **errp)
@@ -3123,16 +3137,16 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
                                           "Set on/off to enable/disable "
                                           "ITS instantiation");
 
-    object_class_property_add_bool(oc, "dtb-randomness",
-                                   virt_get_dtb_randomness,
-                                   virt_set_dtb_randomness);
+    object_class_property_add(oc, "dtb-randomness", "OnOffAuto",
+                              virt_get_dtb_randomness, virt_set_dtb_randomness,
+                              NULL, NULL);
     object_class_property_set_description(oc, "dtb-randomness",
                                           "Set off to disable passing random or "
                                           "non-deterministic dtb nodes to guest");
 
-    object_class_property_add_bool(oc, "dtb-kaslr-seed",
-                                   virt_get_dtb_randomness,
-                                   virt_set_dtb_randomness);
+    object_class_property_add(oc, "dtb-kaslr-seed", "OnOffAuto",
+                              virt_get_dtb_randomness, virt_set_dtb_randomness,
+                              NULL, NULL);
     object_class_property_set_description(oc, "dtb-kaslr-seed",
                                           "Deprecated synonym of dtb-randomness");
 
@@ -3203,9 +3217,6 @@ static void virt_instance_init(Object *obj)
     /* MTE is disabled by default.  */
     vms->mte = false;
 
-    /* Supply kaslr-seed and rng-seed by default */
-    vms->dtb_randomness = true;
-
     vms->irqmap = a15irqmap;
 
     virt_flash_create(vms);
-- 
2.44.0



  parent reply	other threads:[~2024-04-19 16:02 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19 15:56 [PATCH v2 00/22] arm: Run CCA VMs with KVM Jean-Philippe Brucker
2024-04-19 15:56 ` [PATCH v2 01/22] kvm: Merge kvm_check_extension() and kvm_vm_check_extension() Jean-Philippe Brucker
2024-04-19 15:56 ` [PATCH v2 02/22] target/arm: Add confidential guest support Jean-Philippe Brucker
2024-04-19 16:25   ` Daniel P. Berrangé
2024-04-23  9:44     ` Jean-Philippe Brucker
2024-04-23  9:49       ` Daniel P. Berrangé
2024-04-23 12:15     ` Markus Armbruster
2024-04-19 15:56 ` [PATCH v2 03/22] target/arm/kvm: Return immediately on error in kvm_arch_init() Jean-Philippe Brucker
2024-04-19 15:56 ` [PATCH v2 04/22] target/arm/kvm-rme: Initialize realm Jean-Philippe Brucker
2024-04-19 15:56 ` [PATCH v2 05/22] hw/arm/virt: Add support for Arm RME Jean-Philippe Brucker
2024-04-19 15:56 ` Jean-Philippe Brucker [this message]
2024-04-19 15:56 ` [PATCH v2 07/22] hw/arm/virt: Reserve one bit of guest-physical address for RME Jean-Philippe Brucker
2024-04-19 15:56 ` [PATCH v2 08/22] target/arm/kvm: Split kvm_arch_get/put_registers Jean-Philippe Brucker
2024-04-19 15:56 ` [PATCH v2 09/22] target/arm/kvm-rme: Initialize vCPU Jean-Philippe Brucker
2024-04-19 15:56 ` [PATCH v2 10/22] target/arm/kvm: Create scratch VM as Realm if necessary Jean-Philippe Brucker
2024-04-19 15:56 ` [PATCH v2 11/22] hw/core/loader: Add ROM loader notifier Jean-Philippe Brucker
2024-04-19 15:57 ` [PATCH v2 12/22] target/arm/kvm-rme: Populate Realm memory Jean-Philippe Brucker
2024-04-19 15:57 ` [PATCH v2 13/22] hw/arm/boot: Register Linux BSS section for confidential guests Jean-Philippe Brucker
2024-04-19 15:57 ` [PATCH v2 14/22] target/arm/kvm-rme: Add Realm Personalization Value parameter Jean-Philippe Brucker
2024-04-23 12:17   ` Markus Armbruster
2024-04-23 12:20   ` Peter Maydell
2024-04-23 12:30     ` Daniel P. Berrangé
2024-04-23 12:35     ` Markus Armbruster
2024-04-19 15:57 ` [PATCH v2 15/22] target/arm/kvm-rme: Add measurement algorithm property Jean-Philippe Brucker
2024-04-23 12:23   ` Markus Armbruster
2024-04-19 15:57 ` [PATCH v2 16/22] target/arm/cpu: Set number of breakpoints and watchpoints in KVM Jean-Philippe Brucker
2024-04-19 15:57 ` [PATCH v2 17/22] target/arm/cpu: Set number of PMU counters " Jean-Philippe Brucker
2024-04-19 15:57 ` [PATCH v2 18/22] target/arm/kvm: Disable Realm reboot Jean-Philippe Brucker
2024-04-19 15:57 ` [PATCH v2 19/22] target/arm/cpu: Inform about reading confidential CPU registers Jean-Philippe Brucker
2024-04-19 15:57 ` [PATCH v2 20/22] target/arm/kvm-rme: Enable guest memfd Jean-Philippe Brucker
2024-04-19 15:57 ` [PATCH v2 21/22] hw/arm/virt: Move virt_flash_create() to machvirt_init() Jean-Philippe Brucker
2024-04-19 15:57 ` [PATCH v2 22/22] hw/arm/virt: Use RAM instead of flash for confidential guest firmware Jean-Philippe Brucker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240419155709.318866-8-jean-philippe@linaro.org \
    --to=jean-philippe@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).