[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 51/91] contrib/vhost-user-blk: fix bind() using the right size of
From: |
Michael S. Tsirkin |
Subject: |
[PULL 51/91] contrib/vhost-user-blk: fix bind() using the right size of the address |
Date: |
Tue, 2 Jul 2024 10:09:32 -0400 |
From: Stefano Garzarella <sgarzare@redhat.com>
On macOS passing `-s /tmp/vhost.socket` parameter to the vhost-user-blk
application, the bind was done on `/tmp/vhost.socke` pathname,
missing the last character.
This sounds like one of the portability problems described in the
unix(7) manpage:
Pathname sockets
When binding a socket to a pathname, a few rules should
be observed for maximum portability and ease of coding:
• The pathname in sun_path should be null-terminated.
• The length of the pathname, including the terminating
null byte, should not exceed the size of sun_path.
• The addrlen argument that describes the enclosing
sockaddr_un structure should have a value of at least:
offsetof(struct sockaddr_un, sun_path) +
strlen(addr.sun_path)+1
or, more simply, addrlen can be specified as
sizeof(struct sockaddr_un).
So let's follow the last advice and simplify the code as well.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20240618100440.145664-1-sgarzare@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
contrib/vhost-user-blk/vhost-user-blk.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/contrib/vhost-user-blk/vhost-user-blk.c
b/contrib/vhost-user-blk/vhost-user-blk.c
index 89e5f11a64..a8ab9269a2 100644
--- a/contrib/vhost-user-blk/vhost-user-blk.c
+++ b/contrib/vhost-user-blk/vhost-user-blk.c
@@ -469,7 +469,6 @@ static int unix_sock_new(char *unix_fn)
{
int sock;
struct sockaddr_un un;
- size_t len;
assert(unix_fn);
@@ -481,10 +480,9 @@ static int unix_sock_new(char *unix_fn)
un.sun_family = AF_UNIX;
(void)snprintf(un.sun_path, sizeof(un.sun_path), "%s", unix_fn);
- len = sizeof(un.sun_family) + strlen(un.sun_path);
(void)unlink(unix_fn);
- if (bind(sock, (struct sockaddr *)&un, len) < 0) {
+ if (bind(sock, (struct sockaddr *)&un, sizeof(un)) < 0) {
perror("bind");
goto fail;
}
--
MST
- [PULL 41/91] i386/apic: Add hint on boot failure because of disabling x2APIC, (continued)
- [PULL 41/91] i386/apic: Add hint on boot failure because of disabling x2APIC, Michael S. Tsirkin, 2024/07/02
- [PULL 42/91] hw/virtio: Free vqs after vhost_dev_cleanup(), Michael S. Tsirkin, 2024/07/02
- [PULL 45/91] hw/net/virtio-net.c: fix crash in iov_copy(), Michael S. Tsirkin, 2024/07/02
- [PULL 44/91] vhost-user: Skip unnecessary duplicated VHOST_USER_SET_LOG_BASE requests, Michael S. Tsirkin, 2024/07/02
- [PULL 43/91] virtio-iommu: add error check before assert, Michael S. Tsirkin, 2024/07/02
- [PULL 47/91] libvhost-user: set msg.msg_control to NULL when it is empty, Michael S. Tsirkin, 2024/07/02
- [PULL 48/91] libvhost-user: fail vu_message_write() if sendmsg() is failing, Michael S. Tsirkin, 2024/07/02
- [PULL 46/91] qapi: clarify that the default is backend dependent, Michael S. Tsirkin, 2024/07/02
- [PULL 50/91] vhost-user-server: do not set memory fd non-blocking, Michael S. Tsirkin, 2024/07/02
- [PULL 49/91] libvhost-user: mask F_INFLIGHT_SHMFD if memfd is not supported, Michael S. Tsirkin, 2024/07/02
- [PULL 51/91] contrib/vhost-user-blk: fix bind() using the right size of the address,
Michael S. Tsirkin <=
- [PULL 52/91] contrib/vhost-user-*: use QEMU bswap helper functions, Michael S. Tsirkin, 2024/07/02
- [PULL 54/91] libvhost-user: enable it on any POSIX system, Michael S. Tsirkin, 2024/07/02
- [PULL 55/91] contrib/vhost-user-blk: enable it on any POSIX system, Michael S. Tsirkin, 2024/07/02
- [PULL 53/91] vhost-user: enable frontends on any POSIX system, Michael S. Tsirkin, 2024/07/02
- [PULL 56/91] hostmem: add a new memory backend based on POSIX shm_open(), Michael S. Tsirkin, 2024/07/02
- [PULL 58/91] tests/qtest/vhost-user-test: add a test case for memory-backend-shm, Michael S. Tsirkin, 2024/07/02
- [PULL 57/91] tests/qtest/vhost-user-blk-test: use memory-backend-shm, Michael S. Tsirkin, 2024/07/02
- [PULL 59/91] hw/virtio: Fix the de-initialization of vhost-user devices, Michael S. Tsirkin, 2024/07/02
- [PULL 60/91] hw/arm/virt-acpi-build: Drop local iort_node_offset, Michael S. Tsirkin, 2024/07/02
- [PULL 61/91] hw/i386/fw_cfg: Add etc/e820 to fw_cfg late, Michael S. Tsirkin, 2024/07/02