Skip to contentSkip to conversation

Encode object type security status in code

PATCH In review Daniel P. Berrangé 2 participants 29 messages Sep 9 Arm i.MX and Layerscape

lore
Share & tools
lore
#0 lore raw

cover Encode object type security status in code

Our docs/system/security.rst file loosely classifies code into that applicable for 'virtualization' vs 'non-virtualization' use cases. Only code relevant to the former group is eligible for security bug handling. It is difficult for any contributors to know what devices are in scope for 'virtualization' when reporting bugs, and even maintainers can have a hard time agreeing.

It is well overdue to declare this information the code and present it to end users at runtime. This series starts the effort by defining the internal infrastructure, command line args and QMP extensions to handle the security status recording and reporting.

A previous posting included classifications for many devices. That is dropped this v3 series so we can focus on getting the core infra included. Device classifications will follow afterwards in a separate series.

The base concept is that the QOM TypeInfo struct gains a new field "bool secure". This enables querying any ObjectClass to ask whether or not it is declared secure.

By only using a single boolean flag, at runtime we are unable to distinguish between "marked insecure" and "no decision, implicitly insecure". As such, all our existing code is initially considered insecure, once this series is applied. Code we want to provide a security boundary for will explicitly opt-in with '.secure = true'.

Previously it was intended to add '.secure = false' to each file too as it gets evaluated, however, this is now considered to be overkill. It is easy enough to build a list of everything that should be treated as secure by perusing "-device help" output.

Classification for non-user creatable types can be left to a 2nd phase of work.

In terms of user interface, the "-compat" argument gains a new parameter

* insecure-types=accept|reject|warn

The default 'accept' preserves historical behaviour of anything being permissible. The other two options both identify use of types that are not explicitly marked as secure.

The code annotations are useful immediately, but the -compat -compat switch is unusable unless a minimum viable set of secure devices are defined in a follow series. Some conceptual examples though...

Example: TCG is explicitly insecure, KVM is explicitly secure:

  $ qemu-system-x86_64 -display none -compat insecure-types=reject -accel tcg
  qemu-system-x86_64: -accel tcg: Type 'tcg-accel' does not provide a security boundary to protect against untrusted workloads
  $ qemu-system-x86_64 -display none -compat insecure-types=reject -accel kvm
  ^C

Example: isapc machine type is explicitly insecure

  $ qemu-system-x86_64 -display none -compat insecure-types=reject -machine isapc
  qemu-system-x86_64: Type 'isapc-machine' does not provide a security boundary to protect against untrusted workloads

Example: checks also apply in HMP, ne2k_pci is insecure

  $ ./build/qemu-system-x86_64 -display none -compat insecure-types=reject -monitor stdio -accel kvm
  QEMU 10.1.50 monitor - type 'help' for more information
  (qemu) device_add ne2k_pci
  Error: Type 'ne2k_pci' does not provide a security boundary to protect against untrusted workloads

Example: checks also apply in QMP:

  $ ./scripts/qmp/qmp-shell-wrap qemu-system-x86_64 -display none -compat insecure-types=reject -accel kvm
  Welcome to the QMP low-level shell!
  Connected
  (QEMU) device_add driver=ne2k_oci
  {"error": {"class": "GenericError", "desc": "Type 'ne2k_pci' does not provide a security boundary to protect against untrusted workloads"}}
  (QEMU) device_add driver=virtio-net
  {"return": {}}

This series is available at

https://gitlab.com/berrange/qemu/-/commits/docs-security-status

The WIP patches that add tagging of devices (which I will post separately in future) are at

https://gitlab.com/berrange/qemu/-/commits/docs-security-devices

Changes in v3:

* Dropped all device classification, to be re-posted as a separate series
* Reworded the docs based on previous feedback
* Improved commit messages
* Reformatted QAPI docs per feedback
* Split commit adding QMP device list filtering into two
* Make CompatPolicy parameters 'const'
* Add helper APIs in QOM for querying security status to reduce duplicate code pattern
* Fix placement of security check for accelerator types

Changes in v2:

* Report security status in qom-list-types
* Allow qom-list-types to filter on secure types
* Remove 'bool insecure' on TypeInfo, assume that no specified data is equivalent to '.secure = false'
* Annotate a massive number of object types

Daniel P. Berrangé (14):
qom: add tracking of security state of object types
qapi: add 'insecure-types' option for -compat argument
qom: add helper APIs for checking object security policy compliance
system: check security for accelerator types
system: report acclerator security status in help output
system: check security for machine types
system: report machine security status in help output
system: check security of device types
system: report device security status in help output hw/core: report security status in query-machines
qom: refactor data passing for QOM list filtering
qom: report & filter on security status in qom-list-types
docs: expand security docs with info about security status
machine: add helpers for declaring secure/insecure machine types

 docs/system/security.rst     | 36 +++++++++++++++++++++++++++++++++
 hw/arm/bananapi_m2u.c        |  2 +-
 hw/arm/cubieboard.c          |  2 +-
 hw/arm/imx8mm-evk.c          |  2 +-
 hw/arm/integratorcp.c        |  2 +-
 hw/arm/mcimx7d-sabre.c       |  2 +-
 hw/arm/orangepi.c            |  2 +-
 hw/core/machine-qmp-cmds.c   |  1 +
 hw/ppc/pegasos.c             |  3 ++-
 include/hw/core/boards.h     | 25 ++++++++++++++++++-----
 include/hw/i386/pc.h         | 11 +++++++++-
 include/qapi/compat-policy.h |  5 +++++
 include/qom/object.h         | 39 ++++++++++++++++++++++++++++++++++++
 qapi/compat.json             | 23 ++++++++++++++++++++-
 qapi/machine.json            |  8 +++++++-
 qapi/qapi-util.c             | 30 +++++++++++++++++++++++++++
 qapi/qom.json                | 13 ++++++++++--
 qom/object.c                 | 22 ++++++++++++++++++++
 qom/qom-qmp-cmds.c           | 30 +++++++++++++++++++++------
 system/qdev-monitor.c        |  7 +++++++
 system/vl.c                  | 30 ++++++++++++++++++++++-----
 21 files changed, 267 insertions(+), 28 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/14 qom: add tracking of security state of object types

This introduces a new flag "secure" against the Type/TypeInfo structs, and helpers to check this against the ObjectClass struct.

If an object is considered to provide a security boundary to protect against untrusted code, the "secure" flag must be explicitly set to true.

If it is set to false, or left unset, this indicates that the object does not intend to provide a security boundary. Bugs related to this object class will be ineligible for CVE assignment.

---
 include/qom/object.h | 13 +++++++++++++
 qom/object.c         |  7 +++++++
 2 files changed, 20 insertions(+)
