Message ID | 039dc3828328fe8cb59e2b74936bc67e9f01581f.1430326928.git.crobinso@redhat.com |
---|---|
State | New |
Headers | show |
On 04/29/2015 11:03 AM, Cole Robinson wrote: > Consider this case: > > $ ls -ld ~/root-owned/ > drwx--x--x. 2 root root 4096 Apr 29 12:55 /home/crobinso/root-owned/ > $ ls -l ~/root-owned/foo.sock > -rwxrwxrwx. 1 crobinso crobinso 0 Apr 29 12:55 /home/crobinso/root-owned/foo.sock > > $ qemu-system-x86_64 -vnc unix:~/root-owned/foo.sock > qemu-system-x86_64: -vnc unix:/home/crobinso/root-owned/foo.sock: Failed to start VNC server: Failed to bind socket to /home/crobinso/root-owned/foo.sock: Address already in use > > ...which is techinically true, but the real error is that we failed to > unlink. So report it. > > This may seem pathological but it's a real possibility via libvirt. > > Signed-off-by: Cole Robinson <crobinso@redhat.com> > --- > Sigh, sent an old version of the patch accidentally > > v2: > Fix the access check > Better commit message Sigh, and I was too hasty in my review of v1 to notice the logic bug in access() use. v2 is definitely better: Reviewed-by: Eric Blake <eblake@redhat.com>
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c index 87c9bc6..527f488 100644 --- a/util/qemu-sockets.c +++ b/util/qemu-sockets.c @@ -729,7 +729,11 @@ int unix_listen_opts(QemuOpts *opts, Error **errp) qemu_opt_set(opts, "path", un.sun_path, &error_abort); } - unlink(un.sun_path); + if ((access(un.sun_path, F_OK) == 0) && + unlink(un.sun_path) < 0) { + error_setg_errno(errp, errno, "Failed to unlink socket %s", un.sun_path); + goto err; + } if (bind(sock, (struct sockaddr*) &un, sizeof(un)) < 0) { error_setg_errno(errp, errno, "Failed to bind socket to %s", un.sun_path); goto err;
Consider this case: $ ls -ld ~/root-owned/ drwx--x--x. 2 root root 4096 Apr 29 12:55 /home/crobinso/root-owned/ $ ls -l ~/root-owned/foo.sock -rwxrwxrwx. 1 crobinso crobinso 0 Apr 29 12:55 /home/crobinso/root-owned/foo.sock $ qemu-system-x86_64 -vnc unix:~/root-owned/foo.sock qemu-system-x86_64: -vnc unix:/home/crobinso/root-owned/foo.sock: Failed to start VNC server: Failed to bind socket to /home/crobinso/root-owned/foo.sock: Address already in use ...which is techinically true, but the real error is that we failed to unlink. So report it. This may seem pathological but it's a real possibility via libvirt. Signed-off-by: Cole Robinson <crobinso@redhat.com> --- Sigh, sent an old version of the patch accidentally v2: Fix the access check Better commit message util/qemu-sockets.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)