From nobody Thu May 2 12:15:36 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.zoho.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; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1490259208648936.0245514826897; Thu, 23 Mar 2017 01:53:28 -0700 (PDT) Received: from localhost ([::1]:54987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqyUp-0000wr-3c for importer@patchew.org; Thu, 23 Mar 2017 04:53:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqyTr-0000PL-Gz for qemu-devel@nongnu.org; Thu, 23 Mar 2017 04:52:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqyTo-0003j9-Fz for qemu-devel@nongnu.org; Thu, 23 Mar 2017 04:52:27 -0400 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:34745) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cqyTo-0003il-A7 for qemu-devel@nongnu.org; Thu, 23 Mar 2017 04:52:24 -0400 Received: by mail-pg0-x243.google.com with SMTP id w20so9968885pgc.1 for ; Thu, 23 Mar 2017 01:52:23 -0700 (PDT) Received: from localhost.localdomain.localdomain ([104.192.110.250]) by smtp.gmail.com with ESMTPSA id o24sm8601074pfj.126.2017.03.23.01.52.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Mar 2017 01:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=MADqscJPIqXWn2cB38egcIYjKilikL7RFwooYJqRyC0=; b=DAL1ZnjwMctYbJcTdPq+05w3DbFTw0Jpf3wwx6T3tUCT7WDNJWunI0Bx0qmyiXq3Uc iEoVxpD7pu3GP4x4gmcWAzPfYoS3UnXkZW2uV9H/CE4VswktY16QDuFnBN4EX++XgbB7 D+EkFGGzU3H78N79Os4MQWCTcpflUKL5uE6PRn2fICvb7GYtmCNeJK0tg2vpVFEVTH1O aUzEwJu2scmQGb4SOgaFl54ka6KXrMlmh30RQsmmoOS440z9pV9qbrqa2LUFlunx4yAn 3IUgBR/dKOMqXJuCj/hodtwuluclnFrpbnK5Lqwa1+yDSKLonW12CYyse5yxPbIXrcNA 1MYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MADqscJPIqXWn2cB38egcIYjKilikL7RFwooYJqRyC0=; b=HfofxqV0q1284jYAikfAUX5rIv582CKbHvkxhk+JYPOzba0CE96o99ZO3P+lmXJEZI +w+ML0ttm6s+yHaUybF52Gv2HVFRlWcojvCy4IdPnOF9WwylF2Q5vTmmUZ/+ZgEDttYJ 5EcV7NVyMSt9+hUBX8Txqm0fKSraq13awi/1+PGdWv1sXCEDyP3kVjmDW2gUWYqoe9f5 YyzSgXC+Iw7e3S3TUfIoG9Mlj9AnNr7BEWIvFeG/vDz0jQnqlV+U5+pbY6OQqVjQY8oP 2hzLL9+zq3KhkMyVTPHI4eC+L6rRnERa3/VS23j3H6+mA//fgCp4yR8rPKs9xhtRRMxD NoGw== X-Gm-Message-State: AFeK/H1bROJz7O7HlhRDKdX88TgKZDNCRQaiWYuwGcK3LaA/W2GTyzn7DYpswgv39qhRRQ== X-Received: by 10.84.217.222 with SMTP id d30mr2082101plj.33.1490259142906; Thu, 23 Mar 2017 01:52:22 -0700 (PDT) From: Li Qiang X-Google-Original-From: Li Qiang To: groug@kaod.org, qemu-devel@nongnu.org Date: Thu, 23 Mar 2017 01:52:13 -0700 Message-Id: <1490259133-44411-1-git-send-email-liqiang6-s@360.cn> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH] 9pfs: fix file descriptor leak 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: Li Qiang , ppandit@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In v9fs_create/lcreate dispatch handler, the fidp's fid_type is not checked before used. As these function will set the fid_type, if the guest call more than once them, it will leak the fidp. This can cause some other issue, such as memory leak. Check the fid_type before using them. Signed-off-by: Li Qiang --- hw/9pfs/9p.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index b8c0b99..48babce 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1550,6 +1550,10 @@ static void coroutine_fn v9fs_lcreate(void *opaque) err =3D -ENOENT; goto out_nofid; } + if (fidp->fid_type !=3D P9_FID_NONE) { + err =3D -EINVAL; + goto out; + } =20 flags =3D get_dotl_openflags(pdu->s, flags); err =3D v9fs_co_open2(pdu, fidp, &name, gid, @@ -2153,6 +2157,10 @@ static void coroutine_fn v9fs_create(void *opaque) err =3D -EINVAL; goto out_nofid; } + if (fidp->fid_type !=3D P9_FID_NONE) { + err =3D -EINVAL; + goto out; + } if (perm & P9_STAT_MODE_DIR) { err =3D v9fs_co_mkdir(pdu, fidp, &name, perm & 0777, fidp->uid, -1, &stbuf); --=20 1.8.3.1