include/qom/object.h +13 -0
index 7ecd0f210f..687ceb6bba 100644
@@ -453,6 +453,10 @@ struct Object
  *   function.
  * @abstract: If this field is true, then the class is considered abstract and
  *   cannot be directly instantiated.
+ * @secure: If this field is initialized to true, then the class is considered
+ *   to provide a security boundary. If initialized to false, the class does
+ *   not provide a security boundary. If uninitialized (and thus implicitly
+ *   false) its status is not yet defined.
  * @class_size: The size of the class object (derivative of #ObjectClass)
  *   for this object.  If @class_size is 0, then the size of the class will be
  *   assumed to be the size of the parent class.  This allows a type to avoid
@@ -487,6 +491,7 @@ struct TypeInfo
     void (*instance_finalize)(Object *obj);
 
     bool abstract;
+    bool secure;
     size_t class_size;
 
     void (*class_init)(ObjectClass *klass, const void *data);
@@ -1074,6 +1079,14 @@ const char *object_class_get_name(ObjectClass *klass);
  */
 bool object_class_is_abstract(ObjectClass *klass);
 
+/**
+ * object_class_is_secure:
+ * @klass: The class to check security of
+ *
+ * Returns: %true if @klass is declared to be secure, %false if not declared
+ */
+bool object_class_is_secure(ObjectClass *klass);
+
 /**
  * object_class_by_name:
  * @typename: The QOM typename to obtain the class for.
qom/object.c +7 -0
index b1834a57cc..32736a0111 100644
@@ -67,6 +67,7 @@ struct TypeImpl
     void (*instance_finalize)(Object *obj);
 
     bool abstract;
+    bool secure;
 
     const char *parent;
     TypeImpl *parent_type;
@@ -122,6 +123,7 @@ static TypeImpl *type_new(const TypeInfo *info)
     ti->instance_finalize = info->instance_finalize;
 
     ti->abstract = info->abstract;
+    ti->secure = info->secure;
 
     for (i = 0; info->interfaces && info->interfaces[i].type; i++) {
         ti->interfaces[i].typename = g_strdup(info->interfaces[i].type);
@@ -1144,6 +1146,11 @@ bool object_class_is_abstract(ObjectClass *klass)
     return klass->type->abstract;
 }
 
+bool object_class_is_secure(ObjectClass *klass)
+{
+    return klass->type->secure;
+}
+
 const char *object_class_get_name(ObjectClass *klass)
 {
     return klass->type->name;
Signature · 1 line
2.55.0
#21 lore raw

PATCH 11/14 qom: refactor data passing for QOM list filtering

In reply to Daniel P. Berrangé

Currently the QOM list method can filter on the abstract flag, but extending the filtering to more variables requires a way to pass in extra data items. This requires a refactoring of the iterator to take a full struct as its opaque data item.

---
 qom/qom-qmp-cmds.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
qom/qom-qmp-cmds.c +12 -6
index 330895361d..b999e9f723 100644
@@ -151,9 +151,13 @@ QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
     return object_property_get_qobject(obj, property, errp);
 }
 
-static void qom_list_types_tramp(ObjectClass *klass, void *data)
+typedef struct {
+    ObjectTypeInfoList *list;
+} ObjectTypeInfoData;
+
+static void qom_list_types_tramp(ObjectClass *klass, void *opaque)
 {
-    ObjectTypeInfoList **pret = data;
+    ObjectTypeInfoData *data = opaque;
     ObjectTypeInfo *info;
     ObjectClass *parent = object_class_get_parent(klass);
 
@@ -164,7 +168,7 @@ static void qom_list_types_tramp(ObjectClass *klass, void *data)
         info->parent = g_strdup(object_class_get_name(parent));
     }
 
-    QAPI_LIST_PREPEND(*pret, info);
+    QAPI_LIST_PREPEND(data->list, info);
 }
 
 ObjectTypeInfoList *qmp_qom_list_types(const char *implements,
@@ -172,12 +176,14 @@ ObjectTypeInfoList *qmp_qom_list_types(const char *implements,
                                        bool abstract,
                                        Error **errp)
 {
-    ObjectTypeInfoList *ret = NULL;
+    ObjectTypeInfoData data = {
+        .list = NULL,
+    };
 
     module_load_qom_all();
-    object_class_foreach(qom_list_types_tramp, implements, abstract, &ret);
+    object_class_foreach(qom_list_types_tramp, implements, abstract, &data);
 
-    return ret;
+    return data.list;
 }
 
 ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
Signature · 1 line
2.55.0
#19 lore raw

PATCH 10/14 hw/core: report security status in query-machines

In reply to Daniel P. Berrangé
---
 hw/core/machine-qmp-cmds.c | 1 +
 qapi/machine.json          | 8 +++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
hw/core/machine-qmp-cmds.c +1 -0
index 543dd3201b..9c08b17510 100644
@@ -127,6 +127,7 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, bool compat_props,
         if (mc->default_ram_id) {
             info->default_ram_id = g_strdup(mc->default_ram_id);
         }
+        info->secure = object_class_is_secure(OBJECT_CLASS(mc));
 
         if (compat_props && mc->compat_props) {
             int i;
qapi/machine.json +7 -1
index 2d63c1bac3..942db9a52b 100644
@@ -196,6 +196,11 @@
 #     present when `query-machines` argument @compat-props is true.
 #     (since 9.1)
 #
+# @secure: If true, the machine is declared to provide a security
+#     boundary from the guest; if false the machine is either
+#     not providing a security boundary, or its status is undefined.
+#     (since 11.1)
+#
 # Features:
 #
 # @unstable: Member @compat-props is experimental.
@@ -209,7 +214,8 @@
             'deprecated': 'bool', '*default-cpu-type': 'str',
             '*default-ram-id': 'str', 'acpi': 'bool',
             '*compat-props': { 'type': ['CompatProperty'],
-                               'features': ['unstable'] } } }
+                               'features': ['unstable'] },
+            'secure': 'bool' } }
 
 ##
 # @query-machines:
Signature · 1 line
2.55.0
#23 lore raw

PATCH 12/14 qom: report & filter on security status in qom-list-types

In reply to Daniel P. Berrangé

This adds:

* a new boolean 'secure' field to the type info returned by qom-list-types, which will be set if the type provides a security boundary

* a new boolean 'secure' parameter to the arguments of qom-list-types, which can be used to filter types based on their security status

---
 qapi/qom.json      | 13 +++++++++++--
 qom/qom-qmp-cmds.c | 12 ++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)
qapi/qom.json +11 -2
index 4a9b7f9088..b14f063144 100644
@@ -210,12 +210,18 @@
 # @abstract: the type is abstract and can't be directly instantiated.
 #     Omitted if false.  (since 2.10)
 #
+# @secure: the type provides a security boundary.  Omitted if false.
+#     (since 11.2)
+#
 # @parent: Name of parent type, if any (since 2.10)
 #
 # Since: 1.1
 ##
 { 'struct': 'ObjectTypeInfo',
-  'data': { 'name': 'str', '*abstract': 'bool', '*parent': 'str' } }
+  'data': { 'name': 'str',
+            '*abstract': 'bool',
+            '*parent': 'str',
+            '*secure': 'bool' } }
 
 ##
 # @qom-list-types:
@@ -227,12 +233,15 @@
 #
 # @abstract: if true, include abstract types in the results
 #
+# @secure: if set, filter to only include types with matching security
+#     status (since 11.1)
+#
 # Returns: a list of types, or an empty list if no results are found
 #
 # Since: 1.1
 ##
 { 'command': 'qom-list-types',
-  'data': { '*implements': 'str', '*abstract': 'bool' },
+  'data': { '*implements': 'str', '*abstract': 'bool', '*secure': 'bool' },
   'returns': [ 'ObjectTypeInfo' ],
   'allow-preconfig': true }
 
qom/qom-qmp-cmds.c +12 -0
index b999e9f723..9474a1b04b 100644
@@ -153,6 +153,8 @@ QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
 
 typedef struct {
     ObjectTypeInfoList *list;
+    bool has_secure;
+    bool secure;
 } ObjectTypeInfoData;
 
 static void qom_list_types_tramp(ObjectClass *klass, void *opaque)
@@ -161,9 +163,15 @@ static void qom_list_types_tramp(ObjectClass *klass, void *opaque)
     ObjectTypeInfo *info;
     ObjectClass *parent = object_class_get_parent(klass);
 
+    if (data->has_secure &&
+        data->secure != object_class_is_secure(klass)) {
+        return;
+    }
+
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(object_class_get_name(klass));
     info->has_abstract = info->abstract = object_class_is_abstract(klass);
+    info->has_secure = info->secure = object_class_is_secure(klass);
     if (parent) {
         info->parent = g_strdup(object_class_get_name(parent));
     }
@@ -174,10 +182,14 @@ static void qom_list_types_tramp(ObjectClass *klass, void *opaque)
 ObjectTypeInfoList *qmp_qom_list_types(const char *implements,
                                        bool has_abstract,
                                        bool abstract,
+                                       bool has_secure,
+                                       bool secure,
                                        Error **errp)
 {
     ObjectTypeInfoData data = {
         .list = NULL,
+        .has_secure = has_secure,
+        .secure = secure,
     };
 
     module_load_qom_all();
Signature · 1 line
2.55.0
#15 lore raw

PATCH 8/14 system: check security of device types

In reply to Daniel P. Berrangé

This wires up the DeviceClass types to have their
security checked when devices are created.

---
 system/qdev-monitor.c | 4 ++++
 1 file changed, 4 insertions(+)
system/qdev-monitor.c +4 -0
index 5c87fda509..a69dbf802f 100644
@@ -672,6 +672,10 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
         return NULL;
     }
 
+    if (!object_class_check_security(OBJECT_CLASS(dc), errp)) {
+        return NULL;
+    }
+
     /* find bus */
     path = qdict_get_try_str(opts, "bus");
     if (path != NULL) {
Signature · 1 line
2.55.0
#13 lore raw

PATCH 7/14 system: report machine security status in help output

In reply to Daniel P. Berrangé

When '-machine help' is given, report the security status of each machine.

---
 system/vl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
system/vl.c +3 -2
index f54449b43e..468a9fc247 100644
@@ -1586,9 +1586,10 @@ static void machine_help_func(const QDict *qdict)
         if (mc->alias) {
             printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
         }
-        printf("%-20s %s%s%s\n", mc->name, mc->desc,
+        printf("%-20s %s%s%s%s\n", mc->name, mc->desc,
                mc->is_default ? " (default)" : "",
-               mc->deprecation_reason ? " (deprecated)" : "");
+               mc->deprecation_reason ? " (deprecated)" : "",
+               object_class_is_secure(OBJECT_CLASS(mc)) ? " (secure)" : "");
     }
 }
 
