From nobody Fri May 17 09:38:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1671710415; cv=none; d=zohomail.com; s=zohoarc; b=Ztffi7G2QtUFg4PvFrYbVZSMS5TbZPGtA45nQv160q1ao1VnTFvZ85pAXur2T49JAD9RsQU2PdfEJHbH5f1Fb8G0vAuJ+CTZojo8bKrHqS0v3HlhsRKtqnWqFxYueRB2q7Fj6vr9aghlMzc8B0HUSdibPowzfxSFqHA2IR7Zy/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671710415; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=BnAcfbTZ4nwaeYqK9lP8FQ84o5LQBF90VaPnttSuTf8=; b=MggRQg9836xq2JI2E+GRPxMutn2WGf7/10MLiv3XUpVt+6Bj9ahQmdtMds/lEr4mD9dE9sYtrCNrV8zO9iyquHZx3ZL8u+spgWnTEGwfBlyCkbRrfWj/z3iREucPuDY3HehCeU1PvRa5rSeXPZJuJ540cIw5pE4WW9c2UXgDObE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1671710415905223.8325272747319; Thu, 22 Dec 2022 04:00:15 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-74-KMdCIDkROrKYsh11t_WB9A-1; Thu, 22 Dec 2022 07:00:12 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4E4C929ABA2D; Thu, 22 Dec 2022 12:00:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9396940C2064; Thu, 22 Dec 2022 12:00:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7369919465B1; Thu, 22 Dec 2022 12:00:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DEDD319465A8 for ; Thu, 22 Dec 2022 12:00:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id BD1C12166B29; Thu, 22 Dec 2022 12:00:07 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64A652166B26 for ; Thu, 22 Dec 2022 12:00:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671710414; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=BnAcfbTZ4nwaeYqK9lP8FQ84o5LQBF90VaPnttSuTf8=; b=gAQ5kIXaIYV6O0hxNtwMC/TBEcFRCRDdaIfSayND9f2IcYvCzFCv42wnnYzbLZshfxSp/1 +nxHQtKqamuIZcWkaYGcDQKWSu157bQKnPTvf4sOUBVVVWvBCSXkK5F/M8WA39R+4auM6y Fd2dpjH62VGRd2KI0lQA6m16A1ciOyM= X-MC-Unique: KMdCIDkROrKYsh11t_WB9A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2] virQEMUDriverGetDomainCapabilities: Validate arguments Date: Thu, 22 Dec 2022 13:00:06 +0100 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1671710417203100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When calling virConnectGetDomainCapabilities() (exposed as virsh domcapabilities) users have option to specify whatever sub-set of { emulatorbin, arch, machine, virttype } they want. Then we have a logic (hidden in virQEMUCapsCacheLookupDefault()) that picks qemuCaps that satisfy values passed by user. And whatever was not specified is then set to the default value as specified by picked qemuCaps. For instance: if no machine type was provided but emulatorbin was, then the machine type is set to the default one as defined by the emulatorbin. Or, when just virttype was set then the remaining three values are set to their respective defaults. Except, we have a crasher in this case: # virsh domcapabilities --virttype hvf error: Disconnected from qemu:///system due to end of file error: failed to get emulator capabilities error: End of file while reading data: Input/output error This is because for 'hvf' virttype (at least my) QEMU does not have any machine type. Therefore, @machine is set to NULL and the rest of the code does not expect that. What we can do about this is to validate all arguments. Well, except for the emulatorbin which is obtained from passed qemuCaps. This also fixes the issue when domcapabilities for a virttype of a different driver are requested, or a different arch. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- v2 of: https://listman.redhat.com/archives/libvir-list/2022-December/236460.html diff to v1: - validate @arch, @virttype as well, not just @machine src/qemu/qemu_conf.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index ae5bbcd138..6760bef14c 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1454,6 +1454,27 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriver *dr= iver, g_autoptr(virDomainCaps) domCaps =3D NULL; const char *path =3D virQEMUCapsGetBinary(qemuCaps); =20 + if (!virQEMUCapsIsArchSupported(qemuCaps, arch)) { + virReportError(VIR_ERR_INVALID_ARG, + _("Emulator '%s' does not support arch '%s'"), + path, virArchToString(arch)); + return NULL; + } + + if (!virQEMUCapsIsVirtTypeSupported(qemuCaps, virttype)) { + virReportError(VIR_ERR_INVALID_ARG, + _("Emulator '%s' does not support virt type '%s'"), + path, virDomainVirtTypeToString(virttype)); + return NULL; + } + + if (!virQEMUCapsIsMachineSupported(qemuCaps, virttype, machine)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("Emulator '%s' does not support machine type '%s'= "), + path, NULLSTR(machine)); + return NULL; + } + if (!(domCaps =3D virDomainCapsNew(path, machine, arch, virttype))) return NULL; =20 --=20 2.38.2