From nobody Mon Nov 25 09:58:31 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=1716476304; cv=none; d=zohomail.com; s=zohoarc; b=AD1ThI+b3azd0pTUb9KAGEWi7tsCboJKqFo42SkeE6L87pRvOTbZrzG/viNqeBxr4RLBDEe6QGot2eYvZrOynFVOuiT3mHkctUU/3hki1+LBg+O0jcnWG00QoVrLVcRowC5pLcJLlQW55H4e6gpvT2l9uuvSl5R8FCVgUdFjamo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716476304; 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=E8Qic62YBqRdzP7F+Sc3L6ItKzN7rCBikXFWYxb/pVU=; b=JToDLYlbg8FB3U4wPhFQnPLNWnOwmE5ciwtc2EhutO6LXroQUDBUqRPrNDJsBp7EbLk6NzrCnBdlZhJZivdM4UFhxG8eRQTbiDx8bSBzj44tGq35yMiGdprCS1pngt6Lih9CFnzqChi4J/PpkQkfyvyRw1g0AqGcMB1Dzrz4qoI= 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 1716476304834812.7261899141824; Thu, 23 May 2024 07:58:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sA9rt-0002kb-AE; Thu, 23 May 2024 10:56:33 -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 1sA9rd-0002Os-Cf for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:20 -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 1sA9rX-00040H-W3 for qemu-devel@nongnu.org; Thu, 23 May 2024 10:56:17 -0400 Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-Q-9nhn3YN5aDdWTJOR2o-g-1; Thu, 23 May 2024 10:56:09 -0400 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-43e349c3983so2218661cf.2 for ; Thu, 23 May 2024 07:56:09 -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 d75a77b69052e-43f86a12d71sm56614101cf.17.2024.05.23.07.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 07:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716476171; 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=E8Qic62YBqRdzP7F+Sc3L6ItKzN7rCBikXFWYxb/pVU=; b=gsTrVkhdQ5T6u1Ub/wibKHk+3YK0my6WsActOfUHLASS31nfjlXCudjjqBwKEIO7jPc3yF xp40sxTTl9Obcfbvmw8ATAjHQP4AY2742v5LxfIGLz4ntVtS++eek2HjAnQsyN4QDZKsTv gUHP+Jsv2Lag1iDb1EJ5QIwsdXc+/Z8= X-MC-Unique: Q-9nhn3YN5aDdWTJOR2o-g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716476169; x=1717080969; 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=E8Qic62YBqRdzP7F+Sc3L6ItKzN7rCBikXFWYxb/pVU=; b=jmpAV36N4WXjkg0E6Lt680k8YEflLGfhiL158YLta186Lm3J9lX+8RmPLEVVlqpP38 BPFn4BSnIlbzdw+beGArowB53Jp/llcx5csCIPAlcfvuuNgovJZssugdIieFZxX3BwPS qIVnXjl1ljgEM32AsYevh1ayo+yzHuy8BfxpKCfvL6EBEB4YzPzZyHWQ7HTE53R+z6zP pEXNp+Ca9TBvdkmTRAFtszz8MRoOGN+YnFc7B4S8WI0RJwKfp95C2Hkjd91n4zWVMyUZ rdINTMhZdg8FwFd9D2JmdNNTxafPooL+Y5JBCmstWYaOusJLSOotpPjMy4Yd4b7lglqG SYbg== X-Gm-Message-State: AOJu0Yx4APf9tJpqf0OhNorgdbIhxDCpeJnWl6nt/u9IjUWFhkutyuto n7Ww7YWUGAdKKc9IjXj1PLWKVp7FhDRcWbWPEXZ5ax6w1KvY5Ld2qBos5bl5817JnZDF/Rlf7By MjwhNEpCTgsK0aSFVyXNq2/SWjsuS56S2r6Y0Iu7GEta9yDLMlayvYUKHDd1gRhCEadn2c6ppZP OlGYQlTNHmMhI9asb7c0lVPgdd8Sh+8StIj5HL X-Received: by 2002:a05:622a:1305:b0:43d:f4d3:8990 with SMTP id d75a77b69052e-43f9e0c04cfmr53940431cf.40.1716476168848; Thu, 23 May 2024 07:56:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4knHCI1y7ZQ8UZ51KzryHPvknrU7ndeoKWFHCJZ8XCXb84ppDg0sZIsRtAfZHzmWbF8zKPQ== X-Received: by 2002:a05:622a:1305:b0:43d:f4d3:8990 with SMTP id d75a77b69052e-43f9e0c04cfmr53939981cf.40.1716476168398; Thu, 23 May 2024 07:56:08 -0700 (PDT) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Eric Blake , Igor Mammedov , Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Brad Smith , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Coiby Xu , Markus Armbruster , David Hildenbrand , slp@redhat.com, Eduardo Habkost , stefanha@redhat.com, Hanna Reitz , Raphael Norwitz , Jason Wang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Kevin Wolf , gmaglione@redhat.com, Thomas Huth , qemu-block@nongnu.org, Stefano Garzarella Subject: [PATCH v5 05/13] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Thu, 23 May 2024 16:55:14 +0200 Message-ID: <20240523145522.313012-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240523145522.313012-1-sgarzare@redhat.com> References: <20240523145522.313012-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.001, 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 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: 1716476306642100010 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 Signed-off-by: Stefano Garzarella Reviewed-by: David Hildenbrand --- 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