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.
--- tools/virtiofsd/passthrough_ll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/virtiofsd/passthrough_ll.c +1 -2
@@ -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);
Signature · 1 line
2.21.1
Quoted 7 lines · Philippe Mathieu-Daudé
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 thefdopendir()call failed.Fixes 7c6b66027 (Import passthrough_ll from libfuse fuse-3.8.0)
libfuse is correct, the bug was introduced in commit b39bce121b, so:
Quoted 22 lines
Reported-by Coverity (CID 1421933 USE_AFTER_FREE)Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)tools/virtiofsd/passthrough_ll.c +1
-2@@ -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);
Stefan Hajnoczi
Reviewed-byQuoted 5 lines · Philippe Mathieu-Daudé
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 thefdopendir()call failed.
Quoted 8 lines
Fixes 7c6b66027 (Import passthrough_ll from libfuse fuse-3.8.0)Reported-by Coverity (CID 1421933 USE_AFTER_FREE)Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Thanks!
Quoted 6 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
Quoted 5 lines · Philippe Mathieu-Daudé
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 thefdopendir()call failed.
Quoted 6 lines
Quoted 2 lines
Fixes 7c6b66027 (Import passthrough_ll from libfuse fuse-3.8.0)libfuse is correct, the bug was introduced in commit
b39bce121b, so:Fixes b39bce121b (add dirp_map to hide lo_dirp pointers)
Queued with that tweak
Quoted 7 lines
Quoted 7 lines
Reported-by Coverity (CID 1421933 USE_AFTER_FREE)Suggested-by Peter Maydell <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 17 lines
Quoted 6 lines
tools/virtiofsd/passthrough_ll.c +0
-0tools/virtiofsd/passthrough_ll.c out_err: · line 1526
Quoted 9 lines
tools/virtiofsd/passthrough_ll.c +1
-2@@ -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);
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK