From nobody Sun Apr 28 21:25:45 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543308193970115.51147107269685; Tue, 27 Nov 2018 00:43:13 -0800 (PST) Received: from localhost ([::1]:40697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRYxN-0006Fe-RX for importer@patchew.org; Tue, 27 Nov 2018 03:42:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33410) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRYwJ-0004ul-NE for qemu-devel@nongnu.org; Tue, 27 Nov 2018 03:41:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRYwG-0007hK-Hx for qemu-devel@nongnu.org; Tue, 27 Nov 2018 03:41:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33558) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gRYwG-0007gk-D5 for qemu-devel@nongnu.org; Tue, 27 Nov 2018 03:41:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 66937307D931; Tue, 27 Nov 2018 08:41:47 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-104.ams2.redhat.com [10.36.116.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD872608C1; Tue, 27 Nov 2018 08:41:44 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3DC601132928; Tue, 27 Nov 2018 09:41:43 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 27 Nov 2018 09:41:43 +0100 Message-Id: <20181127084143.1113-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Tue, 27 Nov 2018 08:41:47 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH for-3.1] vfio-helpers: Fix qemu_vfio_open_pci() crash X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, pbonzini@redhat.com, coli@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qemu_vfio_open_common() initializes s->lock only after passing s to qemu_vfio_dma_map() via qemu_vfio_init_ramblock(). qemu_vfio_dma_map() tries to lock the uninitialized lock and crashes. Fix by initializing s->lock first. RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=3D1645840 Fixes: 418026ca43bc2626db092d7558258f9594366f28 Cc: qemu-stable@nongnu.org Signed-off-by: Markus Armbruster Reviewed-by: Cornelia Huck Reviewed-by: Stefan Hajnoczi --- Compile-tested only, as I lack suitable hardware. Cong Li (cc'ed) is going to test it for real. It looks obvious enough to me to put it into -rc3 without waiting for the test results. We can also wait and put it into -rc4. util/vfio-helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c index 1d9272efa4..cccc9cd42e 100644 --- a/util/vfio-helpers.c +++ b/util/vfio-helpers.c @@ -411,13 +411,13 @@ static int qemu_vfio_init_ramblock(const char *block_= name, void *host_addr, =20 static void qemu_vfio_open_common(QEMUVFIOState *s) { + qemu_mutex_init(&s->lock); s->ram_notifier.ram_block_added =3D qemu_vfio_ram_block_added; s->ram_notifier.ram_block_removed =3D qemu_vfio_ram_block_removed; ram_block_notifier_add(&s->ram_notifier); s->low_water_mark =3D QEMU_VFIO_IOVA_MIN; s->high_water_mark =3D QEMU_VFIO_IOVA_MAX; qemu_ram_foreach_block(qemu_vfio_init_ramblock, s); - qemu_mutex_init(&s->lock); } =20 /** --=20 2.17.2