From nobody Wed Sep 18 23:11:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1716892637; cv=none; d=zohomail.com; s=zohoarc; b=XdZXyYkGshyXAyxh6EsAqYkXzCMtedmaB39+FQFxIQ1LDA3aObPDui6jqvfoQexxKU0H6QerZ7OngFLP28dVJQQTVffLY+WXvOWiJr/c8t0YqowWvFs0SkcIKd+tkl5g8wdZLq37gpeEYcAxaJ+V6fNaqoLmj6sSgmqT2dPUo88= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716892637; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4bUhfln96QjtAy11XUS1EjId/7CwaVd+bJQnV2M45BI=; b=EqK0uYmAKpZ7JDaz1yZtOPYiB6CNml5pSTqSTnySr0PvyqNCWQ6QC6S2VGSH302gp/FgSyunsHaZ1LJHhJpU4WCCfxvmT1kt7FpRRNiuu6DMChfRQQZIfHDHqreiY+pMGhWarAZIqePdtTw7JXi2FLMDmg5Uh5RIzBi8OIvfcRI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1716892637719200.76810250618814; Tue, 28 May 2024 03:37:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sBuBt-0004R0-Rr; Tue, 28 May 2024 06:36:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBuBr-0004Mr-TP for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sBuBl-0008EZ-Pz for qemu-devel@nongnu.org; Tue, 28 May 2024 06:36:20 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-_I0jgNvGMHCs0GywptXwaQ-1; Tue, 28 May 2024 06:36:12 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3564bb7b352so372174f8f.3 for ; Tue, 28 May 2024 03:36:12 -0700 (PDT) Received: from step1.redhat.com (host-79-53-30-109.retail.telecomitalia.it. [79.53.30.109]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3577505a218sm8155894f8f.31.2024.05.28.03.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 03:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716892574; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4bUhfln96QjtAy11XUS1EjId/7CwaVd+bJQnV2M45BI=; b=AuaaOy/aHpVM6IjPXBG29/2M1BCYoRo4jKZ+3wdpXdk7PJXInO8mFjwEAp0WAF5o06N3dp ascgdisJJGpq0q4wbSKJ/GSq24tZHLzN3EqUIwPQXaX0RmDXjZgNYqJtxtwhntY2cfnUnZ /X4WEndmQ/WsgQ+i3oXXIYLa0tlgpwA= X-MC-Unique: _I0jgNvGMHCs0GywptXwaQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716892571; x=1717497371; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4bUhfln96QjtAy11XUS1EjId/7CwaVd+bJQnV2M45BI=; b=aBZ7y/mX8H6ZE3ijJhiZLovTAuwxgO8XTp6KbpULqSK0NMofQXo2zz8VjlI32hMoBB xjLDeFSD+iaT+qJmjf/QoEu0bHUO/6OzHsYXA+3fHRsAEuqNE7xlFvwJE1xZKhw3J00a QcabgS5auv8t+x90oit98mC3L1do1476hbuZCVb2aykNFSFcjzTYO/lZ3fwj3mWOC+RS j11B4qi6jyHU+K1wI9pfFJFa3Y4Ah/2UgmCknhNXkED/1mYRMxHpndnQdeYoaatghalb MCcTtsx7Vt032gOySBGeyhZMU6Xb/AZJ0dIySenaa7ddkXwtJANNFs/arFiOqcId5lW+ f+cw== X-Gm-Message-State: AOJu0YyAEsHTNQz0A42BFAKMxv0ViNF/EGBKQMExPzrIpG9KUbktot5p 6M+kLe2CW31G9t5OEpHAT3QY4Jer5L9LUZZZxgVn1C8BxtjqRujo/HSx/P/YW+U/yyHuvgRtS1z JSf9GX2E4Pr0Ps1EBjIl7ueKeedZSPV1bB7Gy5CwS2rpXkDPS/Z0LdmiMA7e5TsowklA7P/8kpk m2ku+7KNfF/mL4Zg1n4zz9Axh9qVNVEcfKolW4 X-Received: by 2002:adf:a316:0:b0:354:f444:c21e with SMTP id ffacd0b85a97d-35522186c5amr6992169f8f.22.1716892571334; Tue, 28 May 2024 03:36:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLhNQ8/ZaebS0APBXilO61bzf36ADNcAkfEhqPDQzntQVYr0Z2ify1MYaBOdN0D+hBcqsHxA== X-Received: by 2002:adf:a316:0:b0:354:f444:c21e with SMTP id ffacd0b85a97d-35522186c5amr6992132f8f.22.1716892570870; Tue, 28 May 2024 03:36:10 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: slp@redhat.com, David Hildenbrand , Paolo Bonzini , Eduardo Habkost , Igor Mammedov , Brad Smith , gmaglione@redhat.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , Kevin Wolf , Jason Wang , "Michael S. Tsirkin" , Eric Blake , Markus Armbruster , Coiby Xu , qemu-block@nongnu.org, Hanna Reitz , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Raphael Norwitz , Thomas Huth , stefanha@redhat.com, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Gerd Hoffmann , Stefano Garzarella Subject: [PATCH v6 05/12] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Tue, 28 May 2024 12:35:36 +0200 Message-ID: <20240528103543.145412-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240528103543.145412-1-sgarzare@redhat.com> References: <20240528103543.145412-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=sgarzare@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.034, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1716892638122100001 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: =E2=80=A2 The pathname in sun_path should be null-terminated. =E2=80=A2 The length of the pathname, including the terminating null byte, should not exceed the size of sun_path. =E2=80=A2 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=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Stefan Hajnoczi Reviewed-by: David Hildenbrand Signed-off-by: Stefano Garzarella --- 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-b= lk/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; =20 assert(unix_fn); =20 @@ -481,10 +480,9 @@ static int unix_sock_new(char *unix_fn) =20 un.sun_family =3D AF_UNIX; (void)snprintf(un.sun_path, sizeof(un.sun_path), "%s", unix_fn); - len =3D sizeof(un.sun_family) + strlen(un.sun_path); =20 (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; } --=20 2.45.1