qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

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>

authored by

Philippe Mathieu-Daudé and committed by
Dr. David Alan Gilbert
e1cd92d9 d4ff1093

+1 -2
+1 -2
tools/virtiofsd/passthrough_ll.c
··· 1520 1520 if (d) { 1521 1521 if (d->dp) { 1522 1522 closedir(d->dp); 1523 - } 1524 - if (fd != -1) { 1523 + } else if (fd != -1) { 1525 1524 close(fd); 1526 1525 } 1527 1526 free(d);