From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9215DA0A0C; Thu, 1 Jul 2021 17:01:12 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1C31D40141; Thu, 1 Jul 2021 17:01:12 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id 591534003E for ; Thu, 1 Jul 2021 17:01:10 +0200 (CEST) Received: from [192.168.38.17] (aros.oktetlabs.ru [192.168.38.17]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by shelob.oktetlabs.ru (Postfix) with ESMTPSA id F0E2F7F528; Thu, 1 Jul 2021 18:01:09 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru F0E2F7F528 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=oktetlabs.ru; s=default; t=1625151670; bh=zYb951wQ5WFDEspDehgsed9nSZnvDsIOB9K7TT/mxiw=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=B3HT3+OecrQsQYveqI5PBIcs6QEj/6Tej4p+fQvcQ/aLo1SfCs0Q3EzoM+n0N5mE8 FvJtCAczsIBQCcpIl2q/b8IQGdlkLzktzLTfxOB/vxWlQPF2Cfmf6TvxXUObYHiSOw snXAuwGs+LqKmj0er0pwwaJT6KT85XGm59fRSa7E= To: Nathan Skrzypczak , dev@dpdk.org Cc: jgrajcia@cisco.com References: <20210617162233.54296-1-nathan.skrzypczak@gmail.com> From: Andrew Rybchenko Organization: OKTET Labs Message-ID: <162bcfeb-926c-834a-40df-42ac3b9730de@oktetlabs.ru> Date: Thu, 1 Jul 2021 18:01:09 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210617162233.54296-1-nathan.skrzypczak@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH] net/memif: fix abstract socket addr_len X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 6/17/21 7:22 PM, Nathan Skrzypczak wrote: > This fixes using abstract sockets with memifs. > we were not passing the exact addr_len, which > requires zeroing the remaining sun_path and > doesn't appear well in other utilities (e.g. > lsof -U) > > Signed-off-by: Nathan Skrzypczak > --- > drivers/net/memif/memif_socket.c | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c > index 5b373738e6..7498a2f58d 100644 > --- a/drivers/net/memif/memif_socket.c > +++ b/drivers/net/memif/memif_socket.c > @@ -866,6 +866,7 @@ memif_socket_create(char *key, uint8_t listener, bool is_abstract) > { > struct memif_socket *sock; > struct sockaddr_un un = { 0 }; > + uint32_t sunlen; > int sockfd; > int ret; > int on = 1; > @@ -890,7 +891,10 @@ memif_socket_create(char *key, uint8_t listener, bool is_abstract) > /* abstract address */ > un.sun_path[0] = '\0'; > strlcpy(un.sun_path + 1, sock->filename, MEMIF_SOCKET_UN_SIZE - 1); > + sunlen = 1 + strlen(sock->filename) + > + sizeof(un.sun_family); It assumes that sockaddr_un consists of two fields. It is better to avoid the assumption and subtract sizeof(un.sun_path) from sizeof(un). It assumes fields order, but it is essential for the patch anyway. Also always true as far as I know. What I don't understand is why we don't care about the case when filename does not fit into sun_path. If so, strlcpy() will truncate it and sunlen will be incorrect. > } else { > + sunlen = sizeof(un); > strlcpy(un.sun_path, sock->filename, MEMIF_SOCKET_UN_SIZE); > } > > @@ -899,7 +903,7 @@ memif_socket_create(char *key, uint8_t listener, bool is_abstract) > if (ret < 0) > goto error; > > - ret = bind(sockfd, (struct sockaddr *)&un, sizeof(un)); > + ret = bind(sockfd, (struct sockaddr *)&un, sunlen); > if (ret < 0) > goto error; > > @@ -1061,6 +1065,7 @@ memif_connect_client(struct rte_eth_dev *dev) > { > int sockfd; > int ret; > + uint32_t sunlen; > struct sockaddr_un sun = { 0 }; > struct pmd_internals *pmd = dev->data->dev_private; > > @@ -1075,16 +1080,18 @@ memif_connect_client(struct rte_eth_dev *dev) > } > > sun.sun_family = AF_UNIX; > + sunlen = sizeof(struct sockaddr_un); > if (pmd->flags & ETH_MEMIF_FLAG_SOCKET_ABSTRACT) { > /* abstract address */ > sun.sun_path[0] = '\0'; > strlcpy(sun.sun_path + 1, pmd->socket_filename, MEMIF_SOCKET_UN_SIZE - 1); > + sunlen = strlen(pmd->socket_filename) + 1 + > + sizeof(sun.sun_family); same as above > } else { > strlcpy(sun.sun_path, pmd->socket_filename, MEMIF_SOCKET_UN_SIZE); > } > > - ret = connect(sockfd, (struct sockaddr *)&sun, > - sizeof(struct sockaddr_un)); > + ret = connect(sockfd, (struct sockaddr *)&sun, sunlen); > if (ret < 0) { > MIF_LOG(ERR, "Failed to connect socket: %s.", pmd->socket_filename); > goto error; >