From nobody Tue May 21 00:21:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618327962; cv=none; d=zohomail.com; s=zohoarc; b=Wum9QOpq2SsTHaoPyyLWCQgWCZ8+zkwoZpGZNC7bp0CAye8hxsE7Gjm5zYRfch4sSbH3w773I2Stc4MuhOf4GwMbvfeiRpjEP/KhfPS4sS9+TCnZdBuyRpHv/f1HhUITbFjwlA0fzdKo4vwVoMZmL1fUyq6Ean6UOE80b4I9cTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618327962; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ZxwOqlEYqTn1MYwKhtK1QG1K91hS6kwKXEI6HZ9YnIo=; b=FIe1218CCj8s+t+zKDzu6onGqTjCLtOIUJamEHH0yOd4qtLdJYMK9nun47+ea3NA9h4DzrNPUo7Pl0+z3NOF/JC0s4uiWOCfY+BpvBeoTh0gX/pYxvnOcLbQ7cisshSrykRa3gb0aXuv9MYH9bUleGizBE9825xaojtzFAerMuc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618327962955119.50036590780235; Tue, 13 Apr 2021 08:32:42 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-543-OvY8jMgsPr6ZH3NoImwLkw-1; Tue, 13 Apr 2021 11:32:38 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5106410054F6; Tue, 13 Apr 2021 15:32:31 +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 C53C05D9DE; Tue, 13 Apr 2021 15:32:29 +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 32FBA44A5A; Tue, 13 Apr 2021 15:32:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13DFWQxd011583 for ; Tue, 13 Apr 2021 11:32:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 25D9413905; Tue, 13 Apr 2021 15:32:26 +0000 (UTC) Received: from nautilus.redhat.com (unknown [10.40.192.147]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73DF8610A8; Tue, 13 Apr 2021 15:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618327961; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZxwOqlEYqTn1MYwKhtK1QG1K91hS6kwKXEI6HZ9YnIo=; b=O0++McYxonpm54fi4doj6kwmm7G1XnCPSwNhDcL0f9PdBDOTalBmxVAXnQRsOANJ89IBXJ mGw6lKE99heowhME0jy0K4Cr7YjvsDZV+c9X4nsbQAD4TxMJuAiqb3qMem/ujX+NCO2DaD bu+fW+cj+2LwnRE3TlB5Z9X7wklIbhY= X-MC-Unique: OvY8jMgsPr6ZH3NoImwLkw-1 From: Erik Skultety To: libvir-list@redhat.com Subject: [libvirt PATCH] nodedev: Fix possible NULL pointer dereference on vfiogroup opening Date: Tue, 13 Apr 2021 17:32:21 +0200 Message-Id: <47677b5201138c02a7d159acb50d9eebc1e30c4d.1618327933.git.eskultet@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: eskultet@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.79 on 10.5.11.14 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) Content-Type: text/plain; charset="utf-8" Coverity report: 1193 g_autofree char *vfiogroup =3D 1194 virMediatedDeviceGetIOMMUGroupDev(def->caps->data.mdev.uuid= ); >>> CID 317619: Null pointer dereferences (NULL_RETURNS) >>> Dereferencing a pointer that might be "NULL" "vfiogroup" when calling "open". [Note: The source code implementation of the function has been overridden by a builtin model.] 1195 VIR_AUTOCLOSE fd =3D open(vfiogroup, O_RDONLY); This patch shuffles the declarations in the affected 'if' block a bit to make it more readable after adding the NULL pointer condition. Note that error is not reported in this patch, because if @vfiogroup is NULL, then it must have been a system error which was already reported by the called function. Don't get confused by virMediatedDeviceGetIOMMUGroupDev returning NULL on an empty UUID, mdevs will always have one. Signed-off-by: Erik Skultety --- src/node_device/node_device_driver.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index e33d4a965b..7289322050 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1190,10 +1190,16 @@ nodeDeviceDestroy(virNodeDevicePtr device) * to be opened by one user at a time. So if we get EBUSY when ope= ning * the group, we infer that the device is in use and therefore we * shouldn't try to remove the device. */ - g_autofree char *vfiogroup =3D - virMediatedDeviceGetIOMMUGroupDev(def->caps->data.mdev.uuid); - VIR_AUTOCLOSE fd =3D open(vfiogroup, O_RDONLY); g_autofree char *errmsg =3D NULL; + g_autofree char *vfiogroup =3D NULL; + const char *uuidstr =3D def->caps->data.mdev.uuid; + VIR_AUTOCLOSE fd =3D -1; + + vfiogroup =3D virMediatedDeviceGetIOMMUGroupDev(uuidstr); + if (!vfiogroup) + goto cleanup; + + fd =3D open(vfiogroup, O_RDONLY); =20 if (fd < 0 && errno =3D=3D EBUSY) { virReportError(VIR_ERR_INTERNAL_ERROR, --=20 2.30.2