aboutsummaryrefslogtreecommitdiff
path: root/tools/virtiofsd
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé <philmd@redhat.com>2020-03-21 13:06:54 +0100
committerDr. David Alan Gilbert <dgilbert@redhat.com>2020-03-25 12:31:38 +0000
commite1cd92d95cd4f97b3464c4e08cd5b22bf5ca05cb (patch)
tree7bda276d3ce1fab3d4addffb643fb9289385bc09 /tools/virtiofsd
parentd4ff109373ce871928c7e9ef648973eba642b484 (diff)
downloadqemu-e1cd92d95cd4f97b3464c4e08cd5b22bf5ca05cb.zip
qemu-e1cd92d95cd4f97b3464c4e08cd5b22bf5ca05cb.tar.gz
qemu-e1cd92d95cd4f97b3464c4e08cd5b22bf5ca05cb.tar.bz2
tools/virtiofsd/passthrough_ll: Fix double close()
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>
Diffstat (limited to 'tools/virtiofsd')
-rw-r--r--tools/virtiofsd/passthrough_ll.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 4f259aa..4c35c95 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);