From nobody Fri Apr 26 12:57:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1610032171; cv=none; d=zohomail.com; s=zohoarc; b=QXpEen8EQ0mCVPlCqLlGR61dScav8VFGf+pL7VHuyZQzs4lVZjLhQzz1zBiOJvOuizJruGzLVx79kIKEwzkIUHNGe+LMeg/5PzuV3nk6qWFKvQdKlELjxM/3jzmIg+3q5ifM7OZXF8sqtT5FiVa+cEWaHxWY25SlutGbMsICm98= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610032171; 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=k7zFCkwM+E7sJmgMI1z9FBu2f8nyQV830AfcCYira60=; b=bpy8C7aO/UJ8cl/A926uBxPwdS/f9/GSCWdOHSD80z/tksZlte9RlPOmwmKos2hu2mKudgM86eXzIjBumzfNPMkLYKE5oxM/nM1E9PP6yUKNDmdaFgtdr5pgg3QfpBzOm3FRWXLQWN8n6tvMUooaxhwaUgFrUMhOHOmRgx2Xenk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1610032171936633.1576271234859; Thu, 7 Jan 2021 07:09:31 -0800 (PST) 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-452-26M1Ww-9N1ejrurKxq2iKA-1; Thu, 07 Jan 2021 10:09:26 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C98B107ACF5; Thu, 7 Jan 2021 15:09:21 +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 413D019C48; Thu, 7 Jan 2021 15:09:21 +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 E1F05180954D; Thu, 7 Jan 2021 15:09:20 +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 107F9KbK006389 for ; Thu, 7 Jan 2021 10:09:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id 59A481002388; Thu, 7 Jan 2021 15:09:20 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAAFE10013C0 for ; Thu, 7 Jan 2021 15:09:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610032170; 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=k7zFCkwM+E7sJmgMI1z9FBu2f8nyQV830AfcCYira60=; b=YOHuzFsh7mBozUFaGrPVfnIWenxTFffgd0INjAw+s3vmIloixrs+HWhtIs0Xs2OzPZtkLR 8JBRwjHI/cIoDBHrWg9rICqRfhLtoCN2g9M55H1jPqZ9uPlrH7xW+BckbdAY4/Tt0laBSy v4VzaGO5N3DAh3t5VeGInV3jtsEQ0vU= X-MC-Unique: 26M1Ww-9N1ejrurKxq2iKA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] network: Introduce mutex for bridge name generation Date: Thu, 7 Jan 2021 16:09:13 +0100 Message-Id: <96002b1b5d178fe4ae3de2ecd200cd2b96e61e49.1610032153.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.23 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" When defining/creating a network the bridge name may be filled in automatically by libvirt (if none provided in the input XML or the one provided is a pattern, e.g. "virbr%d"). During the bridge name generation process a candidate name is generated which is then checked with the rest of already defined/running networks for collisions. Problem is, that there is no mutex guarding this critical section and thus if two threads line up so that they both generate the same candidate they won't find any collision and the same name is then stored. Closes: https://gitlab.com/libvirt/libvirt/-/issues/78 Signed-off-by: Michal Privoznik Reviewed-by: Laine Stump --- src/network/bridge_driver.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index a7c5aade14..b7c604eaea 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -74,6 +74,8 @@ #define VIR_FROM_THIS VIR_FROM_NETWORK #define MAX_BRIDGE_ID 256 =20 +static virMutex bridgeNameValidateMutex =3D VIR_MUTEX_INITIALIZER; + /** * VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX: * @@ -3115,20 +3117,27 @@ static int networkBridgeNameValidate(virNetworkObjListPtr nets, virNetworkDefPtr def) { + virMutexLock(&bridgeNameValidateMutex); + if (def->bridge && !strstr(def->bridge, "%d")) { if (virNetworkObjBridgeInUse(nets, def->bridge, def->name)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("bridge name '%s' already in use."), def->bridge); - return -1; + goto error; } } else { /* Allocate a bridge name */ if (networkFindUnusedBridgeName(nets, def) < 0) - return -1; + goto error; } =20 + virMutexUnlock(&bridgeNameValidateMutex); return 0; + + error: + virMutexUnlock(&bridgeNameValidateMutex); + return -1; } =20 =20 --=20 2.26.2