Signature · 1 line
2.55.0
#11 lore raw

PATCH 6/14 system: check security for machine types

In reply to Daniel P. Berrangé

This wires up the machine creation code to apply the compat policy security check.

---
 system/vl.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
system/vl.c +13 -2
index ca54da26c5..f54449b43e 100644
@@ -2201,11 +2201,18 @@ static void qemu_create_machine_containers(Object *machine)
     }
 }
 
-static void qemu_create_machine(QDict *qdict)
+static bool qemu_create_machine(QDict *qdict)
 {
+    Error *local_err = NULL;
     MachineClass *machine_class = select_machine(qdict, &error_fatal);
     object_set_machine_compat_props(machine_class->compat_props);
 
+    if (!object_class_check_security(OBJECT_CLASS(machine_class),
+                                     &local_err)) {
+        error_report_err(local_err);
+        return false;
+    }
+
     current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
     object_property_add_child(object_get_root(), "machine",
                               OBJECT(current_machine));
@@ -2237,6 +2244,8 @@ static void qemu_create_machine(QDict *qdict)
                                      false, &error_abort);
         qobject_unref(default_opts);
     }
+
+    return true;
 }
 
 static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
@@ -3790,7 +3799,9 @@ void qemu_init(int argc, char **argv)
     /* Transfer QemuOpts options into machine options */
     parse_memory_options();
 
