Skip to contentSkip to conversation

ppc: add host-serial and host-model machine attributes

PATCH Superseded P J P 2 participants 4 messages Feb 12, 2019 – Feb 15, 2019

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH v2 1/1 ppc: add host-serial and host-model machine attributes

From: Prasad J Pandit <[email protected]>

On ppc hosts, hypervisor shares following system attributes

- /proc/device-tree/system-id
- /proc/device-tree/model

with a guest. This could lead to information leakage and misuse.[*] Add machine attributes to control such system information exposure to a guest.

[*] https://wiki.openstack.org/wiki/OSSN/OSSN-0028

---
 hw/core/machine.c   | 46 +++++++++++++++++++++++++++++++++++++++++++++
 hw/ppc/spapr.c      | 36 +++++++++++++++++++++++++++++------
 include/hw/boards.h |  2 ++
 qemu-options.hx     | 10 +++++++++-
 util/qemu-config.c  |  8 ++++++++
 5 files changed, 95 insertions(+), 7 deletions(-)

Update v2: add backward compatible properties
-> https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg00593.html

hw/core/machine.c +46 -0
index 2629515363..2d5a52476a 100644
@@ -476,6 +476,38 @@ static void machine_set_memory_encryption(Object *obj, const char *value,
     ms->memory_encryption = g_strdup(value);
 }
 
+static char *machine_get_host_serial(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->host_serial);
+}
+
+static void machine_set_host_serial(Object *obj, const char *value,
+                                    Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->host_serial);
+    ms->host_serial = g_strdup(value);
+}
+
+static char *machine_get_host_model(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->host_model);
+}
+
+static void machine_set_host_model(Object *obj, const char *value,
+                                   Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->host_model);
+    ms->host_model = g_strdup(value);
+}
+
 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
 {
     strList *item = g_new0(strList, 1);
@@ -760,6 +792,18 @@ static void machine_class_init(ObjectClass *oc, void *data)
         &error_abort);
     object_class_property_set_description(oc, "memory-encryption",
         "Set memory encryption object to use", &error_abort);
+
+    object_class_property_add_str(oc, "host-serial",
+        machine_get_host_serial, machine_set_host_serial,
+        &error_abort);
+    object_class_property_set_description(oc, "host-serial",
+        "Set host's system-id to use", &error_abort);
+
+    object_class_property_add_str(oc, "host-model",
+        machine_get_host_model, machine_set_host_model,
+        &error_abort);
+    object_class_property_set_description(oc, "host-model",
+        "Set host's model-id to use", &error_abort);
 }
 
 static void machine_class_base_init(ObjectClass *oc, void *data)
@@ -785,6 +829,8 @@ static void machine_initfn(Object *obj)
     ms->dump_guest_core = true;
     ms->mem_merge = true;
     ms->enable_graphics = true;
+    ms->host_serial = NULL;
+    ms->host_model = NULL;
 
     /* Register notifier when init is done for sysbus sanity checks */
     ms->sysbus_notifier.notify = machine_init_notify;
hw/ppc/spapr.c +30 -6
index 0942f35bf8..a70667d72d 100644
@@ -1249,13 +1249,31 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,
      * Add info to guest to indentify which host is it being run on
      * and what is the uuid of the guest
      */
