[Virtio-fs] [PATCH v2] virtiofsd: Prevent multiply running with same vhost_user_socket

Stefan Hajnoczi stefanha at redhat.com
Tue Aug 13 15:51:53 UTC 2019


On Sun, Aug 11, 2019 at 06:55:34PM -0400, Masayoshi Mizuma wrote:
> diff --git a/contrib/virtiofsd/fuse_lowlevel.c b/contrib/virtiofsd/fuse_lowlevel.c
> index 8adc4b1ab8..ab18b86435 100644
> --- a/contrib/virtiofsd/fuse_lowlevel.c
> +++ b/contrib/virtiofsd/fuse_lowlevel.c
> @@ -2587,6 +2587,9 @@ void fuse_session_destroy(struct fuse_session *se)
>  	free(se->vu_socket_path);
>  	se->vu_socket_path = NULL;
>  
> +	unlink(se->vu_socket_lock_file);

Are you sure this works?  We should be inside the chroot here, so this
is probably not the same file that we created!

> +        socket_name = malloc(strlen(se->vu_socket_path) + 1);
> +        memset(socket_name, 0, strlen(se->vu_socket_path) + 1);
> +        memcpy(socket_name, se->vu_socket_path, strlen(se->vu_socket_path));

These lines can be replaced with:

  socket_name = g_strdup(se->vu_socket_path);
  ...
  g_free(socket_name);

> +        strreplace(socket_name, '/', '.');
> +
> +        se->vu_socket_lock_file = malloc(NAME_MAX);
> +        memset(se->vu_socket_lock_file, 0, NAME_MAX);
> +        snprintf(se->vu_socket_lock_file, NAME_MAX, "%s/%s.pid",
> +			dir, socket_name);

These lines can be replaced with:

  se->vu_socket_lock_file = g_strdup_printf("%s/%s.pid", dir, socket_name);

The difference here is that it won't silently truncate to NAME_MAX.
This is probably a good thing since an ENAMETOOLONG error should be
reported instead of silently truncating the path.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virtio-fs/attachments/20190813/31dee680/attachment.sig>


More information about the Virtio-fs mailing list