[PATCH 10/11] sockets: Bypass "replace empty @path" for abstract unix sockets

Markus Armbruster posted 11 patches 5 years, 3 months ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>
There is a newer version of this series
[PATCH 10/11] sockets: Bypass "replace empty @path" for abstract unix sockets
Posted by Markus Armbruster 5 years, 3 months ago
unix_listen_saddr() replaces empty @path by unique value.  It obtains
the value by creating and deleting a unique temporary file with
mkstemp().  This is racy, as the comment explains.  It's also entirely
undocumented as far as I can tell.  Goes back to commit d247d25f18
"sockets: helper functions for qemu (Gerd Hoffman)", v0.10.0.

Since abstract socket addresses have no connection with filesystem
pathnames, making them up with mkstemp() seems inappropriate.  Bypass
the replacement of empty @path.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 util/qemu-sockets.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 801c5e3957..18c8de8cdb 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -871,7 +871,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
         return -1;
     }
 
-    if (saddr->path && saddr->path[0]) {
+    if (saddr->path[0] || saddr->abstract) {
         path = saddr->path;
     } else {
         const char *tmpdir = getenv("TMPDIR");
-- 
2.26.2


Re: [PATCH 10/11] sockets: Bypass "replace empty @path" for abstract unix sockets
Posted by Eric Blake 5 years, 3 months ago
On 10/29/20 8:38 AM, Markus Armbruster wrote:
> unix_listen_saddr() replaces empty @path by unique value.  It obtains
> the value by creating and deleting a unique temporary file with
> mkstemp().  This is racy, as the comment explains.  It's also entirely
> undocumented as far as I can tell.  Goes back to commit d247d25f18
> "sockets: helper functions for qemu (Gerd Hoffman)", v0.10.0.
> 
> Since abstract socket addresses have no connection with filesystem
> pathnames, making them up with mkstemp() seems inappropriate.  Bypass
> the replacement of empty @path.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  util/qemu-sockets.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>

> diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
> index 801c5e3957..18c8de8cdb 100644
> --- a/util/qemu-sockets.c
> +++ b/util/qemu-sockets.c
> @@ -871,7 +871,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
>          return -1;
>      }
>  
> -    if (saddr->path && saddr->path[0]) {
> +    if (saddr->path[0] || saddr->abstract) {
>          path = saddr->path;
>      } else {
>          const char *tmpdir = getenv("TMPDIR");
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org