[Virtio-fs] [PATCH v2] virtiofsd: Prevent multiply running with same vhost_user_socket
Masayoshi Mizuma
msys.mizuma at gmail.com
Tue Aug 13 18:33:09 UTC 2019
On Tue, Aug 13, 2019 at 04:51:53PM +0100, Stefan Hajnoczi wrote:
> 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!
Ah, thank you for pointing it out. You're right.
The namespace is changed into the sandbox after the vhost-user
socket connection is established.
I'll remove the unlink().
>
> > + 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);
Thanks.
>
> > + 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.
Got it. I'll fix this.
Thanks!
Masa
More information about the Virtio-fs
mailing list