From nobody Tue May 7 15:08:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=yandex-team.ru Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528530875436358.7243732954738; Sat, 9 Jun 2018 00:54:35 -0700 (PDT) Received: from localhost ([::1]:39356 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRYhd-0004ZU-Eq for importer@patchew.org; Sat, 09 Jun 2018 03:54:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRYgH-0003zN-IS for qemu-devel@nongnu.org; Sat, 09 Jun 2018 03:53:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRYgG-0002sX-Oj for qemu-devel@nongnu.org; Sat, 09 Jun 2018 03:53:01 -0400 Received: from forwardcorp1j.cmail.yandex.net ([2a02:6b8:0:1630::190]:59658) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRYgG-0002s3-HP for qemu-devel@nongnu.org; Sat, 09 Jun 2018 03:53:00 -0400 Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::30]) by forwardcorp1j.cmail.yandex.net (Yandex) with ESMTP id 4B18C20F02; Sat, 9 Jun 2018 10:52:58 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtpcorp1o.mail.yandex.net (Yandex) with ESMTP id 43B122440DC0; Sat, 9 Jun 2018 10:52:58 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:40c:44f:e5a2:2148:4fca]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id IKrD4Nr5zs-qwu0HwRP; Sat, 09 Jun 2018 10:52:58 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1528530778; bh=F2YZPl67mA3Lkg6l8U7P8169Wb+18hvB3zznvW12Mx0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=bBvGUSTbEksqme6voKFpk5hpVnIVcxZYmbgAPFt+WzYVXv2G0uEVzLUxdnsv3f6Xk fulUMGIyguEc5YSsLpyzT2vcozzLhC99AQlH7BAkcG6e2xR8dtiYmk/RXHZkao4PWw 0C+ORB5bNgL1hotJJo0u48r1uXSE0GTd1d1rgPwA= Authentication-Results: smtpcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 10:52:42 +0300 Message-Id: <1528530764-21376-2-git-send-email-dimastep@yandex-team.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528530764-21376-1-git-send-email-dimastep@yandex-team.ru> References: <1528530764-21376-1-git-send-email-dimastep@yandex-team.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:6b8:0:1630::190 Subject: [Qemu-devel] [PATCH v1 1/3] memfd: fix possible usage of the uninitialized file descriptor 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: dimastep@yandex-team.ru, wrfsh@yandex-team.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The qemu_memfd_alloc_check() routine allocates the fd variable on stack. This variable is initialized inside the qemu_memfd_alloc() function. There are several cases when *fd will be left unintialized which can lead to the unexpected close() in the qemu_memfd_free() call. Set file descriptor to -1 before calling the qemu_memfd_alloc routine. Signed-off-by: Dima Stepanov Reviewed-by: Marc-Andr=C3=A9 Lureau --- util/memfd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util/memfd.c b/util/memfd.c index d248a53..6287946 100644 --- a/util/memfd.c +++ b/util/memfd.c @@ -187,6 +187,7 @@ bool qemu_memfd_alloc_check(void) int fd; void *ptr; =20 + fd =3D -1; ptr =3D qemu_memfd_alloc("test", 4096, 0, &fd, NULL); memfd_check =3D ptr ? MEMFD_OK : MEMFD_KO; qemu_memfd_free(ptr, 4096, fd); --=20 2.7.4 From nobody Tue May 7 15:08:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=yandex-team.ru Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528530954505223.9948557045676; Sat, 9 Jun 2018 00:55:54 -0700 (PDT) Received: from localhost ([::1]:39366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRYj3-0005dF-TS for importer@patchew.org; Sat, 09 Jun 2018 03:55:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRYgN-00044r-H3 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 03:53:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRYgK-0002vp-FU for qemu-devel@nongnu.org; Sat, 09 Jun 2018 03:53:07 -0400 Received: from forwardcorp1g.cmail.yandex.net ([87.250.241.190]:38704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRYgK-0002tX-7p for qemu-devel@nongnu.org; Sat, 09 Jun 2018 03:53:04 -0400 Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::30]) by forwardcorp1g.cmail.yandex.net (Yandex) with ESMTP id B08D72171E; Sat, 9 Jun 2018 10:53:01 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtpcorp1o.mail.yandex.net (Yandex) with ESMTP id A98402440E01; Sat, 9 Jun 2018 10:53:01 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:40c:44f:e5a2:2148:4fca]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id IKrD4Nr5zs-r1umA6GR; Sat, 09 Jun 2018 10:53:01 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1528530781; bh=jnRng46MyzxYjAScMocJUzyU7XT8lt4TJb19KAXPSDQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=1ESoxAnSeUabjB4O7bkHLgLJrq0C8rH1hvN9Ydu0os3YPxWoYgbqb9xW8ngizqsbt f+CZGWW+IjXJYtwoL+BGSjLFgcc9m8MxP9IsHu5lveTOzT01CvTIuXIIZrN6YtWxQY sPzGmUNTvTuNeNi86d56L3ycHncz8v/3aZoWq4CA= Authentication-Results: smtpcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 10:52:43 +0300 Message-Id: <1528530764-21376-3-git-send-email-dimastep@yandex-team.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528530764-21376-1-git-send-email-dimastep@yandex-team.ru> References: <1528530764-21376-1-git-send-email-dimastep@yandex-team.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.250.241.190 Subject: [Qemu-devel] [PATCH v1 2/3] qcow2: fix the uninitialized bitmap_table variable 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: dimastep@yandex-team.ru, wrfsh@yandex-team.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The free_bitmap_clusters() routine is using the bitmap_table_load() call to initialize the local bitmap_table variable. bitmap_table_load() doesn't initialize variable to NULL in case of error. As a result a following assert will be hit: assert(bitmap_table =3D=3D NULL); Remove this assert, since the next instruction is return from routine. Signed-off-by: Dima Stepanov --- block/qcow2-bitmap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 60d5290..69485aa 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -254,7 +254,6 @@ static int free_bitmap_clusters(BlockDriverState *bs, Q= cow2BitmapTable *tb) =20 ret =3D bitmap_table_load(bs, tb, &bitmap_table); if (ret < 0) { - assert(bitmap_table =3D=3D NULL); return ret; } =20 --=20 2.7.4 From nobody Tue May 7 15:08:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) 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; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=yandex-team.ru Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528531029282165.1480560791715; Sat, 9 Jun 2018 00:57:09 -0700 (PDT) Received: from localhost ([::1]:39369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRYkG-0006Dq-LM for importer@patchew.org; Sat, 09 Jun 2018 03:57:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRYgW-00049Z-8e for qemu-devel@nongnu.org; Sat, 09 Jun 2018 03:53:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRYgV-00031w-HN for qemu-devel@nongnu.org; Sat, 09 Jun 2018 03:53:16 -0400 Received: from forwardcorp1j.cmail.yandex.net ([2a02:6b8:0:1630::190]:59719) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRYgV-00031Q-9i for qemu-devel@nongnu.org; Sat, 09 Jun 2018 03:53:15 -0400 Received: from smtpcorp1o.mail.yandex.net (smtpcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::30]) by forwardcorp1j.cmail.yandex.net (Yandex) with ESMTP id E349220F89; Sat, 9 Jun 2018 10:53:13 +0300 (MSK) Received: from smtpcorp1o.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtpcorp1o.mail.yandex.net (Yandex) with ESMTP id AC08A2440E01; Sat, 9 Jun 2018 10:53:11 +0300 (MSK) Received: from unknown (unknown [2a02:6b8:0:40c:44f:e5a2:2148:4fca]) by smtpcorp1o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id IKrD4Nr5zs-rBuCcwaN; Sat, 09 Jun 2018 10:53:11 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1528530791; bh=WkTXRRFnXj8eGvKniCP+CINHdIF0AJFQIa55Q5rTZxM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=MsZJtohNUdC2/SsRarrLMHz8l5VXjykpGkgO6Xyb/90+NFepIUhsDjpKDuwJEEcXm VKMJyd0tdM6tTetDKIv4DE6FzfrdeZpgZAEsoTiOKanz5ruTOb6oULu3WspccVqLqv hhLg050MfaBGYblP8fSdTzdpiFbtnLUvAwCQyAGA= Authentication-Results: smtpcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Dima Stepanov To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 10:52:44 +0300 Message-Id: <1528530764-21376-4-git-send-email-dimastep@yandex-team.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1528530764-21376-1-git-send-email-dimastep@yandex-team.ru> References: <1528530764-21376-1-git-send-email-dimastep@yandex-team.ru> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:6b8:0:1630::190 Subject: [Qemu-devel] [PATCH v1 3/3] memory: fix possible NULL pointer dereference 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: dimastep@yandex-team.ru, wrfsh@yandex-team.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In the memory_region_do_invalidate_mmio_ptr() routine the section variable is intialized by the memory_region_find() call. The section.mr field can be set to NULL. Add the check for NULL before trying to drop a section. Signed-off-by: Dima Stepanov --- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memory.c b/memory.c index 3212acc..bb45248 100644 --- a/memory.c +++ b/memory.c @@ -2712,7 +2712,7 @@ static void memory_region_do_invalidate_mmio_ptr(CPUS= tate *cpu, /* Reset dirty so this doesn't happen later. */ cpu_physical_memory_test_and_clear_dirty(offset, size, 1); =20 - if (section.mr !=3D mr) { + if (section.mr && (section.mr !=3D mr)) { /* memory_region_find add a ref on section.mr */ memory_region_unref(section.mr); if (MMIO_INTERFACE(section.mr->owner)) { --=20 2.7.4