-    qemu_create_machine(machine_opts_dict);
+    if (!qemu_create_machine(machine_opts_dict)) {
+        exit(1);
+    }
 
     /*
      * Load incoming CPR state before any devices are created, because it
Signature · 1 line
2.55.0
#7 lore raw

PATCH 4/14 system: check security for accelerator types

In reply to Daniel P. Berrangé

This wires up the accelerator creation code to apply the compat policy security check. When multiple -accel options are given, normal fallback logic applies. IOW, if one is rejected by the security check, it will carry on to try the next accelerator until one passes the security check.

---
 system/vl.c | 5 +++++
 1 file changed, 5 insertions(+)
system/vl.c +5 -0
index 9bd7664b85..0c6e44f21c 100644
@@ -2412,6 +2412,11 @@ static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
         }
         goto bad;
     }
+
+    if (!object_class_check_security(OBJECT_CLASS(ac), errp)) {
+        goto bad;
+    }
+
     accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
     object_apply_compat_props(OBJECT(accel));
     qemu_opt_foreach(opts, accelerator_set_property,
Signature · 1 line
2.55.0
#3 lore raw

PATCH 2/14 qapi: add 'insecure-types' option for -compat argument

In reply to Daniel P. Berrangé

This introduces a new 'insecure-types' option for the 'compat' argument that accepts three values

* accept: Allow any usage
* reject: Reject with an error reported
* warn: Allow any usage, with a warning reported

For historical compatibility it defaults to 'accept'.

The 'reject' and 'warn' values will take effect for any type that has been explicitly marked insecure, or is lacking an explicit declaration of its security status.

This new command line option is currently a no-op, but will become functional as following patches enable the checks.

---
 include/qapi/compat-policy.h |  5 +++++
 qapi/compat.json             | 23 ++++++++++++++++++++++-
 qapi/qapi-util.c             | 30 ++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 1 deletion(-)
include/qapi/compat-policy.h +5 -0
index ea65e10744..f5af209069 100644
@@ -24,6 +24,11 @@ bool compat_policy_input_ok(uint64_t features,
                             const char *kind, const char *name,
                             Error **errp);
 
+bool compat_policy_check_security(const CompatPolicy *policy,
+                                  const char *typename,
+                                  bool is_secure,
+                                  Error **errp);
+
 /*
  * Create a QObject input visitor for @obj for use with QMP
  *
qapi/compat.json +22 -1
index 90b8d51cf2..d57f25e112 100644
@@ -37,6 +37,23 @@
 { 'enum': 'CompatPolicyOutput',
   'data': [ 'accept', 'hide' ] }
 
+##
+# @CompatPolicySecurity:
+#
+# Policy for handling any devices or backends which do not provide a
+# security boundary to protect against untrusted environments
+#
+# @accept: Allow any usage
+#
+# @reject: Reject with an error reported
+#
+# @warn: Allow any usage, with a warning reported
+#
+# Since: 10.2
+##
+{ 'enum': 'CompatPolicySecurity',
+  'data': [ 'accept', 'reject', 'warn' ] }
+
 ##
 # @CompatPolicy:
 #
@@ -62,10 +79,14 @@
 # @unstable-output: how to handle unstable output (default 'accept')
 #     (since 6.2)
 #
+# @insecure-types: how to handle types that are not declared secure
+#     (default 'accept') (since 10.2)
+#
 # Since: 6.0
 ##
 { 'struct': 'CompatPolicy',
   'data': { '*deprecated-input': 'CompatPolicyInput',
             '*deprecated-output': 'CompatPolicyOutput',
             '*unstable-input': 'CompatPolicyInput',
-            '*unstable-output': 'CompatPolicyOutput' } }
+            '*unstable-output': 'CompatPolicyOutput',
+            '*insecure-types': 'CompatPolicySecurity' } }
qapi/qapi-util.c +30 -0
index 3d849fe034..38b1cec7a4 100644
@@ -14,6 +14,7 @@
 #include "qapi/compat-policy.h"
 #include "qapi/error.h"
 #include "qemu/ctype.h"
+#include "qemu/error-report.h"
 #include "qapi/qmp/qerror.h"
 
 CompatPolicy compat_policy;
@@ -58,6 +59,35 @@ bool compat_policy_input_ok(uint64_t features,
     return true;
 }
 
+bool compat_policy_check_security(const CompatPolicy *policy,
+                                  const char *typename,
+                                  bool is_secure,
+                                  Error **errp)
+{
+    if (is_secure) {
+        return true;
+    }
+
+    switch (policy->insecure_types) {
+    case COMPAT_POLICY_SECURITY_ACCEPT:
+        return true;
+
+    case COMPAT_POLICY_SECURITY_REJECT:
+        error_setg(errp, "Type '%s' does not provide a security boundary "
+                   "to protect against untrusted data or actions", typename);
+        return false;
+
+    case COMPAT_POLICY_SECURITY_WARN:
+        warn_report("Type '%s' does not provide a security boundary "
+                    "to protect against untrusted data or actions", typename);
+        return true;
+
+    default:
+        g_assert_not_reached();
+    }
+}
+
+
 const char *qapi_enum_lookup(const QEnumLookup *lookup, int val)
 {
     assert(val >= 0 && val < lookup->size);
Signature · 1 line
2.55.0
#9 lore raw

PATCH 5/14 system: report acclerator security status in help output

In reply to Daniel P. Berrangé

When '-accel help' is given, report the security status of each accelerator.

---
 system/vl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
system/vl.c +4 -1
index 0c6e44f21c..ca54da26c5 100644
@@ -3451,7 +3451,10 @@ void qemu_init(int argc, char **argv)
                             g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)) {
                             gchar **optname = g_strsplit(typename,
                                                          ACCEL_CLASS_SUFFIX, 0);
-                            printf("%s\n", optname[0]);
+                            printf("%s%s\n", optname[0],
+                                   object_class_is_secure(
+                                       OBJECT_CLASS(el->data)) ?
+                                   " (secure)" : "");
                             g_strfreev(optname);
                         }
                         g_free(typename);
Signature · 1 line
2.55.0
#25 lore raw

PATCH 13/14 docs: expand security docs with info about security status

In reply to Daniel P. Berrangé

The description of virtualization vs non-virtualization use cases is a crude approximation of the security characteristics of QEMU devices.

Document how QEMU can be probed to obtain information on the security status of type classes, and how policies can be set to inform or control their usage.

---
 docs/system/security.rst | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
docs/system/security.rst +36 -0
index 8c42d1a6d8..75e39caede 100644
@@ -158,6 +158,42 @@ an issue as a normal bug.
   usually not justify handling as security bugs, nor assignment
   of CVEs. They will be fixed as routine bugs when time allows.
 
+Security status reporting
+'''''''''''''''''''''''''
+
+The QEMU project annotates types to explicitly state whether they are
+considered to provide a security boundary or not. For machine, accelerator
+and device types, only those annotated with the "secure" flag will be
+eligible for CVE assignment. Annotations will be extended to other backend
+and object types over time, to make their security status explicit.
+
+It is possible to control or identify the usage of types that do not offer
+an explicit security boundary using the ``insecure-types`` parameter to the
+``-compat`` argument, which accepts three values:
+
+ * accept: usage of any type will be permitted. This is the current
+   and historical default behaviour
+ * warn: usage of types not explicitly declared secure will result
+   in a warning message, but still be permitted.
+ * reject: usage of types not explicitly declared secure will result
+   in an error message, and will not be permitted.
+
+The compatibility policy will be honoured both at initial startup of
+QEMU and during any runtime alterations made with monitor commands.
+
+The status of any type class can be queried at runtime using the
+``qom-list-types`` command, whose returned information will flag any
+types declared as secure. The ``query-machines`` command will also
+reflect this same information for machine types.
+
+Machine type, accelerator and device security status can be queried
+using ``-machine help``, ``-accel help`` and ``-device help`` command
+line options respectively.
+
+Setting the ``.secure`` field to ``true`` in the ``TypeInfo``
+instance for an Object class, declares that the type aims to provide
+a security boundary.
+
 Architecture
 ------------
 
Signature · 1 line
2.55.0
#27 lore raw

PATCH 14/14 machine: add helpers for declaring secure/insecure machine types

In reply to Daniel P. Berrangé

The current DEFINE_MACHINE macro will declare machine type without any explicit statement about the security status. As such the machine type will be treated as implicitly insecure at runtime.

Introduce a new DEFINE_SECURE_MACHINE macro (with variants) that allow code to make an explicit statement that the machine is treated as secure. This should primarily be used for versioned machine types that are intended to be used with KVM, though some others may warrant a security declaration.

Use of the existing macros marks a machine as insecure, which is the desired default for most machines servicing emulation use cases.

The same is done for the specialized i386 PC related macros.

---
 hw/arm/bananapi_m2u.c    |  2 +-
 hw/arm/cubieboard.c      |  2 +-
 hw/arm/imx8mm-evk.c      |  2 +-
 hw/arm/integratorcp.c    |  2 +-
 hw/arm/mcimx7d-sabre.c   |  2 +-
 hw/arm/orangepi.c        |  2 +-
 hw/ppc/pegasos.c         |  3 ++-
 include/hw/core/boards.h | 25 ++++++++++++++++++++-----
 include/hw/i386/pc.h     | 11 ++++++++++-
 9 files changed, 38 insertions(+), 13 deletions(-)
hw/arm/bananapi_m2u.c +1 -1
index 8f59111fd4..ccf60ba295 100644
@@ -153,4 +153,4 @@ static void bpim2u_machine_init(MachineClass *mc)
 }
 
 DEFINE_MACHINE_EXTENDED("bpim2u", MACHINE, Bpim2uMachineState,
-                        bpim2u_machine_init, false, NULL)
+                        bpim2u_machine_init, false, false, NULL)
hw/arm/cubieboard.c +1 -1
index ae27056938..e4fef9cd76 100644
@@ -133,5 +133,5 @@ static void cubieboard_machine_init(MachineClass *mc)
 }
 
 DEFINE_MACHINE_EXTENDED("cubieboard", MACHINE, CubieboardMachineState,
-                        cubieboard_machine_init, false,
+                        cubieboard_machine_init, false, false,
                         NULL)
hw/arm/imx8mm-evk.c +1 -1
index 8a5737502f..c3215b11cb 100644
@@ -134,5 +134,5 @@ static void imx8mm_evk_machine_init(MachineClass *mc)
 }
 
 DEFINE_MACHINE_EXTENDED("imx8mm-evk", MACHINE, Imx8mmEvkMachineState,
-                        imx8mm_evk_machine_init, false,
+                        imx8mm_evk_machine_init, false, false,
                         NULL)
hw/arm/integratorcp.c +1 -1
index 382ea7850d..b766edeeee 100644
@@ -704,7 +704,7 @@ static void integratorcp_machine_init(MachineClass *mc)
 }
 
 DEFINE_MACHINE_EXTENDED("integratorcp", MACHINE, IntegratorcpMachineState,
-                        integratorcp_machine_init, false,
+                        integratorcp_machine_init, false, false,
                         NULL)
 
 static const Property core_properties[] = {
hw/arm/mcimx7d-sabre.c +1 -1
index db8a62e5f6..65fdb19c06 100644
@@ -86,5 +86,5 @@ static void mcimx7d_sabre_machine_init(MachineClass *mc)
 }
 
 DEFINE_MACHINE_EXTENDED("mcimx7d-sabre", MACHINE, Mcimx7dSabreMachineState,
-                        mcimx7d_sabre_machine_init, false,
+                        mcimx7d_sabre_machine_init, false, false,
                         NULL)
hw/arm/orangepi.c +1 -1
index 7a19732f5d..18ed174032 100644
@@ -133,5 +133,5 @@ static void orangepi_machine_init(MachineClass *mc)
 }
 
 DEFINE_MACHINE_EXTENDED("orangepi-pc", MACHINE, OrangePiMachineState,
-                        orangepi_machine_init, false,
+                        orangepi_machine_init, false, false,
                         NULL)
hw/ppc/pegasos.c +2 -1
index 9d7e279123..fba2a55890 100644
@@ -788,7 +788,8 @@ static void pegasos2_machine_class_init(ObjectClass *oc, const void *data)
 }
 
 DEFINE_MACHINE_EXTENDED("pegasos", MACHINE, PegasosMachineState,
-                        pegasos_machine_init, true, (const InterfaceInfo[]) {
+                        pegasos_machine_init, true, false,
+                        (const InterfaceInfo[]) {
                         { TYPE_PPC_VIRTUAL_HYPERVISOR },
                         { TYPE_VOF_MACHINE_IF }, { } })
 
include/hw/core/boards.h +20 -5
index a436d48c8e..c2e0327a39 100644
@@ -514,7 +514,7 @@ struct MachineState {
  */
 
 #define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