-    if (kvmppc_get_host_model(&buf)) {
-        _FDT(fdt_setprop_string(fdt, 0, "host-model", buf));
-        g_free(buf);
+    if (machine->host_model && !g_str_equal(machine->host_model, "none")) {
+        if (g_str_equal(machine->host_model, "passthrough")) {
+            /* -M host-model=passthrough */
+            if (kvmppc_get_host_model(&buf)) {
+                _FDT(fdt_setprop_string(fdt, 0, "host-model", buf));
+                g_free(buf);
+            }
+        } else {
+            /* -M host-model=<user-string> */
+            _FDT(fdt_setprop_string(fdt, 0, "host-model", machine->host_model));
+        }
     }
-    if (kvmppc_get_host_serial(&buf)) {
-        _FDT(fdt_setprop_string(fdt, 0, "host-serial", buf));
-        g_free(buf);
+
+    if (machine->host_serial && !g_str_equal(machine->host_serial, "none")) {
+        if (g_str_equal(machine->host_serial, "passthrough")) {
+            /* -M host-serial=passthrough */
+            if (kvmppc_get_host_serial(&buf)) {
+                _FDT(fdt_setprop_string(fdt, 0, "host-serial", buf));
+                g_free(buf);
+            }
+        } else {
+            /* -M host-serial=<user-string> */
+            _FDT(fdt_setprop_string(fdt, 0,
+                                    "host-serial", machine->host_serial));
+        }
     }
 
     buf = qemu_uuid_unparse_strdup(&qemu_uuid);
@@ -4080,9 +4098,15 @@ DEFINE_SPAPR_MACHINE(4_0, "4.0", true);
 static void spapr_machine_3_1_class_options(MachineClass *mc)
 {
     sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
+    static GlobalProperty compat[] = {
+        { TYPE_SPAPR_MACHINE, "host-model", "passthrough" },
+        { TYPE_SPAPR_MACHINE, "host-serial", "passthrough" },
+    };
 
     spapr_machine_4_0_class_options(mc);
     compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
+    compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
+
     mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0");
     smc->update_dt_enabled = false;
 }
include/hw/boards.h +2 -0
index 02f114085f..3e63dc4501 100644
@@ -257,6 +257,8 @@ struct MachineState {
     bool enforce_config_section;
     bool enable_graphics;
     char *memory_encryption;
+    char *host_serial;
+    char *host_model;
     DeviceMemoryState *device_memory;
 
     ram_addr_t ram_size;
qemu-options.hx +9 -1
index 521511ec13..67ac1a9959 100644
@@ -43,7 +43,9 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                suppress-vmdesc=on|off disables self-describing migration (default=off)\n"
     "                nvdimm=on|off controls NVDIMM support (default=off)\n"
     "                enforce-config-section=on|off enforce configuration section migration (default=off)\n"
-    "                memory-encryption=@var{} memory encryption object to use (default=none)\n",
+    "                memory-encryption=@var{} memory encryption object to use (default=none)\n"
+    "                host-serial=none|passthrough|string controls host systemd-id (default=passthrough)\n"
+    "                host-model=none|passthrough|string controls host model-id (default=passthrough)\n",
     QEMU_ARCH_ALL)
 STEXI
 @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@@ -103,6 +105,12 @@ NOTE: this parameter is deprecated. Please use @option{-global}
 @option{migration.send-configuration}=@var{on|off} instead.
 @item memory-encryption=@var{}
 Memory encryption object to use. The default is none.
+@item host-serial=none|passthrough|string
+Pass 'system-id' parameter from host's device-tree to a guest. A user may
+disable it with 'none' or define a custom string for a guest.
+@item host-model=none|passthrough|string
+Pass 'model' paramter from host's device-tree to a guest. A user may disable
+it with 'none' or define a custom string for a guest.
 @end table
 ETEXI
 
util/qemu-config.c +8 -0
index 9d2e278e29..86483ded34 100644
@@ -238,6 +238,14 @@ static QemuOptsList machine_opts = {
             .help = "Up to 8 chars in set of [A-Za-z0-9. ](lower case chars"
                     " converted to upper case) to pass to machine"
                     " loader, boot manager, and guest kernel",
+        },{
+            .name = "host-serial",
+            .type = QEMU_OPT_STRING,
+            .help = "host's system-id seen by guest",
+        },{
+            .name = "host-model",
+            .type = QEMU_OPT_STRING,
+            .help = "host's model-id seen by guest",
         },
         { /* End of list */ }
     }
Signature · 1 line
2.20.1
#1 lore raw
Quoted 76 lines · P J P

From: Prasad J Pandit <[email protected]>

On ppc hosts, hypervisor shares following system attributes

- /proc/device-tree/system-id
- /proc/device-tree/model

with a guest. This could lead to information leakage and misuse.[*] Add machine attributes to control such system information exposure to a guest.

[*] https://wiki.openstack.org/wiki/OSSN/OSSN-0028

---
 hw/core/machine.c   | 46 +++++++++++++++++++++++++++++++++++++++++++++
 hw/ppc/spapr.c      | 36 +++++++++++++++++++++++++++++------
 include/hw/boards.h |  2 ++
 qemu-options.hx     | 10 +++++++++-
 util/qemu-config.c  |  8 ++++++++
 5 files changed, 95 insertions(+), 7 deletions(-)

Update v2: add backward compatible properties
-> https://lists.gnu.org/archive/html/qemu-devel/2019-02/msg00593.html

hw/core/machine.c +34 -0
index 2629515363..2d5a52476a 100644
@@ -476,6 +476,38 @@ static void machine_set_memory_encryption(Object *obj, const char *value,
     ms->memory_encryption = g_strdup(value);
 }
 
+static char *machine_get_host_serial(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->host_serial);
+}
+
+static void machine_set_host_serial(Object *obj, const char *value,
+                                    Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->host_serial);
+    ms->host_serial = g_strdup(value);
+}
+
+static char *machine_get_host_model(Object *obj, Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    return g_strdup(ms->host_model);
+}
+
+static void machine_set_host_model(Object *obj, const char *value,
+                                   Error **errp)
+{
+    MachineState *ms = MACHINE(obj);
+
+    g_free(ms->host_model);
+    ms->host_model = g_strdup(value);
+}
+
 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
 {
     strList *item = g_new0(strList, 1);
@@ -760,6 +792,18 @@ static void machine_class_init(ObjectClass *oc, void *data)
         &error_abort);
     object_class_property_set_description(oc, "memory-encryption",
         "Set memory encryption object to use", &error_abort);
