From patchwork Thu Mar 23 08:52:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 9640577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0A7D9601E9 for ; Thu, 23 Mar 2017 08:53:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3C69284D6 for ; Thu, 23 Mar 2017 08:53:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8A2D284DC; Thu, 23 Mar 2017 08:53:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CEA0A284D6 for ; Thu, 23 Mar 2017 08:53:08 +0000 (UTC) Received: from localhost ([::1]:54983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqyUV-0000PT-Sd for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 Mar 2017 04:53:07 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = -ENOENT; goto out_nofid; } + if (fidp->fid_type != P9_FID_NONE) { + err = -EINVAL; + goto out; + } flags = get_dotl_openflags(pdu->s, flags); err = v9fs_co_open2(pdu, fidp, &name, gid, @@ -2153,6 +2157,10 @@ static void coroutine_fn v9fs_create(void *opaque) err = -EINVAL; goto out_nofid; } + if (fidp->fid_type != P9_FID_NONE) { + err = -EINVAL; + goto out; + } if (perm & P9_STAT_MODE_DIR) { err = v9fs_co_mkdir(pdu, fidp, &name, perm & 0777, fidp->uid, -1, &stbuf);