-                                machine_initfn, ABSTRACT, ifaces...) \
+                                machine_initfn, ABSTRACT, SECURE, ifaces...) \
     static void machine_initfn##_class_init(ObjectClass *oc, const void *data) \
     { \
         MachineClass *mc = MACHINE_CLASS(oc); \
@@ -526,6 +526,7 @@ struct MachineState {
         .class_init = machine_initfn##_class_init, \
         .instance_size = sizeof(InstanceName), \
         .abstract = ABSTRACT, \
+        .secure     = SECURE, \
         .interfaces = ifaces, \
     }; \
     static void machine_initfn##_register_types(void) \
@@ -534,18 +535,32 @@ struct MachineState {
     } \
     type_init(machine_initfn##_register_types)
 
+/* Implicitly insecure */
 #define DEFINE_MACHINE(namestr, machine_initfn) \
     DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
-                            false, NULL)
+                            false, false, NULL)
 
-#define DEFINE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, ifaces...)\
+#define DEFINE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, ifaces...) \
     DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
-                            false, ifaces)
+                            false, false, ifaces)
 
-#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
+#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...)    \
     DEFINE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, \
                                         (const InterfaceInfo[]) { __VA_ARGS__ })
 
+
+#define DEFINE_SECURE_MACHINE(namestr, machine_initfn) \
+    DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
+                            false, true, NULL)
+
+#define DEFINE_SECURE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, ifaces...) \
+    DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
+                            false, true, ifaces)
+
+#define DEFINE_SECURE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
+    DEFINE_SECURE_MACHINE_WITH_INTERFACE_ARRAY(namestr, machine_initfn, \
+                                               (const InterfaceInfo[]) { __VA_ARGS__ })
+
 /*
  * Helper for dispatching different macros based on how
  * many __VA_ARGS__ are passed. Supports 1 to 5 variadic
include/hw/i386/pc.h +10 -1
index ac03da97b6..d5dc79df17 100644
@@ -275,7 +275,7 @@ extern const size_t pc_compat_4_2_len;
 extern GlobalProperty pc_compat_4_1[];
 extern const size_t pc_compat_4_1_len;
 
-#define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
+#define DEFINE_PC_MACHINE_EXTENDED(suffix, namestr, initfn, optsfn, issecure) \
     static void pc_machine_##suffix##_class_init(ObjectClass *oc, \
                                                  const void *data) \
     { \
@@ -287,6 +287,7 @@ extern const size_t pc_compat_4_1_len;
         .name       = namestr TYPE_MACHINE_SUFFIX, \
         .parent     = TYPE_PC_MACHINE, \
         .class_init = pc_machine_##suffix##_class_init, \
+        .secure     = issecure, \
     }; \
     static void pc_machine_init_##suffix(void) \
     { \
@@ -294,6 +295,14 @@ extern const size_t pc_compat_4_1_len;
     } \
     type_init(pc_machine_init_##suffix)
 
+/* Implicitly insecure */
+#define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
+    DEFINE_PC_MACHINE_EXTENDED(suffix, namestr, initfn, optsfn, false)
+
+#define DEFINE_SECURE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
+    DEFINE_PC_MACHINE_EXTENDED(suffix, namestr, initfn, optsfn, true)
+
+
 #define DEFINE_PC_VER_MACHINE(namesym, namestr, initfn, isdefault, malias, ...) \
     static void MACHINE_VER_SYM(init, namesym, __VA_ARGS__)( \
         MachineState *machine) \
