qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, pannengyuan@huawei.com,
	maozhongyi@cmss.chinamobile.com, vsementsov@virtuozzo.com,
	imammedo@redhat.com, philmd@redhat.com
Subject: [PULL 5/9] tools/virtiofsd/passthrough_ll: Fix double close()
Date: Wed, 25 Mar 2020 13:16:28 +0000	[thread overview]
Message-ID: <20200325131632.311034-6-dgilbert@redhat.com> (raw)
In-Reply-To: <20200325131632.311034-1-dgilbert@redhat.com>

From: Philippe Mathieu-Daudé <philmd@redhat.com>

On success, the fdopendir() call closes fd. Later on the error
path we try to close an already-closed fd. This can lead to
use-after-free. Fix by only closing the fd if the fdopendir()
call failed.

Cc: qemu-stable@nongnu.org
Fixes: b39bce121b (add dirp_map to hide lo_dirp pointers)
Reported-by: Coverity (CID 1421933 USE_AFTER_FREE)
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <20200321120654.7985-1-philmd@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
 tools/virtiofsd/passthrough_ll.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 4f259aac70..4c35c95b25 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -1520,8 +1520,7 @@ out_err:
     if (d) {
         if (d->dp) {
             closedir(d->dp);
-        }
-        if (fd != -1) {
+        } else if (fd != -1) {
             close(fd);
         }
         free(d);
-- 
2.25.1



  parent reply	other threads:[~2020-03-25 13:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 13:16 [PULL 0/9] migration queue Dr. David Alan Gilbert (git)
2020-03-25 13:16 ` [PULL 1/9] hmp-cmd: fix a missing_break warning Dr. David Alan Gilbert (git)
2020-03-25 13:16 ` [PULL 2/9] xbzrle: update xbzrle doc Dr. David Alan Gilbert (git)
2020-03-25 13:16 ` [PULL 3/9] tests/migration: Reduce autoconverge initial bandwidth Dr. David Alan Gilbert (git)
2020-06-09 16:36   ` Michael S. Tsirkin
2020-06-09 16:45     ` Philippe Mathieu-Daudé
2020-06-09 17:00     ` Dr. David Alan Gilbert
2020-06-09 17:07       ` Philippe Mathieu-Daudé
2020-06-09 18:10       ` Michael S. Tsirkin
2020-03-25 13:16 ` [PULL 4/9] hmp/vnc: Fix info vnc list leak Dr. David Alan Gilbert (git)
2020-03-25 13:16 ` Dr. David Alan Gilbert (git) [this message]
2020-03-25 13:16 ` [PULL 6/9] vl.c: fix migration failure for 3.1 and older machine types Dr. David Alan Gilbert (git)
2020-03-25 13:16 ` [PULL 7/9] migration/colo: fix use after free of local_err Dr. David Alan Gilbert (git)
2020-03-25 13:16 ` [PULL 8/9] migration/ram: " Dr. David Alan Gilbert (git)
2020-03-25 13:16 ` [PULL 9/9] migration: use "" instead of (null) for tls-authz Dr. David Alan Gilbert (git)
2020-03-26 10:46 ` [PULL 0/9] migration queue Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200325131632.311034-6-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=maozhongyi@cmss.chinamobile.com \
    --cc=pannengyuan@huawei.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).