From nobody Mon Apr 29 02:53:30 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=1625838206; cv=none; d=zohomail.com; s=zohoarc; b=V/Q6YM0lbNkBFljJ5QnKeeiCFHHf2J18hlsYspjsmU8sFXpifTQ1eJFA94GeOH/dfgfC/GXx+YAy0JZyM9dIi+dFzPpYFvfLEQ9WaXDRHlEBmSHnu3N4j4JzoJwk8ZTR1awkmcUsyl6FdFFeFbI2BvcgS0q/IPobYOde4kf4P2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1625838206; 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=FR4gvZNki4IhtZ9wKSrF33UU6Lx+8nRneeuAFAPhI00=; b=LGA+C+N8uVlu5grWMp4ZJxgL8Uy3ShH94R6IljoByJZRgKm8z1NDpEUd+jpqIkWZaR9NLFacOqmtE/rZZJlzw1xf5wdFBASqFGqQavKLl+0OiBMiJcha9eCpdeZbbnst7OdWiSzLWbDbnHLosAO6P8JoKxtIIjpO37wkM6S3kSQ= 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 1625838206380935.6783113934652; Fri, 9 Jul 2021 06:43: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-56-rc960PYtO6SHAJtso03N-A-1; Fri, 09 Jul 2021 09:43:23 -0400 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 05BDF100C660; Fri, 9 Jul 2021 13:43:18 +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 D18041971B; Fri, 9 Jul 2021 13:43: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 3AE621809C99; Fri, 9 Jul 2021 13:43:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 169DhG8O031643 for ; Fri, 9 Jul 2021 09:43:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 449675DEFA; Fri, 9 Jul 2021 13:43:16 +0000 (UTC) Received: from work.redhat.com (ovpn-113-189.ams2.redhat.com [10.36.113.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DA445DD86; Fri, 9 Jul 2021 13:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625838205; 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=FR4gvZNki4IhtZ9wKSrF33UU6Lx+8nRneeuAFAPhI00=; b=hWSau4MH4znpll0gu5wSVe0q6mh30CITnq5EQwPAZRAzapwelSeb1p/Ql7fNTg/Ddtwx+x x1N5kmangJuBS+oR26xL8uGVj5ZvrakBxoRWTvcGZjGO1/zGjiU+r8tQDD1mDyssZJ0o6y PAogUOzB5SOy62j/QpN9EtQpLmcMadI= X-MC-Unique: rc960PYtO6SHAJtso03N-A-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH] virThreadPoolExpand: Prevent expanding worker pool by zero Date: Fri, 9 Jul 2021 15:43:06 +0200 Message-Id: <20210709134306.81124-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.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) X-ZM-MESSAGEID: 1625838208460100001 Content-Type: text/plain; charset="utf-8" `virThreadPoolNewFull` may call `virThreadPoolExpand` with `prioWorkers` = =3D 0. 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: 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 --- src/util/virthreadpool.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/virthreadpool.c b/src/util/virthreadpool.c index 9ddd86a679..c9d2a17ff4 100644 --- a/src/util/virthreadpool.c +++ b/src/util/virthreadpool.c @@ -179,6 +179,9 @@ virThreadPoolExpand(virThreadPool *pool, size_t gain, b= ool priority) size_t i =3D 0; struct virThreadPoolWorkerData *data =3D NULL; =20 + if (gain =3D=3D 0) + return 0; + VIR_EXPAND_N(*workers, *curWorkers, gain); =20 for (i =3D 0; i < gain; i++) { --=20 2.31.1