From nobody Tue May 14 11:53:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1644586625; cv=none; d=zohomail.com; s=zohoarc; b=cG8GdnFptypbqzH8nscKPSvnSDSIchM8H127dRpjNogSR9VwIfEnWBW9nuSMnPlWWrzyKysXEuCiTRf94X7namOsp6YxLSuHmcCoYnIn2ML2M5+ioItn8riwE/+OVShq6KN8VTy/hh3I8ib5GetWCkZDJ/62+9FguIs/wlBC4rA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644586625; 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=EDIYdZNSo+wM8CWeRLG7SyH2t29NvvzYq/rjdjSu8wc=; b=KltVyJLyDF9O4c+5HF3Y4NmlONabYgkFgY6ZQqdr4pL0tyCCAt/Td5oHdAOwsNv9YbWamWEzsCQVJYwUH6h+4IqU+KvL+EScxQ0a5EaJlonluhdIcouHJEoqFYi1leQF8bNwswnVK98yeRWHiNVqeGvIl1r6TPK/Sn7XM0/kirw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1644586625272923.1843451799665; Fri, 11 Feb 2022 05:37:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-251-0t5EzlyUPE69fW9z9PArFQ-1; Fri, 11 Feb 2022 08:37:00 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9774F190D341; Fri, 11 Feb 2022 13:36:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53BBE105916E; Fri, 11 Feb 2022 13:36:55 +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 CF31E4BB7C; Fri, 11 Feb 2022 13:36:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 21BDarRT016235 for ; Fri, 11 Feb 2022 08:36:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0D5781059170; Fri, 11 Feb 2022 13:36:53 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B7AF1059168 for ; Fri, 11 Feb 2022 13:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644586624; 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=EDIYdZNSo+wM8CWeRLG7SyH2t29NvvzYq/rjdjSu8wc=; b=C23Nd/VBba5pK97Hoyxyvn1kiqcCW4xokYG9g1QktdTEuA4hZWp19Lq4Yh1uBWITrGiOBc WmMqDHzbSph4wQTLHsn51JjWVPpsd0K12++ckJuRt/GZCMVG4izwtC/Ch8RtZjm27tRLTj /HPlOuO4yv+SZVzRy4x1l8CrcepPJao= X-MC-Unique: 0t5EzlyUPE69fW9z9PArFQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] src: Initialize stack allocated virPCIDeviceAddress variables Date: Fri, 11 Feb 2022 14:36:51 +0100 Message-Id: <5542f15f4637cdbdbffe05a05ae2d3427d68b56d.1644586611.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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: 1644586627613100001 Content-Type: text/plain; charset="utf-8" There are few places where a virPCIDeviceAddress typed variable is allocated on the stack but it's not initialized. This can lead to random values of its members which in turn can lead to a random behaviour. Generated with help of the following spatch: @@ identifier I; @@ - virPCIDeviceAddress I; + virPCIDeviceAddress I =3D { 0 }; And then fixing bhyveAssignDevicePCISlots() which does declare the variable and then explicitly zero it by calling memset() only to set a specific member afterwards. Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- src/bhyve/bhyve_device.c | 5 +---- src/conf/domain_addr.c | 2 +- src/conf/node_device_conf.c | 4 ++-- src/hypervisor/domain_driver.c | 6 +++--- src/node_device/node_device_udev.c | 2 +- src/qemu/qemu_domain_address.c | 4 ++-- src/util/virpci.c | 2 +- 7 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/bhyve/bhyve_device.c b/src/bhyve/bhyve_device.c index 36b93c0d4c..5654028ca5 100644 --- a/src/bhyve/bhyve_device.c +++ b/src/bhyve/bhyve_device.c @@ -83,10 +83,7 @@ bhyveAssignDevicePCISlots(virDomainDef *def, virDomainPCIAddressSet *addrs) { size_t i; - virPCIDeviceAddress lpc_addr; - - memset(&lpc_addr, 0, sizeof(lpc_addr)); - lpc_addr.slot =3D 0x1; + virPCIDeviceAddress lpc_addr =3D { .slot =3D 0x1 }; =20 /* If the user didn't explicitly specify slot 1 for some of the device= s, reserve it for LPC, even if there's no LPC device configured. diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 49745ba881..49ca775a52 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1181,7 +1181,7 @@ virDomainPCIAddressReserveNextAddr(virDomainPCIAddres= sSet *addrs, virDomainPCIConnectFlags flags, int function) { - virPCIDeviceAddress addr; + virPCIDeviceAddress addr =3D { 0 }; =20 if (virDomainPCIAddressGetNextAddr(addrs, &addr, flags, dev->isolationGroup, function) < 0) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 61c8715037..8b20a7bee9 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2947,7 +2947,7 @@ virNodeDeviceGetPCIIOMMUGroupCaps(virNodeDevCapPCIDev= *pci_dev) { size_t i; int tmpGroup; - virPCIDeviceAddress addr; + virPCIDeviceAddress addr =3D { 0 }; =20 /* this could be a refresh, so clear out the old data */ for (i =3D 0; i < pci_dev->nIommuGroupDevices; i++) @@ -3018,7 +3018,7 @@ static int virNodeDeviceGetPCIVPDDynamicCap(virNodeDevCapPCIDev *devCapPCIDev) { g_autoptr(virPCIDevice) pciDev =3D NULL; - virPCIDeviceAddress devAddr; + virPCIDeviceAddress devAddr =3D { 0 }; g_autoptr(virPCIVPDResource) res =3D NULL; =20 devAddr.domain =3D devCapPCIDev->domain; diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 2083f06287..bb1da7ac6b 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -375,7 +375,7 @@ virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, virHostdevManager *hostdevMgr) { g_autoptr(virPCIDevice) pci =3D NULL; - virPCIDeviceAddress devAddr; + virPCIDeviceAddress devAddr =3D { 0 }; g_autoptr(virNodeDeviceDef) def =3D NULL; g_autofree char *xml =3D NULL; g_autoptr(virConnect) nodeconn =3D NULL; @@ -421,7 +421,7 @@ virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev, virHostdevManager *hostdevMgr) { g_autoptr(virPCIDevice) pci =3D NULL; - virPCIDeviceAddress devAddr; + virPCIDeviceAddress devAddr =3D { 0 }; g_autoptr(virNodeDeviceDef) def =3D NULL; g_autofree char *xml =3D NULL; g_autoptr(virConnect) nodeconn =3D NULL; @@ -466,7 +466,7 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr d= ev, const char *driverName) { g_autoptr(virPCIDevice) pci =3D NULL; - virPCIDeviceAddress devAddr; + virPCIDeviceAddress devAddr =3D { 0 }; g_autoptr(virNodeDeviceDef) def =3D NULL; g_autofree char *xml =3D NULL; g_autoptr(virConnect) nodeconn =3D NULL; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 3d5e25424a..b0a5e6302c 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -366,7 +366,7 @@ udevProcessPCI(struct udev_device *device, virNodeDevCapPCIDev *pci_dev =3D &def->caps->data.pci_dev; virPCIEDeviceInfo *pci_express =3D NULL; virPCIDevice *pciDev =3D NULL; - virPCIDeviceAddress devAddr; + virPCIDeviceAddress devAddr =3D { 0 }; int ret =3D -1; char *p; bool privileged =3D false; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 4e7095d3a7..dd0680f57f 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1743,7 +1743,7 @@ qemuDomainValidateDevicePCISlotsPIIX3(virDomainDef *d= ef, virDomainPCIAddressSet *addrs) { size_t i; - virPCIDeviceAddress tmp_addr; + virPCIDeviceAddress tmp_addr =3D { 0 }; g_autofree char *addrStr =3D NULL; virDomainPCIConnectFlags flags =3D (VIR_PCI_CONNECT_AUTOASSIGN | VIR_PCI_CONNECT_TYPE_PCI_DEVICE); @@ -1853,7 +1853,7 @@ qemuDomainValidateDevicePCISlotsQ35(virDomainDef *def, virDomainPCIAddressSet *addrs) { size_t i; - virPCIDeviceAddress tmp_addr; + virPCIDeviceAddress tmp_addr =3D { 0 }; g_autofree char *addrStr =3D NULL; virDomainPCIConnectFlags flags =3D VIR_PCI_CONNECT_TYPE_PCIE_DEVICE; =20 diff --git a/src/util/virpci.c b/src/util/virpci.c index adc255f438..d141fde814 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -1865,7 +1865,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddr= ess *orig, } =20 while ((direrr =3D virDirRead(groupDir, &ent, groupPath)) > 0) { - virPCIDeviceAddress newDev; + virPCIDeviceAddress newDev =3D { 0 }; =20 if (virPCIDeviceAddressParse(ent->d_name, &newDev) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, --=20 2.34.1