From nobody Mon Feb 9 10:57:21 2026 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=1618244636; cv=none; d=zohomail.com; s=zohoarc; b=mFlLTGYO7NFLWLliOvCkSXfWebwadhu9Ic3dfRe1vWoBeuQzqw6EOzzrm02sxBO2MtnKxbjbQhBrLHlAM0+l3SqX4Qplfo83ie+M9XpQcNSS8N0QtkRSUgil0KRF71Chr/mUCVieAfYds+PXDoVsNhDjiMUjpzJaJTqHE/24eZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618244636; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QH5f3rgSSHfzAOHOZ2ZkfUQEo4r4vroWqUH+bjuTb2M=; b=Qa5GAA28v/RXpKH9G06TFmpvKg9A7Tqth5Jf4kIdGYOmjaX1SzNdnfTEPySbTbLiynNn3GyUhvwxEfaqEJsEpm5MIQlWI7Rif7J10MOEWi3LykYSwe4XjQBeSqPNfRh0fnu2639zqxmRJJrNoeGgtTmbqmfPYtKrKJavQuKpo7g= 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) header.from= 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 1618244636915217.5299371383593; Mon, 12 Apr 2021 09:23:56 -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-326-O81tZdSLPxOexE4aI9du-g-1; Mon, 12 Apr 2021 12:23:53 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BEF4C81746C; Mon, 12 Apr 2021 16:23:48 +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 9AD9959468; Mon, 12 Apr 2021 16:23:48 +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 56C7644A60; Mon, 12 Apr 2021 16:23:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13CGMWn9004562 for ; Mon, 12 Apr 2021 12:22:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 543F650DE3; Mon, 12 Apr 2021 16:22:32 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBD076062F for ; Mon, 12 Apr 2021 16:22:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618244635; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QH5f3rgSSHfzAOHOZ2ZkfUQEo4r4vroWqUH+bjuTb2M=; b=d3VFRRlhamuXhlzclWcLjkFFOIEWJajx4NIs2hgNOUEIAlwmtMrf8mu5kkILXxq8GOfYRT Q2or2Vy1PzZImFV7PQ/lB2LBbVHCBH08Srg9jBhNodP6MLWWmMl6GLEnP19pBNoZSlrIdb ug8wGBYQ7/NOmvsbXad2fSQXOKqXvDY= X-MC-Unique: O81tZdSLPxOexE4aI9du-g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/5] nodedev: Don't join not spawned threads Date: Mon, 12 Apr 2021 18:22:22 +0200 Message-Id: <66d66227264fd9b5af311457f75980aab0979e3e.1618243050.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.79 on 10.5.11.11 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" During the nodedev driver initialization two threads are created: one for listening on udev events (like device plug/unplug) and the other for enumerating devices (so that the main thread doing the driver init is not blocked). If something goes wrong at any point then nodeStateCleanup() is called which joins those two threads (possibly) created before. But it tries to join them even they weren't created which is undefined behaviour (and it just so happens that it crashes on my system). If those two virThread variables are turned into pointers then we can use comparison against NULL to detect whether threads were created. Signed-off-by: Michal Privoznik --- src/node_device/node_device_udev.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index da3754ff80..3e9c7a8d80 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -63,13 +63,13 @@ struct _udevEventData { int watch; =20 /* Thread data */ - virThread th; + virThread *th; virCond threadCond; bool threadQuit; bool dataReady; =20 /* init thread */ - virThread initThread; + virThread *initThread; =20 GList *mdevctlMonitors; virMutex mdevctlLock; @@ -1685,8 +1685,14 @@ nodeStateCleanup(void) priv->threadQuit =3D true; virCondSignal(&priv->threadCond); virObjectUnlock(priv); - virThreadJoin(&priv->initThread); - virThreadJoin(&priv->th); + if (priv->initThread) { + virThreadJoin(priv->initThread); + g_clear_pointer(&priv->initThread, g_free); + } + if (priv->th) { + virThreadJoin(priv->th); + g_clear_pointer(&priv->th, g_free); + } } =20 virObjectUnref(priv); @@ -2243,10 +2249,12 @@ nodeStateInitialize(bool privileged, udev_monitor_set_receive_buffer_size(priv->udev_monitor, 128 * 1024 * 1024); =20 - if (virThreadCreateFull(&priv->th, true, udevEventHandleThread, + priv->th =3D g_new0(virThread, 1); + if (virThreadCreateFull(priv->th, true, udevEventHandleThread, "udev-event", false, NULL) < 0) { virReportSystemError(errno, "%s", _("failed to create udev handler thread")); + g_clear_pointer(&priv->th, g_free); goto unlock; } =20 @@ -2284,10 +2292,12 @@ nodeStateInitialize(bool privileged, if (udevSetupSystemDev() !=3D 0) goto cleanup; =20 - if (virThreadCreateFull(&priv->initThread, true, nodeStateInitializeEn= umerate, + priv->initThread =3D g_new0(virThread, 1); + if (virThreadCreateFull(priv->initThread, true, nodeStateInitializeEnu= merate, "nodedev-init", false, udev) < 0) { virReportSystemError(errno, "%s", _("failed to create udev enumerate thread")); + g_clear_pointer(&priv->initThread, g_free); goto cleanup; } =20 --=20 2.26.3