From nobody Fri May 3 23:49:55 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=1626187766; cv=none; d=zohomail.com; s=zohoarc; b=iYU2nb1lYaEpLL+Nbmu+yLxsN2Y6OBBVRo/GO7TtfmOahbOEtub4dI3meLZt4Qud7UNBWl61HYtOvD1iOAZut6Yw7RZ3jnRNNR4IQktvT6YSDlreYIu5+czt9Dv9iiSH7CFZtvL1kMmrKUcr32fEKPG5G4ybmv5z1LTjlqaUgY8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626187766; h=Content-Type:Content-Transfer-Encoding:Cc: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=0QbuNcmH+HIy/pGEscimbbH96VsDDaoPbJkGh8W85Kw=; b=bLodhjB4xiBCh4KP18srCFeeRMGtb1epmOYSl21MnXun7cWnCW7nOp398ZfloNvEE9NvCRmzMix5VOlfJE7RVFaj7ubwRSKU4AcNscgQmTpeE2Yci8tlOboqsiCxSDXWYnbsfjatHEa2NFTxrD0IvHRna8MZSnG9KLKbqOgu4lg= 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) 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 162618776608383.99881311113484; Tue, 13 Jul 2021 07:49:26 -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-185-eK8LB68QN2SeaatfJ7dtjw-1; Tue, 13 Jul 2021 10:49:23 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C71C08BDEAE; Tue, 13 Jul 2021 14:49:17 +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 953BA692A0; Tue, 13 Jul 2021 14:49:17 +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 5D7F54EA2A; Tue, 13 Jul 2021 14:49:17 +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 16DEnDQV000323 for ; Tue, 13 Jul 2021 10:49:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 038D860583; Tue, 13 Jul 2021 14:49:13 +0000 (UTC) Received: from work.redhat.com (ovpn-113-139.ams2.redhat.com [10.36.113.139]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F03669CB4; Tue, 13 Jul 2021 14:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626187764; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=0QbuNcmH+HIy/pGEscimbbH96VsDDaoPbJkGh8W85Kw=; b=R80/o7DKchPDfrUTcvJlZooYH1fxYF3czi6CvrGSa6VhG7l2RAKmmrjyfW7JUg4Uy2zFNd OZb4ksFd7c9v2tAkvgIxE1Jaj/D9C+k8aTqrtJk1t7M1mpJjc6UQb0pvzqDlquBT8Cqwf+ SCfY6Gy1hkvYBtyZI6aIUErXsRdMSXg= X-MC-Unique: eK8LB68QN2SeaatfJ7dtjw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/1] virThreadPoolNewFull: Prevent expanding worker pool by zero Date: Tue, 13 Jul 2021 16:49:06 +0200 Message-Id: <20210713144906.61187-2-twiederh@redhat.com> In-Reply-To: <20210713144906.61187-1-twiederh@redhat.com> References: <20210713144906.61187-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.16 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: 1626187767737100001 Content-Type: text/plain; charset="utf-8" On libvirtd startup, the list of priority worker threads is uninitialized (`pool->prioWorkers` is NULL), and then "expanded" to zero (`prioWorkers`) entries. This causes `virThreadPoolExpand` to call `VIR_EXPAND_N` on a null pointer and an increment of zero. The zero increment triggers `virReallocN` to not actually allocate any memory and leave the pointer NULL, which, eventually, causes `memset(NULL, 0, 0)` to be called in `virExpandN`. `memset` is declared `__attribute__ ((__nonnull__ 1))`, which triggers the following warning when libvirt is compiled with address sanitizing enabled: $ meson -Dbuildtype=3Ddebug -Db_lundef=3Dfalse -Db_sanitize=3Daddress,u= ndefined build && ninja -C build $ ./build/run build/src/libvirtd src/util/viralloc.c:82:5: runtime error: null pointer passed as argument 1, which is declared to never be null Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/util/virthreadpool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 9ddd86a679..92b7cac286 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -247,10 +247,10 @@ virThreadPoolNewFull(size_t minWorkers, pool->maxWorkers =3D maxWorkers; pool->maxPrioWorkers =3D prioWorkers; =20 - if (virThreadPoolExpand(pool, minWorkers, false) < 0) + if ((minWorkers > 0) && virThreadPoolExpand(pool, minWorkers, false) <= 0) goto error; =20 - if (virThreadPoolExpand(pool, prioWorkers, true) < 0) + if ((prioWorkers > 0) && virThreadPoolExpand(pool, prioWorkers, true) = < 0) goto error; =20 return pool; --=20 2.31.1