virtiofsd coverity fixes
cover virtiofsd coverity fixes
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This is a set of fixes that fixes things that coverity pointed out.
Only the last one (the NULL check in do_read) is probably important.
Dave
Dr. David Alan Gilbert (4):
virtiofsd: Remove fuse_req_getgroups
virtiofsd: fv_create_listen_socket error path socket leak
virtiofsd: load_capng missing unlock
virtiofsd: do_read missing NULL check
tools/virtiofsd/fuse.h | 20 -------- tools/virtiofsd/fuse_lowlevel.c | 81 ++------------------------------ tools/virtiofsd/fuse_lowlevel.h | 21 --------- tools/virtiofsd/fuse_virtio.c | 2 + tools/virtiofsd/passthrough_ll.c | 1 + 5 files changed, 7 insertions(+), 118 deletions(-)
Signature · 1 line
2.24.1
PATCH 2/4 virtiofsd: fv_create_listen_socket error path socket leak
From: "Dr. David Alan Gilbert" <[email protected]>
If we fail when bringing up the socket we can leak the listen_fd; in practice the daemon will exit so it's not really a problem.
--- tools/virtiofsd/fuse_virtio.c | 2 ++ 1 file changed, 2 insertions(+)
tools/virtiofsd/fuse_virtio.c +2 -0
@@ -916,6 +916,7 @@ static int fv_create_listen_socket(struct fuse_session *se) old_umask =umask (0077 );if (bind (listen_sock, (struct sockaddr *)&un, addr_len) ==-1 ) {fuse_log (FUSE_LOG_ERR ,"vhost socket bind: %m\n" ); +close (listen_sock);umask (old_umask);return -1 ; }
@@ -923,6 +924,7 @@ static int fv_create_listen_socket(struct fuse_session *se)if (listen (listen_sock,1 ) ==-1 ) {fuse_log (FUSE_LOG_ERR ,"vhost socket listen: %m\n" ); +close (listen_sock);return -1 ; }
Signature · 1 line
2.24.1
PATCH 3/4 virtiofsd: load_capng missing unlock
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Missing unlock in error path.
--- tools/virtiofsd/passthrough_ll.c | 1 + 1 file changed, 1 insertion(+)
tools/virtiofsd/passthrough_ll.c +1 -0
@@ -232,6 +232,7 @@ static int load_capng(void)*/ cap.saved =capng_save_state ();if (!cap.saved) { +pthread_mutex_unlock (&cap.mutex);fuse_log (FUSE_LOG_ERR ,"capng_save_state (thread)\n" );return -EINVAL ; }
Signature · 1 line
2.24.1
PATCH 1/4 virtiofsd: Remove fuse_req_getgroups
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Remove fuse_req_getgroups that's unused in virtiofsd; it came in from libfuse but we don't actually use it. It was called from fuse_getgroups which we previously removed (but had left it's header in).
Coverity had complained about null termination in it, but removing it is the easiest answer.
--- tools/virtiofsd/fuse.h | 20 --------- tools/virtiofsd/fuse_lowlevel.c | 77 --------------------------------- tools/virtiofsd/fuse_lowlevel.h | 21 --------- 3 files changed, 118 deletions(-)
tools/virtiofsd/fuse.h +0 -20
@@ -1006,26 +1006,6 @@ void fuse_exit(struct fuse *f);*/ struct fuse_context *fuse_get_context (void ); -/** -* Get the current supplementary group IDs for the current request -* -* Similar to the getgroups(2) system call, except the return value is -* always the total number of group IDs, even if it is larger than the -* specified size. -* -* The current fuse kernel module in linux (as of 2.6.30) doesn't pass -* the group list to userspace, hence this function needs to parse -* "/proc/$TID/task/$TID/status" to get the group IDs. -* -* This feature may not be supported on all operating systems. In -* such a case this function will return -ENOSYS. -* -* @param size size of given array -* @param list array of group IDs to be filled in -* @return the total number of supplementary group IDs or -errno on failure -*/ -int fuse_getgroups (int size,gid_t list[]); -/** * Check if the current request has already been interrupted *
tools/virtiofsd/fuse_lowlevel.c +0 -77
83 lines not on this page · raw message
tools/virtiofsd/fuse_lowlevel.h +0 -21
@@ -1704,27 +1704,6 @@ void *fuse_req_userdata(fuse_req_t req);*/ const struct fuse_ctx *fuse_req_ctx (fuse_req_t req); -/** -* Get the current supplementary group IDs for the specified request -* -* Similar to the getgroups(2) system call, except the return value is -* always the total number of group IDs, even if it is larger than the -* specified size. -* -* The current fuse kernel module in linux (as of 2.6.30) doesn't pass -* the group list to userspace, hence this function needs to parse -* "/proc/$TID/task/$TID/status" to get the group IDs. -* -* This feature may not be supported on all operating systems. In -* such a case this function will return -ENOSYS. -* -* @param req request handle -* @param size size of given array -* @param list array of group IDs to be filled in -* @return the total number of supplementary group IDs or -errno on failure -*/ -int fuse_req_getgroups (fuse_req_t req,int size,gid_t list[]); -/** * Callback function for an interrupt *
Signature · 1 line
2.24.1
PATCH 4/4 virtiofsd: do_read missing NULL check
In reply to Dr. David Alan Gilbert (git)From: "Dr. David Alan Gilbert" <[email protected]>
Missing a NULL check if the argument fetch fails.
--- tools/virtiofsd/fuse_lowlevel.c | 4 ++++ 1 file changed, 4 insertions(+)
tools/virtiofsd/fuse_lowlevel.c +4 -0
@@ -1116,6 +1116,10 @@ static void do_read(fuse_req_t req, fuse_ino_t nodeid,struct fuse_file_info fi; arg =fuse_mbuf_iter_advance (iter,sizeof (*arg)); +if (!arg) { +fuse_reply_err (req,EINVAL ); +return ; + }memset (&fi,0 ,sizeof (fi)); fi.fh = arg->fh;
Signature · 1 line
2.24.1
Re: [PATCH 1/4] virtiofsd: Remove fuse_req_getgroups
In reply to Dr. David Alan Gilbert (git)Quoted 9 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Remove
fuse_req_getgroupsthat's unused in virtiofsd; it came in from libfuse but we don't actually use it. It was called fromfuse_getgroupswhich we previously removed (but had left it's header in).Coverity had complained about null termination in it, but removing it is the easiest answer.
:)
Quoted 161 lines
Fixes Coverity CID: 1413117 (String not null terminated)Signed-off-by Dr. David Alan Gilbert <[email protected]>--- tools/virtiofsd/fuse.h | 20 --------- tools/virtiofsd/fuse_lowlevel.c | 77 --------------------------------- tools/virtiofsd/fuse_lowlevel.h | 21 --------- 3 files changed, 118 deletions(-)tools/virtiofsd/fuse.h +0
-20@@ -1006,26 +1006,6 @@ void fuse_exit(struct fuse *f);*/ struct fuse_context *fuse_get_context (void ); -/** -* Get the current supplementary group IDs for the current request -* -* Similar to the getgroups(2) system call, except the return value is -* always the total number of group IDs, even if it is larger than the -* specified size. -* -* The current fuse kernel module in linux (as of 2.6.30) doesn't pass -* the group list to userspace, hence this function needs to parse -* "/proc/$TID/task/$TID/status" to get the group IDs. -* -* This feature may not be supported on all operating systems. In -* such a case this function will return -ENOSYS. -* -* @param size size of given array -* @param list array of group IDs to be filled in -* @return the total number of supplementary group IDs or -errno on failure -*/ -int fuse_getgroups (int size,gid_t list[]); -/** * Check if the current request has already been interrupted * tools/virtiofsd/fuse_lowlevel.c +0
-77@@ -2667,83 +2667,6 @@ int fuse_lowlevel_is_virtio(struct fuse_session *se)return !!se->virtio_dev; } -#ifdef linux -int fuse_req_getgroups (fuse_req_t req,int size,gid_t list[]) -{ -char *buf; -size_t bufsize =1024 ; -char path[128 ]; -int ret; -int fd; -unsigned long pid = req->ctx.pid; -char *s; - -sprintf (path,"/proc/%lu/task/%lu/status" , pid, pid); - -retry: - buf =malloc (bufsize); -if (buf ==NULL ) { -return -ENOMEM ; - } - - ret = -EIO ; - fd =open (path,O_RDONLY ); -if (fd ==-1 ) { - goto out_free; - } - - ret =read (fd, buf, bufsize); -close (fd); -if (ret <0 ) { - ret = -EIO ; - goto out_free; - } - -if ((size_t )ret == bufsize) { -free (buf); - bufsize *=4 ; - goto retry; - } - - ret = -EIO ; - s =strstr (buf,"\nGroups:" ); -if (s ==NULL ) { - goto out_free; - } - - s +=8 ; - ret =0 ; -while (1 ) { -char *end; -unsigned long val =strtoul (s, &end,0 ); -if (end == s) { -break ; - } - - s = end; -if (ret < size) { - list[ret] = val; - } - ret++; - } - -out_free: -free (buf); -return ret; -} -#else /* linux */ -/* -* This is currently not implemented on other than Linux... -*/ -int fuse_req_getgroups (fuse_req_t req,int size,gid_t list[]) -{ - (void )req; - (void )size; - (void )list; -return -ENOSYS ; -} -#endif -void fuse_session_exit (struct fuse_session *se) { se->exited =1 ;tools/virtiofsd/fuse_lowlevel.h +0
-21@@ -1704,27 +1704,6 @@ void *fuse_req_userdata(fuse_req_t req);*/ const struct fuse_ctx *fuse_req_ctx (fuse_req_t req); -/** -* Get the current supplementary group IDs for the specified request -* -* Similar to the getgroups(2) system call, except the return value is -* always the total number of group IDs, even if it is larger than the -* specified size. -* -* The current fuse kernel module in linux (as of 2.6.30) doesn't pass -* the group list to userspace, hence this function needs to parse -* "/proc/$TID/task/$TID/status" to get the group IDs. -* -* This feature may not be supported on all operating systems. In -* such a case this function will return -ENOSYS. -* -* @param req request handle -* @param size size of given array -* @param list array of group IDs to be filled in -* @return the total number of supplementary group IDs or -errno on failure -*/ -int fuse_req_getgroups (fuse_req_t req,int size,gid_t list[]); -/** * Callback function for an interrupt *
Re: [PATCH 2/4] virtiofsd: fv_create_listen_socket error path socket leak
In reply to Dr. David Alan Gilbert (git)Quoted 25 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
If we fail when bringing up the socket we can leak the
listen_fd; in practice the daemon will exit so it's not really a problem.Fixes Coverity CID 1413121Signed-off-by Dr. David Alan Gilbert <[email protected]>--- tools/virtiofsd/fuse_virtio.c | 2 ++ 1 file changed, 2 insertions(+)tools/virtiofsd/fuse_virtio.c +1
-0@@ -916,6 +916,7 @@ static int fv_create_listen_socket(struct fuse_session *se) old_umask =umask (0077 );if (bind (listen_sock, (struct sockaddr *)&un, addr_len) ==-1 ) {fuse_log (FUSE_LOG_ERR ,"vhost socket bind: %m\n" ); +close (listen_sock);umask (old_umask);return -1 ; }
tools/virtiofsd/fuse_virtio.c static int fv_create_listen_socket(struct fuse_session *se) · line 930
Quoted 7 lines
tools/virtiofsd/fuse_virtio.c +1
-0@@ -923,6 +924,7 @@ static int fv_create_listen_socket(struct fuse_session *se)if (listen (listen_sock,1 ) ==-1 ) {fuse_log (FUSE_LOG_ERR ,"vhost socket listen: %m\n" ); +close (listen_sock);return -1 ; }
Re: [PATCH 4/4] virtiofsd: do_read missing NULL check
In reply to Dr. David Alan Gilbert (git)Quoted 3 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Missing a NULL check if the argument fetch fails.
Surprisingly all other calls to fuse_mbuf_iter_advance() do the check.
Quoted 23 lines
Fixes Coverity CID 1413119Signed-off-by Dr. David Alan Gilbert <[email protected]>--- tools/virtiofsd/fuse_lowlevel.c | 4 ++++ 1 file changed, 4 insertions(+)tools/virtiofsd/fuse_lowlevel.c +4
-0@@ -1116,6 +1116,10 @@ static void do_read(fuse_req_t req, fuse_ino_t nodeid,struct fuse_file_info fi; arg =fuse_mbuf_iter_advance (iter,sizeof (*arg)); +if (!arg) { +fuse_reply_err (req,EINVAL ); +return ; + }memset (&fi,0 ,sizeof (fi)); fi.fh = arg->fh;
Re: [PATCH 3/4] virtiofsd: load_capng missing unlock
In reply to Dr. David Alan Gilbert (git)Hi David,
Quoted 16 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Missing unlock in error path.
Fixes Covertiy CID 1413123Signed-off-by Dr. David Alan Gilbert <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 1 + 1 file changed, 1 insertion(+)tools/virtiofsd/passthrough_ll.c +0
-0
tools/virtiofsd/passthrough_ll.c static int load_capng(void) · line 238
Quoted 7 lines
tools/virtiofsd/passthrough_ll.c +1
-0@@ -232,6 +232,7 @@ static int load_capng(void)*/ cap.saved =capng_save_state ();if (!cap.saved) { +pthread_mutex_unlock (&cap.mutex);fuse_log (FUSE_LOG_ERR ,"capng_save_state (thread)\n" );return -EINVAL ; }
What about moving the unlock call?
-- >8 --
tools/virtiofsd/passthrough_ll.c +1 -1
@@ -231,11 +231,11 @@ static int load_capng(void)* so make another. */ cap.saved =capng_save_state (); +pthread_mutex_unlock (&cap.mutex);if (!cap.saved) {fuse_log (FUSE_LOG_ERR ,"capng_save_state (thread)\n" );return -EINVAL ; } -pthread_mutex_unlock (&cap.mutex);/* * We want to use the loaded state for our pid,
---
Re: [PATCH 3/4] virtiofsd: load_capng missing unlock
Quoted 33 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
Hi David,
Quoted 16 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Missing unlock in error path.
Fixes Covertiy CID 1413123Signed-off-by Dr. David Alan Gilbert <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 1 + 1 file changed, 1 insertion(+)tools/virtiofsd/passthrough_ll.c +0
-0tools/virtiofsd/passthrough_ll.c static int load_capng(void) · line 238
Quoted 7 lines
tools/virtiofsd/passthrough_ll.c +1
-0@@ -232,6 +232,7 @@ static int load_capng(void)*/ cap.saved =capng_save_state ();if (!cap.saved) { +pthread_mutex_unlock (&cap.mutex);fuse_log (FUSE_LOG_ERR ,"capng_save_state (thread)\n" );return -EINVAL ; }What about moving the unlock call?
-- >8 --
tools/virtiofsd/passthrough_ll.c static int load_capng(void) · line 235
Quoted 5 lines
tools/virtiofsd/passthrough_ll.c +1
-0@@ -231,11 +231,11 @@ static int load_capng(void)* so make another. */ cap.saved =capng_save_state (); +pthread_mutex_unlock (&cap.mutex);if (!cap.saved) {
I don't think I can legally check cap.saved there if I've already unlocked
tools/virtiofsd/passthrough_ll.c static int load_capng(void)
Quoted 9 lines
tools/virtiofsd/passthrough_ll.c +0
-2fuse_log (FUSE_LOG_ERR ,"capng_save_state (thread)\n" );return -EINVAL ; } -pthread_mutex_unlock (&cap.mutex);/* * We want to use the loaded state for our pid, ---
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Philippe Mathieu-Daudé
Reviewed-byRe: [PATCH 3/4] virtiofsd: load_capng missing unlock
Quoted 30 lines · Dr. David Alan Gilbert
Quoted 29 lines · * Philippe Mathieu-Daudé ([email protected]) wrote:
Hi David,
Quoted 16 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Missing unlock in error path.
Fixes Covertiy CID 1413123Signed-off-by Dr. David Alan Gilbert <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 1 + 1 file changed, 1 insertion(+)tools/virtiofsd/passthrough_ll.c +0
-0tools/virtiofsd/passthrough_ll.c static int load_capng(void) · line 238
Quoted 7 lines
tools/virtiofsd/passthrough_ll.c +1
-0@@ -232,6 +232,7 @@ static int load_capng(void)*/ cap.saved =capng_save_state ();if (!cap.saved) { +pthread_mutex_unlock (&cap.mutex);fuse_log (FUSE_LOG_ERR ,"capng_save_state (thread)\n" );return -EINVAL ; }What about moving the unlock call?
Quoted 12 lines
tools/virtiofsd/passthrough_ll.c static int load_capng(void) · line 235
Quoted 9 lines
-- >8 --
tools/virtiofsd/passthrough_ll.c +1
-0@@ -231,11 +231,11 @@ static int load_capng(void)* so make another. */ cap.saved =capng_save_state (); +pthread_mutex_unlock (&cap.mutex);if (!cap.saved) {I don't think I can legally check cap.saved there if I've already unlocked
Sorry I was with low sugar... I read it as a copy.
The patch is fine:
Quoted 14 lines
tools/virtiofsd/passthrough_ll.c static int load_capng(void)
Quoted 10 lines
tools/virtiofsd/passthrough_ll.c +0
-2fuse_log (FUSE_LOG_ERR ,"capng_save_state (thread)\n" );return -EINVAL ; } -pthread_mutex_unlock (&cap.mutex);/* * We want to use the loaded state for our pid, --- --
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 14 lines · Dr. David Alan Gilbert (git)
From: "Dr. David Alan Gilbert" <[email protected]>
Hi,
This is a set of fixes that fixes things that coverity pointed out.
Only the last one (the NULL check indo_read) is probably important.Dave
Dr. David Alan Gilbert (4):
virtiofsd: Removefuse_req_getgroups
virtiofsd:fv_create_listen_socketerror path socket leak
virtiofsd:load_capngmissing unlock
virtiofsd:do_readmissing NULL check
Quoted 11 lines
tools/virtiofsd/fuse.h | 20 -------- tools/virtiofsd/fuse_lowlevel.c | 81 ++------------------------------ tools/virtiofsd/fuse_lowlevel.h | 21 --------- tools/virtiofsd/fuse_virtio.c | 2 + tools/virtiofsd/passthrough_ll.c | 1 + 5 files changed, 7 insertions(+), 118 deletions(-)Signature · 1 line
2.24.1