From nobody Mon Apr 29 23:00:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1593880882; cv=none; d=zohomail.com; s=zohoarc; b=ZFGCuNrcZKlN7o3Jb2m1JZ4ertkd76CAQpvZ+EkfY/oBttSWVGr7k7oo3ZY0c44I7NRol1HxmMoQukh1w0SzFiZXTkFR38uQa/LYVWk/2z8bUU8/FX5PTvhtpSd8ILGABZY708oGx/6Pu+7xS191ugFaI2GY9F74w2+XMUear8Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593880882; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tGgpow3fwqJFSNYPiLjkxhuOpLJ3WBNs9Q9LxXK/UYk=; b=nsDuvOc6COX0uNKltC3QinAuDPtkjA/GSV5blQ5Ke9p1xBevSGek1ubPuFVqy7WZJRh3N0Ck0kvlvs50G/IxS30OEJnR/mxODXVrkRsZiCCxlDmojxwU8EghqL7Sxjr99qxwf58PFAPgPxD6bdhVV14+bpRAZvrw55ywjVjZ6uE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593880882788242.65466344765173; Sat, 4 Jul 2020 09:41:22 -0700 (PDT) Received: from localhost ([::1]:58682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrlE9-0001yl-CX for importer@patchew.org; Sat, 04 Jul 2020 12:41:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrlCb-0008EX-NF for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:45 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:36596 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jrlCY-0005QZ-Ts for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:45 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-367-HYY6zhycPmiXQpKZBXNflQ-1; Sat, 04 Jul 2020 12:39:36 -0400 Received: by mail-wr1-f69.google.com with SMTP id j3so16494149wrq.9 for ; Sat, 04 Jul 2020 09:39:36 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id z25sm16145518wmk.28.2020.07.04.09.39.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 09:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593880782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tGgpow3fwqJFSNYPiLjkxhuOpLJ3WBNs9Q9LxXK/UYk=; b=OR+EJsN7QaiPm77/WRGL9/fZ7tmUo52H3CsOm/WXzbPBxHY44X4QIvsgpXDVVZCztwN8jg 1CbrknUFbbFOlc9lX4saMNdsbP3/7ezbWoWuyYugH0FZ75/R2ihm2KwN3pJGSBVgKJcEBB wsCwwIr7rKoRoJ2rxMznfoDMn+pKX0Y= X-MC-Unique: HYY6zhycPmiXQpKZBXNflQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tGgpow3fwqJFSNYPiLjkxhuOpLJ3WBNs9Q9LxXK/UYk=; b=Oo/NFLPZrtWX7KMZLWllAVSjvxRDZFcM4Lst3bzFXV+ZdpUE6H+QzBDwMmk/aTbVCV QaxV+HtVC0dNmWY0gv8lJdcp0PYp1PyUiYpKNpQYMBe6OJ5m/cpQ19fCOb8dsRACd7C/ XAT19Qd0Lf+SqafoTooBlhkO6gDl60vYHTG4RN2MHudo2SV9vzgY52gNWALsXF00JFiW 19JG7BNpftJ7evuX5I1WY4WCbkxqGTeoidBm74tpY+3kQZvJ2dNSnVbtw1Z0gJ103+qp H+8nRgtIduDyF7Z9nOz+LqWno729mThy64zw3kg2lUOvUuXHLFY9AeCEA/FQ+QsELPs8 cyzQ== X-Gm-Message-State: AOAM532azBU1nL3CryfkDEYghYeRnKyHb4l/r6mzmaRcRkLUFh8giYmX dzyNYvGMV1rwkuoaKmrLn4F83mOehlIBv2jTvZ0exud8fsxhntl/v+HoK8h1j7XubuoArMmF35P /UtK3wsy0Xb0pEMQ= X-Received: by 2002:a05:600c:2483:: with SMTP id 3mr2535081wms.120.1593880775332; Sat, 04 Jul 2020 09:39:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxv/k7RO+RQuZB9oZZkiFzi2raaBePLIpC0SLyxIrAPEFeX3z5iGrBLf48Fm8a7wskDFjRdqw== X-Received: by 2002:a05:600c:2483:: with SMTP id 3mr2535067wms.120.1593880775000; Sat, 04 Jul 2020 09:39:35 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 1/5] crypto: Add tls-cipher-suites object Date: Sat, 4 Jul 2020 18:39:23 +0200 Message-Id: <20200704163927.28188-2-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200704163927.28188-1-philmd@redhat.com> References: <20200704163927.28188-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/04 08:57:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Laszlo Ersek , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) On the host OS, various aspects of TLS operation are configurable. In particular it is possible for the sysadmin to control the TLS cipher/protocol algorithms that applications are permitted to use. * Any given crypto library has a built-in default priority list defined by the distro maintainer of the library package (or by upstream). * The "crypto-policies" RPM (or equivalent host OS package) provides a config file such as "/etc/crypto-policies/config", where the sysadmin can set a high level (library-independent) policy. The "update-crypto-policies --set" command (or equivalent) is used to translate the global policy to individual library representations, producing files such as "/etc/crypto-policies/back-ends/*.config". The generated files, if present, are loaded by the various crypto libraries to override their own built-in defaults. For example, the GNUTLS library may read "/etc/crypto-policies/back-ends/gnutls.config". * A management application (or the QEMU user) may overide the system-wide crypto-policies config via their own config, if they need to diverge from the former. Thus the priority order is "QEMU user config" > "crypto-policies system config" > "library built-in config". Introduce the "tls-cipher-suites" object for exposing the ordered list of permitted TLS cipher suites from the host side to the guest firmware, via fw_cfg. The list is represented as an array of bytes. The priority at which the host-side policy is retrieved is given by the "priority" property of the new object type. For example, "priority=3D@SYSTEM" may be used to refer to "/etc/crypto-policies/back-ends/gnutls.config" (given that QEMU uses GNUTLS). The firmware uses the IANA_TLS_CIPHER array for configuring guest-side TLS, for example in UEFI HTTPS Boot. [Description from Daniel P. Berrang=C3=A9, edited by Laszlo Ersek.] Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 Acked-by: Laszlo Ersek Message-Id: <20200623172726.21040-2-philmd@redhat.com> --- include/crypto/tls-cipher-suites.h | 39 ++++++++++ crypto/tls-cipher-suites.c | 115 +++++++++++++++++++++++++++++ crypto/Makefile.objs | 1 + crypto/trace-events | 5 ++ qemu-options.hx | 19 +++++ 5 files changed, 179 insertions(+) create mode 100644 include/crypto/tls-cipher-suites.h create mode 100644 crypto/tls-cipher-suites.c diff --git a/include/crypto/tls-cipher-suites.h b/include/crypto/tls-cipher= -suites.h new file mode 100644 index 0000000000..28b3a73ce1 --- /dev/null +++ b/include/crypto/tls-cipher-suites.h @@ -0,0 +1,39 @@ +/* + * QEMU TLS Cipher Suites Registry (RFC8447) + * + * Copyright (c) 2018-2020 Red Hat, Inc. + * + * Author: Philippe Mathieu-Daud=C3=A9 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QCRYPTO_TLSCIPHERSUITES_H +#define QCRYPTO_TLSCIPHERSUITES_H + +#include "qom/object.h" +#include "crypto/tlscreds.h" + +#define TYPE_QCRYPTO_TLS_CIPHER_SUITES "tls-cipher-suites" +#define QCRYPTO_TLS_CIPHER_SUITES(obj) \ + OBJECT_CHECK(QCryptoTLSCipherSuites, (obj), TYPE_QCRYPTO_TLS_CIPHER_SU= ITES) + +typedef struct QCryptoTLSCipherSuites { + /* */ + QCryptoTLSCreds parent_obj; + /* */ +} QCryptoTLSCipherSuites; + +/** + * qcrypto_tls_cipher_suites_get_data: + * @obj: pointer to a TLS cipher suites object + * @errp: pointer to a NULL-initialized error object + * + * Returns: reference to a byte array containing the data. + * The caller should release the reference when no longer + * required. + */ +GByteArray *qcrypto_tls_cipher_suites_get_data(QCryptoTLSCipherSuites *obj, + Error **errp); + +#endif /* QCRYPTO_TLSCIPHERSUITES_H */ diff --git a/crypto/tls-cipher-suites.c b/crypto/tls-cipher-suites.c new file mode 100644 index 0000000000..a4e0f84307 --- /dev/null +++ b/crypto/tls-cipher-suites.c @@ -0,0 +1,115 @@ +/* + * QEMU TLS Cipher Suites + * + * Copyright (c) 2018-2020 Red Hat, Inc. + * + * Author: Philippe Mathieu-Daud=C3=A9 + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qom/object_interfaces.h" +#include "crypto/tlscreds.h" +#include "crypto/tls-cipher-suites.h" +#include "trace.h" + +/* + * IANA registered TLS ciphers: + * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tl= s-parameters-4 + */ +typedef struct { + uint8_t data[2]; +} QEMU_PACKED IANA_TLS_CIPHER; + +GByteArray *qcrypto_tls_cipher_suites_get_data(QCryptoTLSCipherSuites *obj, + Error **errp) +{ + QCryptoTLSCreds *creds =3D QCRYPTO_TLS_CREDS(obj); + gnutls_priority_t pcache; + GByteArray *byte_array; + const char *err; + size_t i; + int ret; + + trace_qcrypto_tls_cipher_suite_priority(creds->priority); + ret =3D gnutls_priority_init(&pcache, creds->priority, &err); + if (ret < 0) { + error_setg(errp, "Syntax error using priority '%s': %s", + creds->priority, gnutls_strerror(ret)); + return NULL; + } + + byte_array =3D g_byte_array_new(); + + for (i =3D 0;; i++) { + int ret; + unsigned idx; + const char *name; + IANA_TLS_CIPHER cipher; + gnutls_protocol_t protocol; + const char *version; + + ret =3D gnutls_priority_get_cipher_suite_index(pcache, i, &idx); + if (ret =3D=3D GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) { + break; + } + if (ret =3D=3D GNUTLS_E_UNKNOWN_CIPHER_SUITE) { + continue; + } + + name =3D gnutls_cipher_suite_info(idx, (unsigned char *)&cipher, + NULL, NULL, NULL, &protocol); + if (name =3D=3D NULL) { + continue; + } + + version =3D gnutls_protocol_get_name(protocol); + g_byte_array_append(byte_array, cipher.data, 2); + trace_qcrypto_tls_cipher_suite_info(cipher.data[0], + cipher.data[1], + version, name); + } + trace_qcrypto_tls_cipher_suite_count(byte_array->len); + gnutls_priority_deinit(pcache); + + return byte_array; +} + +static void qcrypto_tls_cipher_suites_complete(UserCreatable *uc, + Error **errp) +{ + QCryptoTLSCreds *creds =3D QCRYPTO_TLS_CREDS(uc); + + if (!creds->priority) { + error_setg(errp, "'priority' property is not set"); + return; + } +} + +static void qcrypto_tls_cipher_suites_class_init(ObjectClass *oc, void *da= ta) +{ + UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); + + ucc->complete =3D qcrypto_tls_cipher_suites_complete; +} + +static const TypeInfo qcrypto_tls_cipher_suites_info =3D { + .parent =3D TYPE_QCRYPTO_TLS_CREDS, + .name =3D TYPE_QCRYPTO_TLS_CIPHER_SUITES, + .instance_size =3D sizeof(QCryptoTLSCreds), + .class_size =3D sizeof(QCryptoTLSCredsClass), + .class_init =3D qcrypto_tls_cipher_suites_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } +}; + +static void qcrypto_tls_cipher_suites_register_types(void) +{ + type_register_static(&qcrypto_tls_cipher_suites_info); +} + +type_init(qcrypto_tls_cipher_suites_register_types); diff --git a/crypto/Makefile.objs b/crypto/Makefile.objs index 707c02ad37..f1965b1a68 100644 --- a/crypto/Makefile.objs +++ b/crypto/Makefile.objs @@ -13,6 +13,7 @@ crypto-obj-y +=3D cipher.o crypto-obj-$(CONFIG_AF_ALG) +=3D afalg.o crypto-obj-$(CONFIG_AF_ALG) +=3D cipher-afalg.o crypto-obj-$(CONFIG_AF_ALG) +=3D hash-afalg.o +crypto-obj-$(CONFIG_GNUTLS) +=3D tls-cipher-suites.o crypto-obj-y +=3D tlscreds.o crypto-obj-y +=3D tlscredsanon.o crypto-obj-y +=3D tlscredspsk.o diff --git a/crypto/trace-events b/crypto/trace-events index 9e594d30e8..798b6067ab 100644 --- a/crypto/trace-events +++ b/crypto/trace-events @@ -21,3 +21,8 @@ qcrypto_tls_creds_x509_load_cert_list(void *creds, const = char *file) "TLS creds # tlssession.c qcrypto_tls_session_new(void *session, void *creds, const char *hostname, = const char *authzid, int endpoint) "TLS session new session=3D%p creds=3D%p= hostname=3D%s authzid=3D%s endpoint=3D%d" qcrypto_tls_session_check_creds(void *session, const char *status) "TLS se= ssion check creds session=3D%p status=3D%s" + +# tls-cipher-suites.c +qcrypto_tls_cipher_suite_priority(const char *name) "priority: %s" +qcrypto_tls_cipher_suite_info(uint8_t data0, uint8_t data1, const char *ve= rsion, const char *name) "data=3D[0x%02x,0x%02x] version=3D%s name=3D%s" +qcrypto_tls_cipher_suite_count(unsigned count) "count: %u" diff --git a/qemu-options.hx b/qemu-options.hx index 196f468786..ecc4658e1f 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4567,6 +4567,25 @@ SRST string as described at https://gnutls.org/manual/html_node/Priority-Strings.html. =20 + ``-object tls-cipher-suites,id=3Did,priority=3Dpriority`` + Creates a TLS cipher suites object, which can be used to control + the TLS cipher/protocol algorithms that applications are permitted + to use. + + The ``id`` parameter is a unique ID which frontends will use to + access the ordered list of permitted TLS cipher suites from the + host. + + The ``priority`` parameter allows to override the global default + priority used by gnutls. This can be useful if the system + administrator needs to use a weaker set of crypto priorities for + QEMU without potentially forcing the weakness onto all + applications. Or conversely if one wants wants a stronger + default for QEMU than for all other applications, they can do + this through this parameter. Its format is a gnutls priority + string as described at + https://gnutls.org/manual/html_node/Priority-Strings.html. + ``-object filter-buffer,id=3Did,netdev=3Dnetdevid,interval=3Dt[,queue= =3Dall|rx|tx][,status=3Don|off][,position=3Dhead|tail|id=3D][,insert=3D= behind|before]`` Interval t can't be 0, this filter batches the packet delivery: all packets arriving in a given interval on netdev netdevid are --=20 2.21.3 From nobody Mon Apr 29 23:00:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1593880879; cv=none; d=zohomail.com; s=zohoarc; b=ZzLIBXFPhq/ywpUmrGRLoMarh+IvfkN93BfeXb6IDzTgoeBJWRQrFb6YvRDcX3YvF81rcYK2zjaFEJ0Hm57JeLoMX25Yl/YCFlBsLjCKGZz2HapyYKRf8bKCK4XZtLsoIRqGKl0H9JMSb3j2FlqTuin5xlqJGGnX4PvwA5RbBS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593880879; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ly7Mh/MsxnHK8kvX80uCzcBlp2jF7lpo+aVEzFBklDY=; b=nvWXmPFpVphTvlfALnJg6jdJ468ra1Bp5WYJHRninqlDmMDV6ILHNU+UvyyiTWv5adRCL9aRmQif/Ari8DIc3+7+XwlD8Qt7HToErfuLuRFC5Zzki4y63zuGjlRROFcSdo12r2lSjvRNoYRHFM+sot8va29PCi5f0uV/WmjbkuQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593880879309549.4292125074099; Sat, 4 Jul 2020 09:41:19 -0700 (PDT) Received: from localhost ([::1]:58502 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrlE5-0001tO-Vw for importer@patchew.org; Sat, 04 Jul 2020 12:41:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52556) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrlCb-0008Do-0z for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:45 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:57297 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jrlCZ-0005Qb-2L for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:44 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-33-CqNUEqBiMHugSeo8_Pgw0w-1; Sat, 04 Jul 2020 12:39:41 -0400 Received: by mail-wm1-f70.google.com with SMTP id h25so23272176wmb.0 for ; Sat, 04 Jul 2020 09:39:40 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p4sm18450569wrx.63.2020.07.04.09.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 09:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593880782; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ly7Mh/MsxnHK8kvX80uCzcBlp2jF7lpo+aVEzFBklDY=; b=bAJrP+dB/5gZt65CPAfxsnKWFE1goISf4Pn+3PwWGTcr+sHSEADdtb6dSCOYHhT1dtTmbq qH3Xb6rBcus2m+/KBTpQydt0pi3Oo4xjQFof6Lii4J1WCh+pYsP7onxfNM79Je9652k5bJ kwXjUbd3Y1DyRqxJ6ly0ttH4yk2sQZc= X-MC-Unique: CqNUEqBiMHugSeo8_Pgw0w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ly7Mh/MsxnHK8kvX80uCzcBlp2jF7lpo+aVEzFBklDY=; b=l4CMPsu0pA0bHj+z8bD10rFTDKF0ukje9LBCVqjIpgSvL20tdEkzut0xWO8symSJ49 0mhyaHS42sf+c8D6l683A4La4APu/rTmsn1xKc2jr8Q241NSDPbA49Z9SEvwD9OJkj9O t0FRQN+aD9tLtXcUcdZqOIeTzi4kApe74pBNYtMsgiUDlrUSfB9ADHOhacES1hUpwwNl +FskYc0hbOtnvSDi9rDh15SaMb9g5DbVFsYXtE8H4DUz7caH98JWphCkZ68g32JYeFyM ef7/uNV05PswfWtKXgC876LL4oWibDq/FRczbN8o7nXZEbjmRFdZppcS+AMcy5bEf9Gv CI2Q== X-Gm-Message-State: AOAM533CL5ZMcsjeu+nGktcMfO61Jn44k7QVFGSLv9PirPSyxka7J1oD 6a98CNqJ6mO8+bHfrflRikmfvhCPUxEqkrOz5JPjeO2LOeADYI1TTvIojyre0SWMgI5thfYZtjS GavHug53eDqiNAmE= X-Received: by 2002:a5d:4e87:: with SMTP id e7mr43947450wru.12.1593880779837; Sat, 04 Jul 2020 09:39:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxStQY7DqaDzjpgqkNKCE5sSBSID+KJGKErpabAHJqmPvoUCQ4P7ct3NV8U0tih5PCicHLeDw== X-Received: by 2002:a5d:4e87:: with SMTP id e7mr43947434wru.12.1593880779614; Sat, 04 Jul 2020 09:39:39 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 2/5] hw/nvram/fw_cfg: Add the FW_CFG_DATA_GENERATOR interface Date: Sat, 4 Jul 2020 18:39:24 +0200 Message-Id: <20200704163927.28188-3-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200704163927.28188-1-philmd@redhat.com> References: <20200704163927.28188-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/04 11:39:14 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Laszlo Ersek , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The FW_CFG_DATA_GENERATOR allows any object to produce blob of data consumable by the fw_cfg device. Reviewed-by: Laszlo Ersek Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20200623172726.21040-3-philmd@redhat.com> --- docs/specs/fw_cfg.txt | 9 +++++++- include/hw/nvram/fw_cfg.h | 43 +++++++++++++++++++++++++++++++++++++++ hw/nvram/fw_cfg.c | 35 +++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/docs/specs/fw_cfg.txt b/docs/specs/fw_cfg.txt index 8f1ebc66fa..bc16daa38a 100644 --- a/docs/specs/fw_cfg.txt +++ b/docs/specs/fw_cfg.txt @@ -219,7 +219,7 @@ To check the result, read the "control" field: =20 =3D Externally Provided Items =3D =20 -As of v2.4, "file" fw_cfg items (i.e., items with selector keys above +Since v2.4, "file" fw_cfg items (i.e., items with selector keys above FW_CFG_FILE_FIRST, and with a corresponding entry in the fw_cfg file directory structure) may be inserted via the QEMU command line, using the following syntax: @@ -230,6 +230,13 @@ Or =20 -fw_cfg [name=3D],string=3D =20 +Since v5.1, QEMU allows some objects to generate fw_cfg-specific content, +the content is then associated with a "file" item using the 'gen_id' option +in the command line, using the following syntax: + + -object ,id=3D,[generator-specific-optio= ns] \ + -fw_cfg [name=3D],gen_id=3D + See QEMU man page for more documentation. =20 Using item_name with plain ASCII characters only is recommended. diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h index 25d9307018..11feae3177 100644 --- a/include/hw/nvram/fw_cfg.h +++ b/include/hw/nvram/fw_cfg.h @@ -9,11 +9,36 @@ #define TYPE_FW_CFG "fw_cfg" #define TYPE_FW_CFG_IO "fw_cfg_io" #define TYPE_FW_CFG_MEM "fw_cfg_mem" +#define TYPE_FW_CFG_DATA_GENERATOR_INTERFACE "fw_cfg-data-generator" =20 #define FW_CFG(obj) OBJECT_CHECK(FWCfgState, (obj), TYPE_FW_CFG) #define FW_CFG_IO(obj) OBJECT_CHECK(FWCfgIoState, (obj), TYPE_FW_CFG_IO) #define FW_CFG_MEM(obj) OBJECT_CHECK(FWCfgMemState, (obj), TYPE_FW_CFG_MEM) =20 +#define FW_CFG_DATA_GENERATOR_CLASS(class) \ + OBJECT_CLASS_CHECK(FWCfgDataGeneratorClass, (class), \ + TYPE_FW_CFG_DATA_GENERATOR_INTERFACE) +#define FW_CFG_DATA_GENERATOR_GET_CLASS(obj) \ + OBJECT_GET_CLASS(FWCfgDataGeneratorClass, (obj), \ + TYPE_FW_CFG_DATA_GENERATOR_INTERFACE) + +typedef struct FWCfgDataGeneratorClass { + /*< private >*/ + InterfaceClass parent_class; + /*< public >*/ + + /** + * get_data: + * @obj: the object implementing this interface + * @errp: pointer to a NULL-initialized error object + * + * Returns: reference to a byte array containing the data. + * The caller should release the reference when no longer + * required. + */ + GByteArray *(*get_data)(Object *obj, Error **errp); +} FWCfgDataGeneratorClass; + typedef struct fw_cfg_file FWCfgFile; =20 #define FW_CFG_ORDER_OVERRIDE_VGA 70 @@ -263,6 +288,24 @@ void fw_cfg_add_file_callback(FWCfgState *s, const cha= r *filename, void *fw_cfg_modify_file(FWCfgState *s, const char *filename, void *data, size_t len); =20 +/** + * fw_cfg_add_from_generator: + * @s: fw_cfg device being modified + * @filename: name of new fw_cfg file item + * @gen_id: name of object implementing FW_CFG_DATA_GENERATOR interface + * @errp: pointer to a NULL initialized error object + * + * Add a new NAMED fw_cfg item with the content generated from the + * @gen_id object. The data generated by the @gen_id object is copied + * into the data structure of the fw_cfg device. + * The next available (unused) selector key starting at FW_CFG_FILE_FIRST + * will be used; also, a new entry will be added to the file directory + * structure residing at key value FW_CFG_FILE_DIR, containing the item na= me, + * data size, and assigned selector key value. + */ +void fw_cfg_add_from_generator(FWCfgState *s, const char *filename, + const char *gen_id, Error **errp); + FWCfgState *fw_cfg_init_io_dma(uint32_t iobase, uint32_t dma_iobase, AddressSpace *dma_as); FWCfgState *fw_cfg_init_io(uint32_t iobase); diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 0408a31f8e..694722b212 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -1032,6 +1032,35 @@ void *fw_cfg_modify_file(FWCfgState *s, const char *= filename, return NULL; } =20 +void fw_cfg_add_from_generator(FWCfgState *s, const char *filename, + const char *gen_id, Error **errp) +{ + FWCfgDataGeneratorClass *klass; + Error *local_err =3D NULL; + GByteArray *array; + Object *obj; + gsize size; + + obj =3D object_resolve_path_component(object_get_objects_root(), gen_i= d); + if (!obj) { + error_setg(errp, "Cannot find object ID '%s'", gen_id); + return; + } + if (!object_dynamic_cast(obj, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE)) { + error_setg(errp, "Object ID '%s' is not a '%s' subclass", + gen_id, TYPE_FW_CFG_DATA_GENERATOR_INTERFACE); + return; + } + klass =3D FW_CFG_DATA_GENERATOR_GET_CLASS(obj); + array =3D klass->get_data(obj, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + size =3D array->len; + fw_cfg_add_file(s, filename, g_byte_array_free(array, TRUE), size); +} + static void fw_cfg_machine_reset(void *opaque) { MachineClass *mc =3D MACHINE_GET_CLASS(qdev_get_machine()); @@ -1333,12 +1362,18 @@ static const TypeInfo fw_cfg_mem_info =3D { .class_init =3D fw_cfg_mem_class_init, }; =20 +static const TypeInfo fw_cfg_data_generator_interface_info =3D { + .parent =3D TYPE_INTERFACE, + .name =3D TYPE_FW_CFG_DATA_GENERATOR_INTERFACE, + .class_size =3D sizeof(FWCfgDataGeneratorClass), +}; =20 static void fw_cfg_register_types(void) { type_register_static(&fw_cfg_info); type_register_static(&fw_cfg_io_info); type_register_static(&fw_cfg_mem_info); + type_register_static(&fw_cfg_data_generator_interface_info); } =20 type_init(fw_cfg_register_types) --=20 2.21.3 From nobody Mon Apr 29 23:00:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1593880884; cv=none; d=zohomail.com; s=zohoarc; b=CCWBp6EgQRLAatvp1HdfqH5wHchrQexXWWsnnEuMUTXf4jOcyUZO89srfwmm/AcV8Fbe19UWzJx029VEyvLFtzpMNVvcC/LZyMG43SyjGwpkKTzaQ87zb2JDUJ56x96VDVwuaBqoox6+MrfHetUcUc6ORMWF8pBF/Cywm6Bk4IM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593880884; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TDGGTTstAqFb8rph+32+4m9KiUd9ZzJb6BPoEr8HLY0=; b=FgZGUkg4WgyKNy5iR/KDb6GCkzqMfgh3U5rvvq1MDt+Bns2scnfV7Zk2f3m5kSCD3XRQmbQTYni/IdQ3HKyVPH5oNrgNCt6AZvpItdExy3AmJgRYWGRGkA8YtOp3vRDz7zmEDteeGUArGQAJ0Y4T1Mlf89KD6wzESJ8I9+7KCQY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593880884667903.2155435413583; Sat, 4 Jul 2020 09:41:24 -0700 (PDT) Received: from localhost ([::1]:58988 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrlEB-00026n-CK for importer@patchew.org; Sat, 04 Jul 2020 12:41:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrlCf-0008MK-ST for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:49 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:56705 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jrlCe-0005Ry-6N for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:49 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-153-NweEQLpkPt2SRpljS7-EPw-1; Sat, 04 Jul 2020 12:39:45 -0400 Received: by mail-wr1-f72.google.com with SMTP id i14so35938284wru.17 for ; Sat, 04 Jul 2020 09:39:45 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id l17sm16984109wmh.14.2020.07.04.09.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 09:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593880787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TDGGTTstAqFb8rph+32+4m9KiUd9ZzJb6BPoEr8HLY0=; b=KeRSj+H9z7sqVXUDyqqzGVXTqJOGTM+KdVBtMYND1U2sW+b3VmI/UAOn4bjhibEo6a3U1H E43qydNlXVZzDXWHsc2q0iUDHUVoz+f2lkOUBIg4wIRrHVXC21eQqHQEx+Ugj0ArNsYCcv GsnDJibvLYBuahMv0HpZXO75F3syp0Q= X-MC-Unique: NweEQLpkPt2SRpljS7-EPw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TDGGTTstAqFb8rph+32+4m9KiUd9ZzJb6BPoEr8HLY0=; b=CQaMTL5j2CHf2N+k1SH1bxjys5vc3cuQrjenZoA7CKiLLDJ3vOnoI04Sn5TAWdhMKP mGsRQF/BE11CvBNxEwCxlNIikQcHuD26Oh2GmbWKAZ1ZFyyjhe3NZm93rpjoO1bi7k+o /AuoGTKS2bquc9yhcYWXjbyNYw8PMpMtSHmdDJXlcqehUmga1aI9FcS2LidUANOitSVa UAGtk33gYYZj4szLkosyRwQF/TZ6K/idWLGMX/JM7iglmvko+uMdv3MEy5+xXxXESxNP L7tp9ZoL8/rAszDC3EIHDzjKTnvnSjxJ055dVTmd0ZhMP7ZV04zaAJ1qometv/QOEqA7 aRzQ== X-Gm-Message-State: AOAM530UEI7/qUOserpJxKiy9APKXMTeZk6i+AiItczLCs2bBXTj76NK 77BacZfdDUDjXihfuU9ChX5SC99nRD14Rk4t1MhNcCLJaaA6uds9egkGMkjMTTYpolU4tFfZxYS 4UNKRgLHK71qnqCY= X-Received: by 2002:a5d:4202:: with SMTP id n2mr40319447wrq.171.1593880784588; Sat, 04 Jul 2020 09:39:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7am+LGYKG/fLBcesaC0CU1ZYuYCwQ+K6NS3Lg4oxAsWUMqGza1gAs6X0DA2V4bQTjqm8kvA== X-Received: by 2002:a5d:4202:: with SMTP id n2mr40319434wrq.171.1593880784375; Sat, 04 Jul 2020 09:39:44 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 3/5] softmmu/vl: Let -fw_cfg option take a 'gen_id' argument Date: Sat, 4 Jul 2020 18:39:25 +0200 Message-Id: <20200704163927.28188-4-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200704163927.28188-1-philmd@redhat.com> References: <20200704163927.28188-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/04 11:39:14 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Laszlo Ersek , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The 'gen_id' argument refers to a QOM object able to produce data consumable by the fw_cfg device. The producer object must implement the FW_CFG_DATA_GENERATOR interface. Reviewed-by: Laszlo Ersek Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20200623172726.21040-4-philmd@redhat.com> --- softmmu/vl.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index 3e15ee2435..13cada39d6 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -489,6 +489,11 @@ static QemuOptsList qemu_fw_cfg_opts =3D { .name =3D "string", .type =3D QEMU_OPT_STRING, .help =3D "Sets content of the blob to be inserted from a stri= ng", + }, { + .name =3D "gen_id", + .type =3D QEMU_OPT_STRING, + .help =3D "Sets id of the object generating the fw_cfg blob " + "to be inserted", }, { /* end of list */ } }, @@ -2020,7 +2025,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts,= Error **errp) { gchar *buf; size_t size; - const char *name, *file, *str; + const char *name, *file, *str, *gen_id; FWCfgState *fw_cfg =3D (FWCfgState *) opaque; =20 if (fw_cfg =3D=3D NULL) { @@ -2030,14 +2035,13 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opt= s, Error **errp) name =3D qemu_opt_get(opts, "name"); file =3D qemu_opt_get(opts, "file"); str =3D qemu_opt_get(opts, "string"); + gen_id =3D qemu_opt_get(opts, "gen_id"); =20 - /* we need name and either a file or the content string */ - if (!(nonempty_str(name) && (nonempty_str(file) || nonempty_str(str)))= ) { - error_setg(errp, "invalid argument(s)"); - return -1; - } - if (nonempty_str(file) && nonempty_str(str)) { - error_setg(errp, "file and string are mutually exclusive"); + /* we need the name, and exactly one of: file, content string, gen_id = */ + if (!nonempty_str(name) || + nonempty_str(file) + nonempty_str(str) + nonempty_str(gen_id) !=3D= 1) { + error_setg(errp, "name, plus exactly one of file," + " string and gen_id, are needed"); return -1; } if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) { @@ -2052,6 +2056,15 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts= , Error **errp) if (nonempty_str(str)) { size =3D strlen(str); /* NUL terminator NOT included in fw_cfg blo= b */ buf =3D g_memdup(str, size); + } else if (nonempty_str(gen_id)) { + Error *local_err =3D NULL; + + fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp); + if (local_err) { + error_propagate(errp, local_err); + return -1; + } + return 0; } else { GError *err =3D NULL; if (!g_file_get_contents(file, &buf, &size, &err)) { --=20 2.21.3 From nobody Mon Apr 29 23:00:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1593881004; cv=none; d=zohomail.com; s=zohoarc; b=ne71oKkQWP4xLsaeVkYaj2CzKUraHWXfWka7xHbCp4q3CHyX2V9m5S082yHc9nOIvFED1G3oiA3IfLbJYfhLUNFpSawaU4/BKt5hTon55pE4lZc5+DJzv21ZjpWBce+A3qL33Wx2B4K7O6nI7tzddn1HSyNrQcsiKIy4nUyjc7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593881004; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uLixvpNJpQxN4tT2DsMy+7dKl6K2fJXcgmydaNhaJeY=; b=TDtwGyfraXGIArvstTEywVAwWqfX9J6JbcJccNWES0sNF23zAB4skWEzvbBkLunMmBmbEV7zEp/oyTB4sQg98Id0L7TlcRIFB/Hx7vZpd6E4aCwgW8UmbrzKCMs8gmr4NXDj3kq8TwZWvpPUOhjDhuvGXmCwdPEP4GVsKlzbRpQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593881004826194.26745524518083; Sat, 4 Jul 2020 09:43:24 -0700 (PDT) Received: from localhost ([::1]:37400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrlG7-00052p-Hd for importer@patchew.org; Sat, 04 Jul 2020 12:43:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrlCl-000071-V1 for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:55 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:20779 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jrlCj-0005SH-Dw for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:55 -0400 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-482-E_rAndy4MjSdeuhPIX60Zw-1; Sat, 04 Jul 2020 12:39:50 -0400 Received: by mail-wr1-f72.google.com with SMTP id j3so16494708wrq.9 for ; Sat, 04 Jul 2020 09:39:50 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id l8sm17362051wrq.15.2020.07.04.09.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 09:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593880792; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uLixvpNJpQxN4tT2DsMy+7dKl6K2fJXcgmydaNhaJeY=; b=Vw49s+CTVDI3CEzu23pnI3UL/ak1nQHSRRbi850xyLy4FMC5Tip3pYfEGQzSK43Odrq48Y CD6hiRx9k9Zp/xUH21r6FChxUc07XAUeANL4RJgDe4I+Du47niDLvm6BkVkYAKO4eRzhv6 tZ3Pp/ld2HXrqhVmMJbr9ECkU2IagQY= X-MC-Unique: E_rAndy4MjSdeuhPIX60Zw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uLixvpNJpQxN4tT2DsMy+7dKl6K2fJXcgmydaNhaJeY=; b=ZPabgXfiYlPZmNOKRqaRrVLEr75dTt2JATGCpx3FL/1/CFb8aIo7x7JEYZPqQVLKXq LR4dy1eoME7euwobFeU+tmZ6ueguBXOorp6KfUjeph4Fapmt9YwYoUukK6Ei505UAg// BxQCOHjQcVUo9w9Ho5E6rGOUKrjNMRrMXDtH07lW1WQvC0hTD0Q3Cz6/ANCrhwWEqOx+ N1JrsVEDmFwO6qWEE1feWCBji0eIiGX0MfU7ba7wanCCy/ifk3MiwnT7ZI2AGwimzRGr KFyGXHC61KXpnobWOG8RF00DlBZNK7bc77YV0oNPZSUqwXTB4ncuZwtwossArIYp1hjz ak+w== X-Gm-Message-State: AOAM532o+vMZVsGl1IMIl2du+wuASmy/XfKwlxYg9uXZ5VswdQ+sKzOJ IINrxV6aORsyjdgho5l5Ttg5fruXA5lVCWCC45NLFshe+XP706dzRdVAZyt4ja1xjeAEjHJYrbF YvLJ2wLlhkkKUXzA= X-Received: by 2002:adf:8168:: with SMTP id 95mr42230307wrm.104.1593880789192; Sat, 04 Jul 2020 09:39:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/OkON3+vkcSs96FPZYD4K5p222dIH+82xd59DrfBq/WyafmFq0U4r/bOf4qSqal6vtDjLlg== X-Received: by 2002:adf:8168:: with SMTP id 95mr42230298wrm.104.1593880789034; Sat, 04 Jul 2020 09:39:49 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 4/5] softmmu/vl: Allow -fw_cfg 'gen_id' option to use the 'etc/' namespace Date: Sat, 4 Jul 2020 18:39:26 +0200 Message-Id: <20200704163927.28188-5-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200704163927.28188-1-philmd@redhat.com> References: <20200704163927.28188-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/04 11:39:15 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Laszlo Ersek , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Names of user-provided fw_cfg items are supposed to start with "opt/". However FW_CFG_DATA_GENERATOR items are generated by QEMU, so allow the "etc/" namespace in this specific case. Reviewed-by: Laszlo Ersek Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 Message-Id: <20200623172726.21040-5-philmd@redhat.com> --- docs/specs/fw_cfg.txt | 4 ++++ softmmu/vl.c | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/specs/fw_cfg.txt b/docs/specs/fw_cfg.txt index bc16daa38a..3e6d586f66 100644 --- a/docs/specs/fw_cfg.txt +++ b/docs/specs/fw_cfg.txt @@ -258,4 +258,8 @@ Prefix "opt/org.qemu/" is reserved for QEMU itself. Use of names not beginning with "opt/" is potentially dangerous and entirely unsupported. QEMU will warn if you try. =20 +Use of names not beginning with "opt/" is tolerated with 'gen_id' (that +is, the warning is suppressed), but you must know exactly what you're +doing. + All externally provided fw_cfg items are read-only to the guest. diff --git a/softmmu/vl.c b/softmmu/vl.c index 13cada39d6..159f0352a9 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2049,7 +2049,13 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts= , Error **errp) FW_CFG_MAX_FILE_PATH - 1); return -1; } - if (strncmp(name, "opt/", 4) !=3D 0) { + if (nonempty_str(gen_id)) { + /* + * In this particular case where the content is populated + * internally, the "etc/" namespace protection is relaxed, + * so do not emit a warning. + */ + } else if (strncmp(name, "opt/", 4) !=3D 0) { warn_report("externally provided fw_cfg item names " "should be prefixed with \"opt/\""); } --=20 2.21.3 From nobody Mon Apr 29 23:00:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1593881019; cv=none; d=zohomail.com; s=zohoarc; b=QsXi8NlEXnxCAS1SocY5v9XvsYQHUN7PBV3JBou6LCBasHFJO5AtGy3ecMEiE/Grlio1qmT76fKdEmtU56pniNWiJza3fcBUI7l2rx8CXiYL9ofJksnuWy5jXS2fa7n39Mw2yIvIEtj6G6HohwyU2UVBByZ8yJG+nNZtlQbvDyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593881019; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SoMzx8A+FvWrYD3fCm48tVpQZqurazT9wEn66p/sv/E=; b=EuIHX/goiP0W0LyCYoIWwjHZPCT5ULYrSKpC1HqtyAdXrd8yK8hornZcSIHqzefIvs3sFrFSWFoi4bCZzGsuCJVX95mXGKTxmF686PKdG6kSB+Pc5iKVU8BN4aocYXXcObRkTopWto9uN+fnCt1oNayslVJGNZxqALLClOoqfIc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593881019319118.43449738814354; Sat, 4 Jul 2020 09:43:39 -0700 (PDT) Received: from localhost ([::1]:37894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jrlGL-0005Gw-VX for importer@patchew.org; Sat, 04 Jul 2020 12:43:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jrlCp-0000Ay-Th for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:59 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:44924 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jrlCn-0005T5-MV for qemu-devel@nongnu.org; Sat, 04 Jul 2020 12:39:59 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-475-y8YM_rxZMaK_3UbSTojltw-1; Sat, 04 Jul 2020 12:39:55 -0400 Received: by mail-wm1-f72.google.com with SMTP id t145so39976322wmt.2 for ; Sat, 04 Jul 2020 09:39:55 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id j4sm13006917wrp.51.2020.07.04.09.39.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 09:39:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593880797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SoMzx8A+FvWrYD3fCm48tVpQZqurazT9wEn66p/sv/E=; b=RREtsUMuf9xOfAwH5LcjUdLkFP0X6r6WhYZYPSaIfGzbrrQghdOqBZY4SqJP8maGjU70GH dB1ewDXE826XncH3DimPXlg2x233aT6oTBkURhT5ZhfvazUC7QXtRvIdD+nOAt7AqMrVv5 W9+rrd7yIL6pwduIxURzChlpN34C160= X-MC-Unique: y8YM_rxZMaK_3UbSTojltw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SoMzx8A+FvWrYD3fCm48tVpQZqurazT9wEn66p/sv/E=; b=tjcQXjXf4z3YFsZWKD7PBsXUefft3d8k1n4lpd2Wxldu2wYptqoPeCZUkgZSYspHzC j0PJULytq6bK15cr29etY4haWFvrRnhiFovI9hcXFGzIORwHnos3/nzNFII6tJ5dpEQA volzirLRHa8Tv0JT5tjHuZpCCSuhF8iFt5WRiHiSGAqhDkjO8cEwaNyMLPCd/CmIBkqX 2WSnpBKHnHrpfNgN/1FvBh3yDfxr0ojI2zwsR409tAaFevG0LFz0QmhD0zbAGkmNDb4b zgEPpLVLHwtksH+YKfMJkHgCvRslAyd/U5bhKRObd7WRspKOmobXNa2Xm2QF0YxJHNUr Oidw== X-Gm-Message-State: AOAM533ZYua75a+bOKEgi2TPmMMGJlkcJ3pesWImW6/rx5CU7Hau1ve1 4lHvfbW/I5bwgznuD5rhZWAxaILZ7b8nnfH6v10xNJ0v1/k+0+YLwQY7SwEkTBBSMDGO0Ko/q00 x/YpveO1qJThM6BI= X-Received: by 2002:adf:e50a:: with SMTP id j10mr44217697wrm.71.1593880794065; Sat, 04 Jul 2020 09:39:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVcBdbyx4Vu6pxwhm7S5WKVdlD8nuS4ufxBCdNKEKYMUmbFUM+owxKRd2/wi3OZdKggl32zw== X-Received: by 2002:adf:e50a:: with SMTP id j10mr44217677wrm.71.1593880793778; Sat, 04 Jul 2020 09:39:53 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PULL 5/5] crypto/tls-cipher-suites: Produce fw_cfg consumable blob Date: Sat, 4 Jul 2020 18:39:27 +0200 Message-Id: <20200704163927.28188-6-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200704163927.28188-1-philmd@redhat.com> References: <20200704163927.28188-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/04 11:39:14 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Laszlo Ersek , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Since our format is consumable by the fw_cfg device, we can implement the FW_CFG_DATA_GENERATOR interface. Example of use to dump the cipher suites (if tracing enabled): $ qemu-system-x86_64 -S \ -object tls-cipher-suites,id=3Dmysuite1,priority=3D@SYSTEM \ -fw_cfg name=3Detc/path/to/ciphers,gen_id=3Dmysuite1 \ -trace qcrypto\* 1590664444.197123:qcrypto_tls_cipher_suite_priority priority: @SYSTEM 1590664444.197219:qcrypto_tls_cipher_suite_info data=3D[0x13,0x02] versio= n=3DTLS1.3 name=3DTLS_AES_256_GCM_SHA384 1590664444.197228:qcrypto_tls_cipher_suite_info data=3D[0x13,0x03] versio= n=3DTLS1.3 name=3DTLS_CHACHA20_POLY1305_SHA256 1590664444.197233:qcrypto_tls_cipher_suite_info data=3D[0x13,0x01] versio= n=3DTLS1.3 name=3DTLS_AES_128_GCM_SHA256 1590664444.197236:qcrypto_tls_cipher_suite_info data=3D[0x13,0x04] versio= n=3DTLS1.3 name=3DTLS_AES_128_CCM_SHA256 1590664444.197240:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x30] versio= n=3DTLS1.2 name=3DTLS_ECDHE_RSA_AES_256_GCM_SHA384 1590664444.197245:qcrypto_tls_cipher_suite_info data=3D[0xcc,0xa8] versio= n=3DTLS1.2 name=3DTLS_ECDHE_RSA_CHACHA20_POLY1305 1590664444.197250:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x14] versio= n=3DTLS1.0 name=3DTLS_ECDHE_RSA_AES_256_CBC_SHA1 1590664444.197254:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x2f] versio= n=3DTLS1.2 name=3DTLS_ECDHE_RSA_AES_128_GCM_SHA256 1590664444.197258:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x13] versio= n=3DTLS1.0 name=3DTLS_ECDHE_RSA_AES_128_CBC_SHA1 1590664444.197261:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x2c] versio= n=3DTLS1.2 name=3DTLS_ECDHE_ECDSA_AES_256_GCM_SHA384 1590664444.197266:qcrypto_tls_cipher_suite_info data=3D[0xcc,0xa9] versio= n=3DTLS1.2 name=3DTLS_ECDHE_ECDSA_CHACHA20_POLY1305 1590664444.197270:qcrypto_tls_cipher_suite_info data=3D[0xc0,0xad] versio= n=3DTLS1.2 name=3DTLS_ECDHE_ECDSA_AES_256_CCM 1590664444.197274:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x0a] versio= n=3DTLS1.0 name=3DTLS_ECDHE_ECDSA_AES_256_CBC_SHA1 1590664444.197278:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x2b] versio= n=3DTLS1.2 name=3DTLS_ECDHE_ECDSA_AES_128_GCM_SHA256 1590664444.197283:qcrypto_tls_cipher_suite_info data=3D[0xc0,0xac] versio= n=3DTLS1.2 name=3DTLS_ECDHE_ECDSA_AES_128_CCM 1590664444.197287:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x09] versio= n=3DTLS1.0 name=3DTLS_ECDHE_ECDSA_AES_128_CBC_SHA1 1590664444.197291:qcrypto_tls_cipher_suite_info data=3D[0x00,0x9d] versio= n=3DTLS1.2 name=3DTLS_RSA_AES_256_GCM_SHA384 1590664444.197296:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x9d] versio= n=3DTLS1.2 name=3DTLS_RSA_AES_256_CCM 1590664444.197300:qcrypto_tls_cipher_suite_info data=3D[0x00,0x35] versio= n=3DTLS1.0 name=3DTLS_RSA_AES_256_CBC_SHA1 1590664444.197304:qcrypto_tls_cipher_suite_info data=3D[0x00,0x9c] versio= n=3DTLS1.2 name=3DTLS_RSA_AES_128_GCM_SHA256 1590664444.197308:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x9c] versio= n=3DTLS1.2 name=3DTLS_RSA_AES_128_CCM 1590664444.197312:qcrypto_tls_cipher_suite_info data=3D[0x00,0x2f] versio= n=3DTLS1.0 name=3DTLS_RSA_AES_128_CBC_SHA1 1590664444.197316:qcrypto_tls_cipher_suite_info data=3D[0x00,0x9f] versio= n=3DTLS1.2 name=3DTLS_DHE_RSA_AES_256_GCM_SHA384 1590664444.197320:qcrypto_tls_cipher_suite_info data=3D[0xcc,0xaa] versio= n=3DTLS1.2 name=3DTLS_DHE_RSA_CHACHA20_POLY1305 1590664444.197325:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x9f] versio= n=3DTLS1.2 name=3DTLS_DHE_RSA_AES_256_CCM 1590664444.197329:qcrypto_tls_cipher_suite_info data=3D[0x00,0x39] versio= n=3DTLS1.0 name=3DTLS_DHE_RSA_AES_256_CBC_SHA1 1590664444.197333:qcrypto_tls_cipher_suite_info data=3D[0x00,0x9e] versio= n=3DTLS1.2 name=3DTLS_DHE_RSA_AES_128_GCM_SHA256 1590664444.197337:qcrypto_tls_cipher_suite_info data=3D[0xc0,0x9e] versio= n=3DTLS1.2 name=3DTLS_DHE_RSA_AES_128_CCM 1590664444.197341:qcrypto_tls_cipher_suite_info data=3D[0x00,0x33] versio= n=3DTLS1.0 name=3DTLS_DHE_RSA_AES_128_CBC_SHA1 1590664444.197345:qcrypto_tls_cipher_suite_count count: 29 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Daniel P. Berrang=C3=A9 Acked-by: Laszlo Ersek Message-Id: <20200623172726.21040-6-philmd@redhat.com> --- crypto/tls-cipher-suites.c | 11 +++++++++++ qemu-options.hx | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/crypto/tls-cipher-suites.c b/crypto/tls-cipher-suites.c index a4e0f84307..0d305b684b 100644 --- a/crypto/tls-cipher-suites.c +++ b/crypto/tls-cipher-suites.c @@ -13,6 +13,7 @@ #include "qom/object_interfaces.h" #include "crypto/tlscreds.h" #include "crypto/tls-cipher-suites.h" +#include "hw/nvram/fw_cfg.h" #include "trace.h" =20 /* @@ -88,11 +89,20 @@ static void qcrypto_tls_cipher_suites_complete(UserCrea= table *uc, } } =20 +static GByteArray *qcrypto_tls_cipher_suites_fw_cfg_gen_data(Object *obj, + Error **errp) +{ + return qcrypto_tls_cipher_suites_get_data(QCRYPTO_TLS_CIPHER_SUITES(ob= j), + errp); +} + static void qcrypto_tls_cipher_suites_class_init(ObjectClass *oc, void *da= ta) { UserCreatableClass *ucc =3D USER_CREATABLE_CLASS(oc); + FWCfgDataGeneratorClass *fwgc =3D FW_CFG_DATA_GENERATOR_CLASS(oc); =20 ucc->complete =3D qcrypto_tls_cipher_suites_complete; + fwgc->get_data =3D qcrypto_tls_cipher_suites_fw_cfg_gen_data; } =20 static const TypeInfo qcrypto_tls_cipher_suites_info =3D { @@ -103,6 +113,7 @@ static const TypeInfo qcrypto_tls_cipher_suites_info = =3D { .class_init =3D qcrypto_tls_cipher_suites_class_init, .interfaces =3D (InterfaceInfo[]) { { TYPE_USER_CREATABLE }, + { TYPE_FW_CFG_DATA_GENERATOR_INTERFACE }, { } } }; diff --git a/qemu-options.hx b/qemu-options.hx index ecc4658e1f..b2cbbbf281 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4586,6 +4586,24 @@ SRST string as described at https://gnutls.org/manual/html_node/Priority-Strings.html. =20 + An example of use of this object is to control UEFI HTTPS Boot. + The tls-cipher-suites object exposes the ordered list of permitted + TLS cipher suites from the host side to the guest firmware, via + fw_cfg. The list is represented as an array of IANA_TLS_CIPHER + objects. The firmware uses the IANA_TLS_CIPHER array for configuri= ng + guest-side TLS. + + In the following example, the priority at which the host-side poli= cy + is retrieved is given by the ``priority`` property. + Given that QEMU uses GNUTLS, ``priority=3D@SYSTEM`` may be used to + refer to /etc/crypto-policies/back-ends/gnutls.config. + + .. parsed-literal:: + + # |qemu_system| \ + -object tls-cipher-suites,id=3Dmysuite0,priority=3D@SYSTE= M \ + -fw_cfg name=3Detc/edk2/https/ciphers,gen_id=3Dmysuite0 + ``-object filter-buffer,id=3Did,netdev=3Dnetdevid,interval=3Dt[,queue= =3Dall|rx|tx][,status=3Don|off][,position=3Dhead|tail|id=3D][,insert=3D= behind|before]`` Interval t can't be 0, this filter batches the packet delivery: all packets arriving in a given interval on netdev netdevid are --=20 2.21.3