+
+    object_class_property_add_str(oc, "host-serial",

hw/core/machine.c static void machine_class_init(ObjectClass *oc, void *data) · line 806

Quoted 10 lines
hw/core/machine.c +10 -0
+        machine_get_host_serial, machine_set_host_serial,
+        &error_abort);
+    object_class_property_set_description(oc, "host-serial",
+        "Set host's system-id to use", &error_abort);
+
+    object_class_property_add_str(oc, "host-model",
+        machine_get_host_model, machine_set_host_model,
+        &error_abort);
+    object_class_property_set_description(oc, "host-model",
+        "Set host's model-id to use", &error_abort);

You're adding properties to *all* machines, for something that's only used on the PAPR machine. That doesn't seem right.

Quoted 56 lines
hw/core/machine.c +2 -0
 }
 
 static void machine_class_base_init(ObjectClass *oc, void *data)
@@ -785,6 +829,8 @@ static void machine_initfn(Object *obj)
     ms->dump_guest_core = true;
     ms->mem_merge = true;
     ms->enable_graphics = true;
+    ms->host_serial = NULL;
+    ms->host_model = NULL;
 
     /* Register notifier when init is done for sysbus sanity checks */
     ms->sysbus_notifier.notify = machine_init_notify;
hw/ppc/spapr.c +24 -6
index 0942f35bf8..a70667d72d 100644
@@ -1249,13 +1249,31 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,
      * Add info to guest to indentify which host is it being run on
      * and what is the uuid of the guest
      */
-    if (kvmppc_get_host_model(&buf)) {
-        _FDT(fdt_setprop_string(fdt, 0, "host-model", buf));
-        g_free(buf);
+    if (machine->host_model && !g_str_equal(machine->host_model, "none")) {
+        if (g_str_equal(machine->host_model, "passthrough")) {
+            /* -M host-model=passthrough */
+            if (kvmppc_get_host_model(&buf)) {
+                _FDT(fdt_setprop_string(fdt, 0, "host-model", buf));
+                g_free(buf);
+            }
+        } else {
+            /* -M host-model=<user-string> */
+            _FDT(fdt_setprop_string(fdt, 0, "host-model", machine->host_model));
+        }
     }
-    if (kvmppc_get_host_serial(&buf)) {
-        _FDT(fdt_setprop_string(fdt, 0, "host-serial", buf));
-        g_free(buf);
+
+    if (machine->host_serial && !g_str_equal(machine->host_serial, "none")) {
+        if (g_str_equal(machine->host_serial, "passthrough")) {
+            /* -M host-serial=passthrough */
+            if (kvmppc_get_host_serial(&buf)) {
+                _FDT(fdt_setprop_string(fdt, 0, "host-serial", buf));
+                g_free(buf);
+            }
+        } else {
+            /* -M host-serial=<user-string> */
+            _FDT(fdt_setprop_string(fdt, 0,
+                                    "host-serial", machine->host_serial));
+        }
     }
 
     buf = qemu_uuid_unparse_strdup(&qemu_uuid);
@@ -4080,9 +4098,15 @@ DEFINE_SPAPR_MACHINE(4_0, "4.0", true);
 static void spapr_machine_3_1_class_options(MachineClass *mc)

hw/ppc/spapr.c DEFINE_SPAPR_MACHINE(4_0, "4.0", true); · line 4108

Quoted 10 lines
hw/ppc/spapr.c +5 -0
 {
     sPAPRMachineClass *smc = SPAPR_MACHINE_CLASS(mc);
+    static GlobalProperty compat[] = {
+        { TYPE_SPAPR_MACHINE, "host-model", "passthrough" },
+        { TYPE_SPAPR_MACHINE, "host-serial", "passthrough" },
+    };
 
     spapr_machine_4_0_class_options(mc);
     compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
+    compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));

I'm still not convinced maintaining super-strict backwards compat at the expense of security is a good tradeoff here, but since the code's already written, let's run with it.

Quoted 64 lines
hw/ppc/spapr.c +1 -0
+
     mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0");
     smc->update_dt_enabled = false;
 }
