From nobody Sat Nov 23 14:50:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723553994998863.2617302332358; Tue, 13 Aug 2024 05:59:54 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E8E131466; Tue, 13 Aug 2024 08:59:53 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 030E815A3; Tue, 13 Aug 2024 08:59:12 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 68D9612C8; Tue, 13 Aug 2024 08:59:07 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id EDB7C12C1 for ; Tue, 13 Aug 2024 08:59:06 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-XUyC9yF_NOWGK3gDRSEk7A-1; Tue, 13 Aug 2024 08:59:05 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 433331955F45 for ; Tue, 13 Aug 2024 12:59:04 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 936851944A95 for ; Tue, 13 Aug 2024 12:59:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723553946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jPdvsEaJyHosx16UgjQEPv2tLvZ/KY7v8RDFk/1Dntg=; b=QNy0LgykPuvOjuTUj4aUx2LSCwQ6Du5s2Jj5AebEJawfdBpbyFWBd2B6XfOOxODN9r5PhM PI/InODsRKEDMk1ykvv/E4a0X9/hsAH9OeieYmR4FKDpKU0fej2UXwUxql+3HRQ/tV7WaF 0kp1aPekTEEj0/afyN9l2Y5L0UorPa0= X-MC-Unique: XUyC9yF_NOWGK3gDRSEk7A-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH v2 1/2] conf: Introduce virNetDevBandwidthValidate() Date: Tue, 13 Aug 2024 14:58:59 +0200 Message-ID: <1fa1cfc85f83723e11097c8ec8315fb2d1351c03.1723553847.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YKOOLSWJI7DKKEM5NJVBOFEOYLQTWHDY X-Message-ID-Hash: YKOOLSWJI7DKKEM5NJVBOFEOYLQTWHDY X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1723553996102116600 Content-Type: text/plain; charset="utf-8"; x-default="true" This function validates whether parsed limits are within range as defined by 'tc' sources (since we use tc to set QoS; or OVS which then uses tc too). The 'tc' program stores speeds in 64bit integers (unit is bytes per second) and sizes in uints (unit is bytes). We use different units: kilobytes per second and kibibytes and therefore we can parse values larger than 'tc' can handle and thus need a function to check if values still fit. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/netdev_bandwidth_conf.c | 42 ++++++++++++++++++++++++++++++++ src/conf/netdev_bandwidth_conf.h | 2 ++ src/libvirt_private.syms | 1 + 3 files changed, 45 insertions(+) diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_c= onf.c index 9faa46a27f..43a2c62240 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -200,6 +200,48 @@ virNetDevBandwidthFormat(const virNetDevBandwidth *def, } =20 =20 +#define CHECK_LIMIT(val, limit, name) \ + do { \ + if ((val) > (limit)) { \ + virReportError(VIR_ERR_OVERFLOW, \ + _("value '%1$llu' is too big for '%2$s' paramet= er, maximum is '%3$llu'"), \ + val, name, (unsigned long long) limit); \ + return false; \ + } \ + } while (0) + +static bool +virNetDevBandwidthRateValidate(const virNetDevBandwidthRate *rate) +{ + const unsigned long long speedLimit =3D 1ULL << 54; + const unsigned int sizeLimit =3D UINT_MAX >> 10; + + /* These limits are taken straight from 'tc' sources. */ + + if (!rate) + return true; + + CHECK_LIMIT(rate->average, speedLimit, "average"); + CHECK_LIMIT(rate->peak, speedLimit, "peak"); + CHECK_LIMIT(rate->burst, sizeLimit, "burst"); + CHECK_LIMIT(rate->floor, speedLimit, "floor"); + + return true; +} + +#undef CHECK_LIMIT + +bool +virNetDevBandwidthValidate(const virNetDevBandwidth *def) +{ + if (!def) + return true; + + return virNetDevBandwidthRateValidate(def->in) && + virNetDevBandwidthRateValidate(def->out); +} + + bool virNetDevSupportsBandwidth(virDomainNetType type) { switch ((virDomainNetType) type) { diff --git a/src/conf/netdev_bandwidth_conf.h b/src/conf/netdev_bandwidth_c= onf.h index b679b0f51f..6dbe0298f6 100644 --- a/src/conf/netdev_bandwidth_conf.h +++ b/src/conf/netdev_bandwidth_conf.h @@ -34,6 +34,8 @@ int virNetDevBandwidthFormat(const virNetDevBandwidth *de= f, unsigned int class_id, virBuffer *buf); =20 +bool virNetDevBandwidthValidate(const virNetDevBandwidth *def); + bool virNetDevSupportsBandwidth(virDomainNetType type); bool virNetDevBandwidthHasFloor(const virNetDevBandwidth *b); bool virNetDevBandwidthSupportsFloor(virNetworkForwardType type); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0accca442a..7a5df5a6a4 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -825,6 +825,7 @@ virNetDevBandwidthFormat; virNetDevBandwidthHasFloor; virNetDevBandwidthParse; virNetDevBandwidthSupportsFloor; +virNetDevBandwidthValidate; virNetDevSupportsBandwidth; =20 =20 --=20 2.44.2 From nobody Sat Nov 23 14:50:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723554029223422.72127520108813; Tue, 13 Aug 2024 06:00:29 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 28B3E12E5; Tue, 13 Aug 2024 09:00:28 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4575815C3; Tue, 13 Aug 2024 08:59:20 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B6977140A; Tue, 13 Aug 2024 08:59:15 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 113571300 for ; Tue, 13 Aug 2024 08:59:09 -0400 (EDT) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-187-kIMbAsZwN9ycQbjSvEUaUA-1; Tue, 13 Aug 2024 08:59:06 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 81AB31954B17 for ; Tue, 13 Aug 2024 12:59:05 +0000 (UTC) Received: from maggie.brq.redhat.com (unknown [10.43.3.102]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A86671944A95 for ; Tue, 13 Aug 2024 12:59:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723553948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wCd9ren4uWjmKUZ/MnLzjpGiFEAcD1y7uZ1Oc1NVU0Y=; b=ON3YUq7fNbWxL1NAYKqE81OtNQSJjxMgQU2b/sw0FClt9QrM9yj/lG/h9WtGUN2zFF9168 nQ60qDz0eYQlOSvgn8zNU/vVq6TTeS9nKzIuTpw05kZmgxz8wDXZlSJNouWmdQHUTCoc4Z XrNj95BZpvGkAWbbzXaebW/dyvgik0w= X-MC-Unique: kIMbAsZwN9ycQbjSvEUaUA-1 From: Michal Privoznik To: devel@lists.libvirt.org Subject: [PATCH v2 2/2] conf: Validate QoS values Date: Tue, 13 Aug 2024 14:59:00 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FOUEDL34VRUVJKJTMTZPFSZPAK52TK3D X-Message-ID-Hash: FOUEDL34VRUVJKJTMTZPFSZPAK52TK3D X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1723554032950116600 Content-Type: text/plain; charset="utf-8"; x-default="true" Since we use 'tc' to set QoS, or we instruct OVS which then uses 'tc', we have to make sure values are within range acceptable to 'tc'. Resolves: https://issues.redhat.com/browse/RHEL-45200 Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/domain_validate.c | 9 +++++++++ src/conf/schemas/networkcommon.rng | 3 ++- src/network/bridge_driver.c | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 39b8d67928..ab1caadc7a 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -22,6 +22,7 @@ =20 #include "domain_validate.h" #include "domain_conf.h" +#include "netdev_bandwidth_conf.h" #include "vircgroup.h" #include "virconftypes.h" #include "virlog.h" @@ -2068,6 +2069,10 @@ virDomainActualNetDefValidate(const virDomainNetDef = *net) return -1; } =20 + if (!virNetDevBandwidthValidate(bandwidth)) { + return -1; + } + if (virDomainNetDefValidatePortOptions(macstr, actualType, vport, virDomainNetGetActualPortOption= sIsolated(net)) < 0) { return -1; @@ -2143,6 +2148,10 @@ virDomainNetDefValidate(const virDomainNetDef *net) return -1; } =20 + if (!virNetDevBandwidthValidate(net->bandwidth)) { + return -1; + } + switch (net->type) { case VIR_DOMAIN_NET_TYPE_VHOSTUSER: if (!virDomainNetIsVirtioModel(net)) { diff --git a/src/conf/schemas/networkcommon.rng b/src/conf/schemas/networkc= ommon.rng index 6df6d43f54..28424f9abd 100644 --- a/src/conf/schemas/networkcommon.rng +++ b/src/conf/schemas/networkcommon.rng @@ -180,9 +180,10 @@ =20 - + [0-9]+ 1 + 18014398509481984 diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 32572c755f..915211d1b5 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2838,6 +2838,10 @@ networkValidate(virNetworkDriverState *driver, return -1; } =20 + if (!virNetDevBandwidthValidate(def->bandwidth)) { + return -1; + } + /* we support configs with a single PF defined: * * or with a list of netdev names: --=20 2.44.2