On Thu, May 08, 2025 at 10:59:19AM -0400, Xiaoyao Li wrote: > From: Isaku Yamahata <isaku.yamah...@intel.com> > > Three sha384 hash values, mrconfigid, mrowner and mrownerconfig, of a TD > can be provided for TDX attestation. Detailed meaning of them can be > found: > https://lore.kernel.org/qemu-devel/31d6dbc1-f453-4cef-ab08-4813f4e0f...@intel.com/ > > Allow user to specify those values via property mrconfigid, mrowner and > mrownerconfig. They are all in base64 format. > > example > -object tdx-guest, \ > > mrconfigid=ASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8BI0VniavN7wEjRWeJq83v,\ > mrowner=ASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8BI0VniavN7wEjRWeJq83v,\ > > mrownerconfig=ASNFZ4mrze8BI0VniavN7wEjRWeJq83vASNFZ4mrze8BI0VniavN7wEjRWeJq83v > > Signed-off-by: Isaku Yamahata <isaku.yamah...@intel.com> > Co-developed-by: Xiaoyao Li <xiaoyao...@intel.com> > Signed-off-by: Xiaoyao Li <xiaoyao...@intel.com> > Acked-by: Markus Armbruster <arm...@redhat.com> > Reviewed-by: Zhao Liu <zhao1....@intel.com> > --- > Changes in v9: > - return -1 directly when qbase64_decode() return NULL; (Daniel) > > Changes in v8: > - it gets squashed into previous patch in v7. So split it out in v8; > > Changes in v6: > - refine the doc comment of QAPI properties; > > Changes in v5: > - refine the description of QAPI properties and add description of > default value when not specified; > > Changes in v4: > - describe more of there fields in qom.json > - free the old value before set new value to avoid memory leak in > _setter(); (Daniel) > > Changes in v3: > - use base64 encoding instread of hex-string; > --- > qapi/qom.json | 16 +++++++- > target/i386/kvm/tdx.c | 95 +++++++++++++++++++++++++++++++++++++++++++ > target/i386/kvm/tdx.h | 3 ++ > 3 files changed, 113 insertions(+), 1 deletion(-) > > diff --git a/qapi/qom.json b/qapi/qom.json > index f229bb07aaec..a8379bac1719 100644 > --- a/qapi/qom.json > +++ b/qapi/qom.json > @@ -1060,11 +1060,25 @@ > # pages. Some guest OS (e.g., Linux TD guest) may require this to > # be set, otherwise they refuse to boot. > # > +# @mrconfigid: ID for non-owner-defined configuration of the guest TD, > +# e.g., run-time or OS configuration (base64 encoded SHA384 digest). > +# Defaults to all zeros. > +# > +# @mrowner: ID for the guest TD’s owner (base64 encoded SHA384 digest). > +# Defaults to all zeros. > +# > +# @mrownerconfig: ID for owner-defined configuration of the guest TD, > +# e.g., specific to the workload rather than the run-time or OS > +# (base64 encoded SHA384 digest). Defaults to all zeros. > +# > # Since: 10.1 > ## > { 'struct': 'TdxGuestProperties', > 'data': { '*attributes': 'uint64', > - '*sept-ve-disable': 'bool' } } > + '*sept-ve-disable': 'bool', > + '*mrconfigid': 'str', > + '*mrowner': 'str', > + '*mrownerconfig': 'str' } } > > ## > # @ThreadContextProperties: > diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c > index 3de3b5fa6a49..39fd964c6b27 100644 > --- a/target/i386/kvm/tdx.c > +++ b/target/i386/kvm/tdx.c > @@ -11,8 +11,10 @@ > > #include "qemu/osdep.h" > #include "qemu/error-report.h" > +#include "qemu/base64.h" > #include "qapi/error.h" > #include "qom/object_interfaces.h" > +#include "crypto/hash.h" > > #include "hw/i386/x86.h" > #include "kvm_i386.h" > @@ -240,6 +242,7 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) > CPUX86State *env = &x86cpu->env; > g_autofree struct kvm_tdx_init_vm *init_vm = NULL; > Error *local_err = NULL; > + size_t data_len; > int retry = 10000; > int r = 0; > > @@ -251,6 +254,45 @@ int tdx_pre_create_vcpu(CPUState *cpu, Error **errp) > init_vm = g_malloc0(sizeof(struct kvm_tdx_init_vm) + > sizeof(struct kvm_cpuid_entry2) * > KVM_MAX_CPUID_ENTRIES); > > + if (tdx_guest->mrconfigid) { > + g_autofree uint8_t *data = qbase64_decode(tdx_guest->mrconfigid, > + strlen(tdx_guest->mrconfigid), &data_len, > errp); > + if (!data) { > + return -1; > + } > + if (data_len != QCRYPTO_HASH_DIGEST_LEN_SHA384) { > + error_setg(errp, "TDX: failed to decode mrconfigid");
As a general guideline I'd always suggest including both the received and expected values, when reporting an length check failure. Also the error message is misleading - we successfully decoded the data, the decoded data was simply the wrong length. eg error_setg(errp, "TDX mrconfigid sha386 digest was %d bytes, expected %d bytes") data_len, QCRYPTO_HASH_DIGEST_LEN_SHA384); With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|