From nobody Mon Feb 9 08:41:21 2026 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