From patchwork Wed Feb 28 11:47:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Garzarella X-Patchwork-Id: 13575314 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C7FCAC47DD9 for ; Wed, 28 Feb 2024 11:49:12 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rfIQb-00037O-Iy; Wed, 28 Feb 2024 06:48:49 -0500 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 1rfIQa-00034o-5B for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:48 -0500 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 1rfIQX-0003jp-Se for qemu-devel@nongnu.org; Wed, 28 Feb 2024 06:48:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709120925; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NRTzpSwWeHQaZAkZ1Wju0ZZmvS1Y/8DKVkOU0OKpskE=; b=JzxR4ajEVa1MVeCDg8KU6cJZLAUvXgUC1WxZrmEsHsdx3xSPatktvXgOz2BX9Vx9NLd/IP PSNdviqZT94m7bezNtpVP3xfNoBffUDQtPEmADwwgpomu8JKQDLdo8lemFNzAKxicCEd1N sTTIcwX16lmuKJeL6b9asFNbzUaIm2g= Received: from mail-yb1-f197.google.com (mail-yb1-f197.google.com [209.85.219.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-693-q1JW1NmIMvm8Mus24gmZ6Q-1; Wed, 28 Feb 2024 06:48:44 -0500 X-MC-Unique: q1JW1NmIMvm8Mus24gmZ6Q-1 Received: by mail-yb1-f197.google.com with SMTP id 3f1490d57ef6-dc64b659a9cso8465890276.3 for ; Wed, 28 Feb 2024 03:48:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709120923; x=1709725723; 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=NRTzpSwWeHQaZAkZ1Wju0ZZmvS1Y/8DKVkOU0OKpskE=; b=GRd8dqxCykb+o3B1MxD9L/yIfLwNhrDvvb/V2csMMOIu4NJZfrYwH3J4cfEeQcAREZ 6TWTuz3QakS7iho0rKoKuIPCJAz83wChw1b0mCOUZa5+Ihwou6If1ltRjtTl2LXVlu0X Z+iIdBvTlCePmgHdCSWmyW+44yIUhj7evrNiEWpiEUj11mswwZdNAnqaGcUaxbXxzxnN f1dSMcfFCw1ACROONCFFg9zJ0CqK21s9VnwW07+zxh6oef0LOW8XQYn5LykSmysdBckv 1bQeLQJdq4aHFoRskWeKPB+M6kQCVtDUfSkQZJpnf0wzIoLJwgG9C1VuloriHGdCvRsm erkA== X-Gm-Message-State: AOJu0Yw8vY0OlW+7hqSrUyi8LzWY2aaCDKahL5YcEaChHzsxMOEVRH+l 7EhGRKqMxaO8PpU3sHdJMS2W1xAAFONcDk5NiKMzW7kqbU82Kn80mfnpQ+QhsRTgSF6A/MGCTLn 7omJ/Y+RUQC9mSbtdT4+zTFoOALJpmI88V20C2Dpqhqd/X7wF1bUhHhaVh4eGmgHrFUVRrhmz0S iM3J+bNtMpJlna6yi1cTpYR1dKpztGJDL97COm X-Received: by 2002:a25:86c5:0:b0:dcf:b5ba:1403 with SMTP id y5-20020a2586c5000000b00dcfb5ba1403mr2145468ybm.6.1709120922877; Wed, 28 Feb 2024 03:48:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfcYHyti9LUIfZ8xO1TKBvsS9yvqRVL1XZY5agcCZwmdzBYf+l7q1Rwk6v0CYLXrz2hafcKQ== X-Received: by 2002:a25:86c5:0:b0:dcf:b5ba:1403 with SMTP id y5-20020a2586c5000000b00dcfb5ba1403mr2145430ybm.6.1709120922454; Wed, 28 Feb 2024 03:48:42 -0800 (PST) Received: from step1.redhat.com (host-82-57-51-64.retail.telecomitalia.it. [82.57.51.64]) by smtp.gmail.com with ESMTPSA id h8-20020ac81388000000b0042e5603b9aasm4484980qtj.75.2024.02.28.03.48.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 03:48:41 -0800 (PST) From: Stefano Garzarella To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, =?utf-8?q?Da?= =?utf-8?q?niel_P=2E_Berrang=C3=A9?= , Thomas Huth , "Michael S. Tsirkin" , Jason Wang , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9_Lureau?= , Markus Armbruster , Eric Blake , Coiby Xu , slp@redhat.com, Eduardo Habkost , Hanna Reitz , Igor Mammedov , Raphael Norwitz , Kevin Wolf , David Hildenbrand , stefanha@redhat.com, gmaglione@redhat.com, Stefano Garzarella , Stefano Garzarella Subject: [PATCH 5/9] contrib/vhost-user-blk: fix bind() using the right size of the address Date: Wed, 28 Feb 2024 12:47:55 +0100 Message-ID: <20240228114759.44758-6-sgarzare@redhat.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240228114759.44758-1-sgarzare@redhat.com> References: <20240228114759.44758-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-type: text/plain 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.102, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PP_MIME_FAKE_ASCII_TEXT=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Stefano Garzarella 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. 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-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; }