Signature · 1 line
2.55.0
#17 lore raw

PATCH 9/14 system: report device security status in help output

In reply to Daniel P. Berrangé

When '-device help', 'device_add help' and 'info qdm' are used, report the security status of each device.

---
 system/qdev-monitor.c | 3 +++
 1 file changed, 3 insertions(+)
system/qdev-monitor.c +3 -0
index a69dbf802f..2120292fd5 100644
@@ -166,6 +166,9 @@ static void qdev_print_devinfo(DeviceClass *dc)
     if (!dc->user_creatable) {
         qemu_printf(", no-user");
     }
+    if (object_class_is_secure(OBJECT_CLASS(dc))) {
+        qemu_printf(", secure");
+    }
     qemu_printf("\n");
 }
 
Signature · 1 line
2.55.0
#5 lore raw

PATCH 3/14 qom: add helper APIs for checking object security policy compliance

In reply to Daniel P. Berrangé

These helpers simply avoid a verbose code pattern being repeated for many callers.

---
 include/qom/object.h | 26 ++++++++++++++++++++++++++
 qom/object.c         | 15 +++++++++++++++
 2 files changed, 41 insertions(+)
include/qom/object.h +26 -0
index 687ceb6bba..3b83ceb7b1 100644
@@ -2405,6 +2405,32 @@ Object *object_property_add_new_container(Object *obj, const char *name);
 char *object_property_help(const char *name, const char *type,
                            QObject *defval, const char *description);
 
+/**
+ * object_class_check_security:
+ * @klass: the object class to check
+ * @errp: a pointer to an Error that is filled if not compliant
+ *
+ * Check whether the object class @klass complies with the
+ * currently requested security policy. Reports an error
+ * in @errp if not compliant.
+ *
+ * Returns: true if compliant, false if an error was raised
+ */
+bool object_class_check_security(ObjectClass *klass, Error **errp);
+
+/**
+ * object_check_security:
+ * @obj: the object instance to check
+ * @errp: a pointer to an Error that is filled if not compliant
+ *
+ * Check whether the object @obj complies with the
+ * currently requested security policy. Reports an
+ * error in @errp if not compliant.
+ *
+ * Returns: true if compliant, false if an error was raised
+ */
+bool object_check_security(Object *obj, Error **errp);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref)
 
 #endif
qom/object.c +15 -0
index 32736a0111..2c93c17802 100644
@@ -23,6 +23,7 @@
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/forward-visitor.h"
 #include "qapi/qapi-builtin-visit.h"
+#include "qapi/compat-policy.h"
 #include "qobject/qdict.h"
 #include "qobject/qjson.h"
 #include "qemu/id.h"
@@ -3149,6 +3150,20 @@ void object_class_property_set_description(ObjectClass *klass,
     op->description = g_strdup(description);
 }
 