include/hw/boards.h +2 -0
index 02f114085f..3e63dc4501 100644
@@ -257,6 +257,8 @@ struct MachineState {
     bool enforce_config_section;
     bool enable_graphics;
     char *memory_encryption;
+    char *host_serial;
+    char *host_model;
     DeviceMemoryState *device_memory;
 
     ram_addr_t ram_size;
qemu-options.hx +9 -1
index 521511ec13..67ac1a9959 100644
@@ -43,7 +43,9 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \
     "                suppress-vmdesc=on|off disables self-describing migration (default=off)\n"
     "                nvdimm=on|off controls NVDIMM support (default=off)\n"
     "                enforce-config-section=on|off enforce configuration section migration (default=off)\n"
-    "                memory-encryption=@var{} memory encryption object to use (default=none)\n",
+    "                memory-encryption=@var{} memory encryption object to use (default=none)\n"
+    "                host-serial=none|passthrough|string controls host systemd-id (default=passthrough)\n"
+    "                host-model=none|passthrough|string controls host model-id (default=passthrough)\n",
     QEMU_ARCH_ALL)
 STEXI
 @item -machine [type=]@var{name}[,prop=@var{value}[,...]]
@@ -103,6 +105,12 @@ NOTE: this parameter is deprecated. Please use @option{-global}
 @option{migration.send-configuration}=@var{on|off} instead.
 @item memory-encryption=@var{}
 Memory encryption object to use. The default is none.
+@item host-serial=none|passthrough|string
+Pass 'system-id' parameter from host's device-tree to a guest. A user may
+disable it with 'none' or define a custom string for a guest.
+@item host-model=none|passthrough|string
+Pass 'model' paramter from host's device-tree to a guest. A user may disable
+it with 'none' or define a custom string for a guest.
 @end table
 ETEXI
 
util/qemu-config.c +8 -0
index 9d2e278e29..86483ded34 100644
@@ -238,6 +238,14 @@ static QemuOptsList machine_opts = {
             .help = "Up to 8 chars in set of [A-Za-z0-9. ](lower case chars"
                     " converted to upper case) to pass to machine"
                     " loader, boot manager, and guest kernel",
+        },{
+            .name = "host-serial",
+            .type = QEMU_OPT_STRING,
+            .help = "host's system-id seen by guest",
+        },{
+            .name = "host-model",
+            .type = QEMU_OPT_STRING,
+            .help = "host's model-id seen by guest",
         },
         { /* End of list */ }
     }
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#2 lore raw
+-- On Wed, 13 Feb 2019, David Gibson wrote --+
| > +
| > +    object_class_property_add_str(oc, "host-serial",
| > +        machine_get_host_serial, machine_set_host_serial,
| > +        &error_abort);
| > +    object_class_property_set_description(oc, "host-serial",
| > +        "Set host's system-id to use", &error_abort);
| > +
| > +    object_class_property_add_str(oc, "host-model",
| > +        machine_get_host_model, machine_set_host_model,
| > +        &error_abort);
| > +    object_class_property_set_description(oc, "host-model",
| > +        "Set host's model-id to use", &error_abort);
| 
| You're adding properties to *all* machines, for something that's only
| used on the PAPR machine.  That doesn't seem right.

I tried to figure out about adding these options to only spapr machine, but it does not seem straight forward as above.

| >      spapr_machine_4_0_class_options(mc);
| >      compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
| > +    compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
| 
| I'm still not convinced maintaining super-strict backwards compat at
| the expense of security is a good tradeoff here, but since the code's
| already written, let's run with it.

I think current patch will provide a way to help fix the security issue, we can revise it further if required.

Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F

#3 lore raw
Quoted 17 lines · P J P
+-- On Wed, 13 Feb 2019, David Gibson wrote --+
| > +
| > +    object_class_property_add_str(oc, "host-serial",
| > +        machine_get_host_serial, machine_set_host_serial,
| > +        &error_abort);
| > +    object_class_property_set_description(oc, "host-serial",
| > +        "Set host's system-id to use", &error_abort);
| > +
| > +    object_class_property_add_str(oc, "host-model",
| > +        machine_get_host_model, machine_set_host_model,
| > +        &error_abort);
| > +    object_class_property_set_description(oc, "host-model",
| > +        "Set host's model-id to use", &error_abort);
| 
| You're adding properties to *all* machines, for something that's only
| used on the PAPR machine.  That doesn't seem right.
Quoted 2 lines

I tried to figure out about adding these options to only spapr machine, but it does not seem straight forward as above.

It really should be. You can just put those object_class_property_add()s into spapr_machine_class_init().

Quoted 10 lines
| >      spapr_machine_4_0_class_options(mc);
| >      compat_props_add(mc->compat_props, hw_compat_3_1, hw_compat_3_1_len);
| > +    compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
| 
| I'm still not convinced maintaining super-strict backwards compat at
| the expense of security is a good tradeoff here, but since the code's
| already written, let's run with it.

I think current patch will provide a way to help fix the security issue, we can revise it further if required.

That's reasonable.

Quoted 2 lines

Thank you.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson