* [dpdk-dev] [PATCH] net/memif: fix abstract socket addr_len
@ 2021-06-17 16:22 Nathan Skrzypczak
2021-07-01 15:01 ` Andrew Rybchenko
2021-07-23 9:18 ` [dpdk-dev] [PATCH v2] " Nathan Skrzypczak
0 siblings, 2 replies; 6+ messages in thread
From: Nathan Skrzypczak @ 2021-06-17 16:22 UTC (permalink / raw)
To: dev; +Cc: jgrajcia
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 <nathan.skrzypczak@gmail.com>
---
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);
} 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);
} 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;
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH] net/memif: fix abstract socket addr_len
2021-06-17 16:22 [dpdk-dev] [PATCH] net/memif: fix abstract socket addr_len Nathan Skrzypczak
@ 2021-07-01 15:01 ` Andrew Rybchenko
2021-07-23 9:18 ` [dpdk-dev] [PATCH v2] " Nathan Skrzypczak
1 sibling, 0 replies; 6+ messages in thread
From: Andrew Rybchenko @ 2021-07-01 15:01 UTC (permalink / raw)
To: Nathan Skrzypczak, dev; +Cc: jgrajcia
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 <nathan.skrzypczak@gmail.com>
> ---
> 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;
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dpdk-dev] [PATCH v2] net/memif: fix abstract socket addr_len
2021-06-17 16:22 [dpdk-dev] [PATCH] net/memif: fix abstract socket addr_len Nathan Skrzypczak
2021-07-01 15:01 ` Andrew Rybchenko
@ 2021-07-23 9:18 ` Nathan Skrzypczak
2021-07-28 11:10 ` Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)
1 sibling, 1 reply; 6+ messages in thread
From: Nathan Skrzypczak @ 2021-07-23 9:18 UTC (permalink / raw)
To: dev; +Cc: andrew.rybchenko, Jakub Grajciar
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 <nathan.skrzypczak@gmail.com>
---
drivers/net/memif/memif_socket.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/net/memif/memif_socket.c b/drivers/net/memif/memif_socket.c
index 5b373738e6..f58ff4c0cb 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,11 @@ 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 = RTE_MIN(1 + strlen(sock->filename),
+ MEMIF_SOCKET_UN_SIZE) +
+ sizeof(un) - sizeof(un.sun_path);
} else {
+ sunlen = sizeof(un);
strlcpy(un.sun_path, sock->filename, MEMIF_SOCKET_UN_SIZE);
}
@@ -899,7 +904,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 +1066,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 +1081,19 @@ 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 = RTE_MIN(strlen(pmd->socket_filename) + 1,
+ MEMIF_SOCKET_UN_SIZE) +
+ sizeof(sun) - sizeof(sun.sun_path);
} 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;
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH v2] net/memif: fix abstract socket addr_len
2021-07-23 9:18 ` [dpdk-dev] [PATCH v2] " Nathan Skrzypczak
@ 2021-07-28 11:10 ` Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)
2021-07-30 11:24 ` Thomas Monjalon
0 siblings, 1 reply; 6+ messages in thread
From: Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco) @ 2021-07-28 11:10 UTC (permalink / raw)
To: Nathan Skrzypczak, dev; +Cc: andrew.rybchenko
> -----Original Message-----
> From: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
> Sent: Friday, July 23, 2021 11:19 AM
> To: dev@dpdk.org
> Cc: andrew.rybchenko@oktetlabs.ru; Jakub Grajciar -X (jgrajcia - PANTHEON
> TECH SRO at Cisco) <jgrajcia@cisco.com>
> Subject: [PATCH v2] net/memif: fix abstract socket addr_len
>
> 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 <nathan.skrzypczak@gmail.com>
Looks ok to me.
Reviewed-by: Jakub Grajciar <jgrajcia@cisco.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH v2] net/memif: fix abstract socket addr_len
2021-07-28 11:10 ` Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)
@ 2021-07-30 11:24 ` Thomas Monjalon
2021-07-30 12:53 ` Nathan Skrzypczak
0 siblings, 1 reply; 6+ messages in thread
From: Thomas Monjalon @ 2021-07-30 11:24 UTC (permalink / raw)
To: Nathan Skrzypczak
Cc: dev, andrew.rybchenko,
Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)
> > 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 <nathan.skrzypczak@gmail.com>
>
> Looks ok to me.
>
> Reviewed-by: Jakub Grajciar <jgrajcia@cisco.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH v2] net/memif: fix abstract socket addr_len
2021-07-30 11:24 ` Thomas Monjalon
@ 2021-07-30 12:53 ` Nathan Skrzypczak
0 siblings, 0 replies; 6+ messages in thread
From: Nathan Skrzypczak @ 2021-07-30 12:53 UTC (permalink / raw)
To: Thomas Monjalon
Cc: dev, andrew.rybchenko,
Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)
Thanks !
Le ven. 30 juil. 2021 à 13:23, Thomas Monjalon <thomas@monjalon.net> a
écrit :
> > > 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 <nathan.skrzypczak@gmail.com>
> >
> > Looks ok to me.
> >
> > Reviewed-by: Jakub Grajciar <jgrajcia@cisco.com>
>
> Applied, thanks.
>
>
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-07-31 9:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 16:22 [dpdk-dev] [PATCH] net/memif: fix abstract socket addr_len Nathan Skrzypczak
2021-07-01 15:01 ` Andrew Rybchenko
2021-07-23 9:18 ` [dpdk-dev] [PATCH v2] " Nathan Skrzypczak
2021-07-28 11:10 ` Jakub Grajciar -X (jgrajcia - PANTHEON TECH SRO at Cisco)
2021-07-30 11:24 ` Thomas Monjalon
2021-07-30 12:53 ` Nathan Skrzypczak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).