+bool object_class_check_security(ObjectClass *klass, Error **errp)
+{
+    return compat_policy_check_security(&compat_policy,
+                                        object_class_get_name(klass),
+                                        object_class_is_secure(klass),
+                                        errp);
+}
+
+bool object_check_security(Object *obj, Error **errp)
+{
+    ObjectClass *klass = OBJECT_CLASS(obj);
+    return object_class_check_security(klass, errp);
+}
+
 static void object_class_init(ObjectClass *klass, const void *data)
 {
     object_class_property_add_str(klass, "type", object_get_type,
Signature · 1 line
2.55.0
Reviewed-by on v1 3/14
#6 lore raw

Re: [PATCH 03/14] qom: add helper APIs for checking object security policy compliance

Quoted 60 lines

These helpers simply avoid a verbose code pattern being repeated for many callers.

Message-ID: <[email protected]>

include/qom/object.h +26 -0
index 687ceb6bba00..3b83ceb7b1ff 100644
@@ -2405,6 +2405,32 @@ Object *object_property_add_new_container(Object *obj, const char *name);
 char *object_property_help(const char *name, const char *type,
                            QObject *defval, const char *description);
 
+/**
+ * object_class_check_security:
+ * @klass: the object class to check
+ * @errp: a pointer to an Error that is filled if not compliant
+ *
+ * Check whether the object class @klass complies with the
+ * currently requested security policy. Reports an error
+ * in @errp if not compliant.
+ *
+ * Returns: true if compliant, false if an error was raised
+ */
+bool object_class_check_security(ObjectClass *klass, Error **errp);
+
+/**
+ * object_check_security:
+ * @obj: the object instance to check
+ * @errp: a pointer to an Error that is filled if not compliant
+ *
+ * Check whether the object @obj complies with the
+ * currently requested security policy. Reports an
+ * error in @errp if not compliant.
+ *
+ * Returns: true if compliant, false if an error was raised
+ */
+bool object_check_security(Object *obj, Error **errp);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(Object, object_unref)
 
 #endif
qom/object.c +2 -0
index 32736a011145..2c93c17802e9 100644
@@ -23,6 +23,7 @@
 #include "qapi/qobject-input-visitor.h"
 #include "qapi/forward-visitor.h"
 #include "qapi/qapi-builtin-visit.h"
+#include "qapi/compat-policy.h"
 #include "qobject/qdict.h"
 #include "qobject/qjson.h"
 #include "qemu/id.h"
@@ -3149,6 +3150,20 @@ void object_class_property_set_description(ObjectClass *klass,
     op->description = g_strdup(description);
 }
 
+bool object_class_check_security(ObjectClass *klass, Error **errp)

qom/object.c void object_class_property_set_description(ObjectClass *klass, · line 3163

Quoted 10 lines
qom/object.c +10 -0
+{
+    return compat_policy_check_security(&compat_policy,
+                                        object_class_get_name(klass),
+                                        object_class_is_secure(klass),
+                                        errp);
+}
+
+bool object_check_security(Object *obj, Error **errp)
+{
+    ObjectClass *klass = OBJECT_CLASS(obj);

This should be object_get_class(obj)

I am not sure the helper is really helpful though.

qom/object.c void object_class_property_set_description(ObjectClass *klass, · line 3169

Quoted 6 lines
qom/object.c +3 -0
+    return object_class_check_security(klass, errp);
+}
+
 static void object_class_init(ObjectClass *klass, const void *data)
 {
     object_class_property_add_str(klass, "type", object_get_type,
Signature · 1 line
Marc-André Lureau <[email protected]>
Reviewed-by on v1 2/14
#4 lore raw

Re: [PATCH 02/14] qapi: add 'insecure-types' option for -compat argument

In reply to Daniel P. Berrangé
Quoted 46 lines

This introduces a new 'insecure-types' option for the 'compat' argument that accepts three values

* accept: Allow any usage
* reject: Reject with an error reported
* warn: Allow any usage, with a warning reported

For historical compatibility it defaults to 'accept'.

The 'reject' and 'warn' values will take effect for any type that has been explicitly marked insecure, or is lacking an explicit declaration of its security status.

This new command line option is currently a no-op, but will become functional as following patches enable the checks.

Message-ID: <[email protected]>

include/qapi/compat-policy.h +5 -0
index ea65e10744ab..f5af20906923 100644
@@ -24,6 +24,11 @@ bool compat_policy_input_ok(uint64_t features,
                             const char *kind, const char *name,
                             Error **errp);
 
+bool compat_policy_check_security(const CompatPolicy *policy,
+                                  const char *typename,
+                                  bool is_secure,
+                                  Error **errp);
+
 /*
  * Create a QObject input visitor for @obj for use with QMP
  *
qapi/compat.json +3 -0
index 90b8d51cf27e..d57f25e112f8 100644
@@ -37,6 +37,23 @@
 { 'enum': 'CompatPolicyOutput',
   'data': [ 'accept', 'hide' ] }
 
+##
+# @CompatPolicySecurity:
+#

qapi/compat.json line 52

Quoted 10 lines
qapi/compat.json +10 -0
+# Policy for handling any devices or backends which do not provide a
+# security boundary to protect against untrusted environments
+#
+# @accept: Allow any usage
+#
+# @reject: Reject with an error reported
+#
+# @warn: Allow any usage, with a warning reported
+#
+# Since: 10.2

Since: 11.2

qapi/compat.json line 83

Quoted 13 lines
qapi/compat.json +6 -0
+##
+{ 'enum': 'CompatPolicySecurity',
+  'data': [ 'accept', 'reject', 'warn' ] }
+
 ##
 # @CompatPolicy:
 #
@@ -62,10 +79,14 @@
 # @unstable-output: how to handle unstable output (default 'accept')
 #     (since 6.2)
 #
+# @insecure-types: how to handle types that are not declared secure
+#     (default 'accept') (since 10.2)

(since 11.2)

Quoted 48 lines
qapi/compat.json +3 -1
+#
 # Since: 6.0
 ##
 { 'struct': 'CompatPolicy',
   'data': { '*deprecated-input': 'CompatPolicyInput',
             '*deprecated-output': 'CompatPolicyOutput',
             '*unstable-input': 'CompatPolicyInput',
-            '*unstable-output': 'CompatPolicyOutput' } }
+            '*unstable-output': 'CompatPolicyOutput',
+            '*insecure-types': 'CompatPolicySecurity' } }
qapi/qapi-util.c +23 -0
index 3d849fe0347f..38b1cec7a415 100644
@@ -14,6 +14,7 @@
 #include "qapi/compat-policy.h"
 #include "qapi/error.h"
 #include "qemu/ctype.h"
+#include "qemu/error-report.h"
 #include "qapi/qmp/qerror.h"
 
 CompatPolicy compat_policy;
@@ -58,6 +59,35 @@ bool compat_policy_input_ok(uint64_t features,
     return true;
 }
 
+bool compat_policy_check_security(const CompatPolicy *policy,
+                                  const char *typename,
+                                  bool is_secure,
+                                  Error **errp)
+{
+    if (is_secure) {
+        return true;
+    }
+
+    switch (policy->insecure_types) {
+    case COMPAT_POLICY_SECURITY_ACCEPT:
+        return true;
+
+    case COMPAT_POLICY_SECURITY_REJECT:
+        error_setg(errp, "Type '%s' does not provide a security boundary "
+                   "to protect against untrusted data or actions", typename);
+        return false;
+
+    case COMPAT_POLICY_SECURITY_WARN:
+        warn_report("Type '%s' does not provide a security boundary "
+                    "to protect against untrusted data or actions", typename);
+        return true;

qapi/qapi-util.c bool compat_policy_input_ok(uint64_t features, · line 93

Quoted 10 lines
qapi/qapi-util.c +7 -0
+
+    default:
+        g_assert_not_reached();
+    }
+}
+
+
 const char *qapi_enum_lookup(const QEnumLookup *lookup, int val)
 {
     assert(val >= 0 && val < lookup->size);
Signature · 1 line
Marc-André Lureau <[email protected]>
Reviewed-by on v1 4/14
#8 lore raw

Re: [PATCH 04/14] system: check security for accelerator types

In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé

This wires up the accelerator creation code to apply the compat policy security check. When multiple -accel options are given, normal fallback logic applies. IOW, if one is rejected by the security check, it will carry on to try the next accelerator until one passes the security check.

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
Reviewed-by on v1 13/14
#26 lore raw

Re: [PATCH 13/14] docs: expand security docs with info about security status

In reply to Daniel P. Berrangé
Quoted 9 lines · Daniel P. Berrangé

The description of virtualization vs non-virtualization use cases is a crude approximation of the security characteristics of QEMU devices.

Document how QEMU can be probed to obtain information on the security status of type classes, and how policies can be set to inform or control their usage.

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
Reviewed-by on v1 14/14
#28 lore raw

Re: [PATCH 14/14] machine: add helpers for declaring secure/insecure machine types

In reply to Daniel P. Berrangé
Quoted 11 lines · Daniel P. Berrangé

The current DEFINE_MACHINE macro will declare machine type without any explicit statement about the security status. As such the machine type will be treated as implicitly insecure at runtime.

Introduce a new DEFINE_SECURE_MACHINE macro (with variants) that allow code to make an explicit statement that the machine is treated as secure. This should primarily be used for versioned machine types that are intended to be used with KVM, though some others may warrant a security declaration.

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
Reviewed-by on v1 1/14
#2 lore raw

Re: [PATCH 01/14] qom: add tracking of security state of object types

In reply to Daniel P. Berrangé
Quoted 9 lines · Daniel P. Berrangé

This introduces a new flag "secure" against the Type/TypeInfo structs, and helpers to check this against the ObjectClass struct.

If an object is considered to provide a security boundary to protect against untrusted code, the "secure" flag must be explicitly set to true.

[...]

Signature · 1 line
Marc-André Lureau <[email protected]>
Reviewed-by on v1 10/14
#20 lore raw

Re: [PATCH 10/14] hw/core: report security status in query-machines

In reply to Daniel P. Berrangé
Quoted 20 lines

Message-ID: <[email protected]>

hw/core/machine-qmp-cmds.c +1 -0
index 543dd3201b5a..9c08b17510a3 100644
@@ -127,6 +127,7 @@ MachineInfoList *qmp_query_machines(bool has_compat_props, bool compat_props,
         if (mc->default_ram_id) {
             info->default_ram_id = g_strdup(mc->default_ram_id);
         }
+        info->secure = object_class_is_secure(OBJECT_CLASS(mc));
 
         if (compat_props && mc->compat_props) {
             int i;
qapi/machine.json +0 -0
index 2d63c1bac3b4..942db9a52ba7 100644

qapi/machine.json line 202

Quoted 7 lines
qapi/machine.json +4 -0
@@ -196,6 +196,11 @@
 #     present when `query-machines` argument @compat-props is true.
 #     (since 9.1)
 #
+# @secure: If true, the machine is declared to provide a security
+#     boundary from the guest; if false the machine is either
+#     not providing a security boundary, or its status is undefined.
+#     (since 11.1)

(since 11.2)

Quoted 5 lines
qapi/machine.json +1 -0
+#
 # Features:
 #
 # @unstable: Member @compat-props is experimental.

qapi/machine.json line 221

Quoted 9 lines
qapi/machine.json +2 -1
@@ -209,7 +214,8 @@
             'deprecated': 'bool', '*default-cpu-type': 'str',
             '*default-ram-id': 'str', 'acpi': 'bool',
             '*compat-props': { 'type': ['CompatProperty'],
-                               'features': ['unstable'] } } }
+                               'features': ['unstable'] },
+            'secure': 'bool' } }
 
 ##
 # @query-machines:
Signature · 1 line
Marc-André Lureau <[email protected]>
Reviewed-by on v1 12/14
#24 lore raw

Re: [PATCH 12/14] qom: report & filter on security status in qom-list-types

In reply to Daniel P. Berrangé
Quoted 38 lines

This adds:

* a new boolean 'secure' field to the type info returned by qom-list-types, which will be set if the type provides a security boundary

* a new boolean 'secure' parameter to the arguments of qom-list-types, which can be used to filter types based on their security status

Message-ID: <[email protected]>

qapi/qom.json +7 -1
index 4a9b7f908844..b14f063144b7 100644
@@ -210,12 +210,18 @@
 # @abstract: the type is abstract and can't be directly instantiated.
 #     Omitted if false.  (since 2.10)
 #
+# @secure: the type provides a security boundary.  Omitted if false.
+#     (since 11.2)
+#
 # @parent: Name of parent type, if any (since 2.10)
 #
 # Since: 1.1
 ##
 { 'struct': 'ObjectTypeInfo',
-  'data': { 'name': 'str', '*abstract': 'bool', '*parent': 'str' } }
+  'data': { 'name': 'str',
+            '*abstract': 'bool',
+            '*parent': 'str',
+            '*secure': 'bool' } }
 
 ##
 # @qom-list-types:

qapi/qom.json line 237

Quoted 5 lines
qapi/qom.json +2 -0
@@ -227,12 +233,15 @@
 #
 # @abstract: if true, include abstract types in the results
 #
+# @secure: if set, filter to only include types with matching security
+#     status (since 11.1)

(since 11.2)

Quoted 45 lines
qapi/qom.json +2 -1
+#
 # Returns: a list of types, or an empty list if no results are found
 #
 # Since: 1.1
 ##
 { 'command': 'qom-list-types',
-  'data': { '*implements': 'str', '*abstract': 'bool' },
+  'data': { '*implements': 'str', '*abstract': 'bool', '*secure': 'bool' },
   'returns': [ 'ObjectTypeInfo' ],
   'allow-preconfig': true }
 
qom/qom-qmp-cmds.c +9 -0
index b999e9f7238c..9474a1b04ba4 100644
@@ -153,6 +153,8 @@ QObject *qmp_qom_get(const char *path, const char *property, Error **errp)
 
 typedef struct {
     ObjectTypeInfoList *list;
+    bool has_secure;
+    bool secure;
 } ObjectTypeInfoData;
 
 static void qom_list_types_tramp(ObjectClass *klass, void *opaque)
@@ -161,9 +163,15 @@ static void qom_list_types_tramp(ObjectClass *klass, void *opaque)
     ObjectTypeInfo *info;
     ObjectClass *parent = object_class_get_parent(klass);
 
+    if (data->has_secure &&
+        data->secure != object_class_is_secure(klass)) {
+        return;
+    }
+
     info = g_malloc0(sizeof(*info));
     info->name = g_strdup(object_class_get_name(klass));
     info->has_abstract = info->abstract = object_class_is_abstract(klass);
+    info->has_secure = info->secure = object_class_is_secure(klass);
     if (parent) {
         info->parent = g_strdup(object_class_get_name(parent));
     }
@@ -174,10 +182,14 @@ static void qom_list_types_tramp(ObjectClass *klass, void *opaque)
 ObjectTypeInfoList *qmp_qom_list_types(const char *implements,
                                        bool has_abstract,
                                        bool abstract,
+                                       bool has_secure,

qom/qom-qmp-cmds.c static void qom_list_types_tramp(ObjectClass *klass, void *opaque) · line 195

Quoted 10 lines
qom/qom-qmp-cmds.c +3 -0
+                                       bool secure,
                                        Error **errp)
 {
     ObjectTypeInfoData data = {
         .list = NULL,
+        .has_secure = has_secure,
+        .secure = secure,
     };
 
     module_load_qom_all();
Signature · 1 line
Marc-André Lureau <[email protected]>
Reviewed-by on v1 11/14
#22 lore raw

Re: [PATCH 11/14] qom: refactor data passing for QOM list filtering

In reply to Daniel P. Berrangé
Quoted 4 lines · Daniel P. Berrangé

Currently the QOM list method can filter on the abstract flag, but extending the filtering to more variables requires a way to pass in extra data items. This requires a refactoring of the iterator to take a full struct as its opaque data item.

Signature · 1 line
Marc-André Lureau <[email protected]>