From nobody Tue May 7 05:47:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1536318412433636.0386890819062; Fri, 7 Sep 2018 04:06:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F357F308A967; Fri, 7 Sep 2018 11:06:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4E1C418B94; Fri, 7 Sep 2018 11:06:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F112218005DF; Fri, 7 Sep 2018 11:06:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w87B6jmj007543 for ; Fri, 7 Sep 2018 07:06:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id CE42C112D19B; Fri, 7 Sep 2018 11:06:45 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.43.2.44]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C9D2112C26E for ; Fri, 7 Sep 2018 11:06:43 +0000 (UTC) From: Andrea Bolognani To: libvir-list@redhat.com Date: Fri, 7 Sep 2018 13:06:39 +0200 Message-Id: <20180907110639.11190-1-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] conf: Fix check for chardev source path X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 07 Sep 2018 11:06:51 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Attempting to use a chardev definition like correctly results in an error being reported, since the source path - a required piece of information - is missing; however, the very similar was happily accepted by libvirt, only to result in libvirtd crashing as soon as the guest was started. The issue was caused by checking the chardev's targetType against whitelisted values from virDomainChrChannelTargetType without first checking the chardev's deviceType to make sure it is actually a channel, for which the check makes sense, rather than a different type of chardev. The only reason this wasn't spotted earlier is that the whitelisted values just so happen to correspond to USB and PCI serial devices and Xen and UML consoles respectively, all of which are fairly uncommon. https://bugzilla.redhat.com/show_bug.cgi?id=3D1609720 Signed-off-by: Andrea Bolognani Reviewed-by: J=EF=BF=BDn Tomko --- I feel compelled to point out that stuff like this wouldn't happen if libvirt was written in Rust O:-) src/conf/domain_conf.c | 8 ++++++-- .../serial-unix-missing-source.xml | 15 +++++++++++++++ tests/qemuxml2argvtest.c | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/qemuxml2argvdata/serial-unix-missing-source.xml diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 86199623cc..6162843028 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5467,10 +5467,14 @@ virDomainChrSourceDefValidate(const virDomainChrSou= rceDef *def, break; =20 case VIR_DOMAIN_CHR_TYPE_UNIX: - /* path can be auto generated */ + /* The source path can be auto generated for certain specific + * types of channels, but in most cases we should report an + * error if the user didn't provide it */ if (!def->data.nix.path && (!chr_def || - (chr_def->targetType !=3D VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_= XEN && + chr_def->deviceType !=3D VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL || + (chr_def->deviceType =3D=3D VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNE= L && + chr_def->targetType !=3D VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_= XEN && chr_def->targetType !=3D VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_= VIRTIO))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing source path attribute for char devic= e")); diff --git a/tests/qemuxml2argvdata/serial-unix-missing-source.xml b/tests/= qemuxml2argvdata/serial-unix-missing-source.xml new file mode 100644 index 0000000000..1e1221f12d --- /dev/null +++ b/tests/qemuxml2argvdata/serial-unix-missing-source.xml @@ -0,0 +1,15 @@ + + guest + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 1048576 + 1 + + hvm + + + /usr/bin/qemu-system-aarch64 + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 35df63b2ac..949b203998 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1417,6 +1417,7 @@ mymain(void) DO_TEST("serial-unix-chardev", QEMU_CAPS_DEVICE_ISA_SERIAL); DO_TEST_CAPS_LATEST("serial-unix-chardev"); + DO_TEST_PARSE_ERROR("serial-unix-missing-source", NONE); DO_TEST("serial-tcp-chardev", QEMU_CAPS_DEVICE_ISA_SERIAL); DO_TEST("serial-udp-chardev", --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list