From nobody Sat May 18 12:30:03 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=1650877590; cv=none; d=zohomail.com; s=zohoarc; b=AbCrxJFKTe0ssMU/eBEhFcGdd4kiEuUFTPTxxS8LH67FzNNPeLmiwKsKLh0zcK29JKxnsgO0OCRg4+PrNsv18kfOXVMrno0Myil6XGgHHYuBqfIUhxmsoTXnfI2gGoFmnO0kDalqVqP5jwn77fKNwbwacHJcdqpo3PaYmMlr4Bw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650877590; 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=VbPnGwpMLy5VH6yLW4vLqQcg+cvzWj4CoEdojhIFyYU=; b=HOOZkBWB1GM+bfOO8kOmU6whG1APXUrhEPsLPdfkAEC5MHx+sK3Xt5G4COWqAvcvY79KrhlDNQOXyTiADVeoXjjq5nVUwB3pZWD4tSAIIWOpsA6RXGgHBnFb921t4LuGif5kk3N0OLi0VV6irdMSDqGm/58BDTt5+xHTON6u7Ec= 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 1650877590980311.7373788674172; Mon, 25 Apr 2022 02:06:30 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-570-6HDJwpolM7qF7fTxv_21vw-1; Mon, 25 Apr 2022 05:06:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C3036866DF4; Mon, 25 Apr 2022 09:06:25 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0B2D404D2D2; Mon, 25 Apr 2022 09:06:24 +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 906461949762; Mon, 25 Apr 2022 09:06:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2B8F71947BBE for ; Mon, 25 Apr 2022 09:06:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1716F200B434; Mon, 25 Apr 2022 09:06:23 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2C842024CC5 for ; Mon, 25 Apr 2022 09:06:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650877589; 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=VbPnGwpMLy5VH6yLW4vLqQcg+cvzWj4CoEdojhIFyYU=; b=VdON1OKbfYkZ+dIUvDtPimASezw4G+XlK81wNRrxlo2PBKyiII7m8yYGksN/7dBl2HSXqn D4WvfEgibjZi31K0fpdbuClZaPsWYP2gI0xijGkvz+7aEPJjBswOjftCSsIMCef3USjjBQ u/0D1ez+bwHZKoGFmVsNKoTz3PnZGns= X-MC-Unique: 6HDJwpolM7qF7fTxv_21vw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] remote_daemon: Don't run virStateCleanup() if virStateReload() is still running Date: Mon, 25 Apr 2022 11:06:06 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 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 2.84 on 10.11.54.2 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: 1650877592304100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When a SIGHUP is received a thread is spawned that runs virStateReload(). However, if SIGINT is received while the former thread is still running then we may get into problematic situation: the cleanup code in main() sees drivers initialized and thus calls virStateCleanup(). So now we have two threads, one running virStateReload() the other virStateCleanup(). In this situation it's very likely that a race condition occurs and either of threads causes SIGSEGV. To fix this, unmark drivers as initialized in the virStateReload() thread for the time the function runs. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2075837 Signed-off-by: Michal Privoznik --- src/remote/remote_daemon.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 26469e0d9f..37d27f93f4 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -77,7 +77,7 @@ virNetSASLContext *saslCtxt =3D NULL; virNetServerProgram *remoteProgram =3D NULL; virNetServerProgram *qemuProgram =3D NULL; =20 -volatile bool driversInitialized =3D false; +volatile gint driversInitialized =3D 0; =20 static void daemonErrorHandler(void *opaque G_GNUC_UNUSED, virErrorPtr err G_GNUC_UNUSED) @@ -453,8 +453,13 @@ static void daemonReloadHandlerThread(void *opaque G_G= NUC_UNUSED) VIR_INFO("Reloading configuration on SIGHUP"); virHookCall(VIR_HOOK_DRIVER_DAEMON, "-", VIR_HOOK_DAEMON_OP_RELOAD, SIGHUP, "SIGHUP", NULL, NULL); - if (virStateReload() < 0) + + g_atomic_int_set(&driversInitialized, 0); + if (virStateReload() < 0) { VIR_WARN("Error while reloading drivers"); + } else { + g_atomic_int_inc(&driversInitialized); + } } =20 static void daemonReloadHandler(virNetDaemon *dmn G_GNUC_UNUSED, @@ -463,7 +468,7 @@ static void daemonReloadHandler(virNetDaemon *dmn G_GNU= C_UNUSED, { virThread thr; =20 - if (!driversInitialized) { + if (g_atomic_int_get(&driversInitialized) =3D=3D 0) { VIR_WARN("Drivers are not initialized, reload ignored"); return; } @@ -607,7 +612,7 @@ static void daemonRunStateInit(void *opaque) goto cleanup; } =20 - driversInitialized =3D true; + g_atomic_int_inc(&driversInitialized); =20 virNetDaemonSetShutdownCallbacks(dmn, virStateShutdownPrepare, @@ -1212,10 +1217,10 @@ int main(int argc, char **argv) { cleanup: virNetlinkEventServiceStopAll(); =20 - if (driversInitialized) { + if (g_atomic_int_get(&driversInitialized) !=3D 0) { /* NB: Possible issue with timing window between driversInitialized * setting if virNetlinkEventServerStart fails */ - driversInitialized =3D false; + g_atomic_int_set(&driversInitialized, 0); virStateCleanup(); } =20 --=20 2.35.1