DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/mlx5: do not close stdin on error
@ 2021-10-14 11:37 David Marchand
  2021-10-19 20:57 ` Dmitry Kozlyuk
  2021-11-01  8:55 ` Raslan Darawsheh
  0 siblings, 2 replies; 3+ messages in thread
From: David Marchand @ 2021-10-14 11:37 UTC (permalink / raw)
  To: dev
  Cc: dkozlyuk, stable, Matan Azrad, Viacheslav Ovsiienko, Xueming Li,
	Xiaoyu Min

If for any reason, a socket could not be opened, mlx5_pmd_socket_init()
could close the 0 fd (which is valid, and has a fair chance to be stdin),
since server_socket == 0 from the variable being in .bss.

Fixes: e6cdc54cc0ef ("net/mlx5: add socket server for external tools")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/mlx5/linux/mlx5_socket.c | 29 ++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_socket.c b/drivers/net/mlx5/linux/mlx5_socket.c
index 902b8ec934..93a55bdce5 100644
--- a/drivers/net/mlx5/linux/mlx5_socket.c
+++ b/drivers/net/mlx5/linux/mlx5_socket.c
@@ -22,7 +22,7 @@
 
 #define MLX5_SOCKET_PATH "/var/tmp/dpdk_net_mlx5_%d"
 
-int server_socket; /* Unix socket for primary process. */
+int server_socket = -1; /* Unix socket for primary process. */
 struct rte_intr_handle server_intr_handle; /* Interrupt handler. */
 
 /**
@@ -144,7 +144,7 @@ mlx5_pmd_socket_handle(void *cb __rte_unused)
 static int
 mlx5_pmd_interrupt_handler_install(void)
 {
-	MLX5_ASSERT(server_socket);
+	MLX5_ASSERT(server_socket != -1);
 	server_intr_handle.fd = server_socket;
 	server_intr_handle.type = RTE_INTR_HANDLE_EXT;
 	return rte_intr_callback_register(&server_intr_handle,
@@ -157,7 +157,7 @@ mlx5_pmd_interrupt_handler_install(void)
 static void
 mlx5_pmd_interrupt_handler_uninstall(void)
 {
-	if (server_socket) {
+	if (server_socket != -1) {
 		mlx5_intr_callback_unregister(&server_intr_handle,
 					      mlx5_pmd_socket_handle,
 					      NULL);
@@ -182,7 +182,7 @@ mlx5_pmd_socket_init(void)
 	int flags;
 
 	MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY);
-	if (server_socket)
+	if (server_socket != -1)
 		return 0;
 	ret = socket(AF_UNIX, SOCK_STREAM, 0);
 	if (ret < 0) {
@@ -193,10 +193,10 @@ mlx5_pmd_socket_init(void)
 	server_socket = ret;
 	flags = fcntl(server_socket, F_GETFL, 0);
 	if (flags == -1)
-		goto error;
+		goto close;
 	ret = fcntl(server_socket, F_SETFL, flags | O_NONBLOCK);
 	if (ret < 0)
-		goto error;
+		goto close;
 	snprintf(sun.sun_path, sizeof(sun.sun_path), MLX5_SOCKET_PATH,
 		 getpid());
 	remove(sun.sun_path);
@@ -204,25 +204,26 @@ mlx5_pmd_socket_init(void)
 	if (ret < 0) {
 		DRV_LOG(WARNING,
 			"cannot bind mlx5 socket: %s", strerror(errno));
-		goto close;
+		goto remove;
 	}
 	ret = listen(server_socket, 0);
 	if (ret < 0) {
 		DRV_LOG(WARNING, "cannot listen on mlx5 socket: %s",
 			strerror(errno));
-		goto close;
+		goto remove;
 	}
 	if (mlx5_pmd_interrupt_handler_install()) {
 		DRV_LOG(WARNING, "cannot register interrupt handler for mlx5 socket: %s",
 			strerror(errno));
-		goto close;
+		goto remove;
 	}
 	return 0;
-close:
+remove:
 	remove(sun.sun_path);
-error:
+close:
 	claim_zero(close(server_socket));
-	server_socket = 0;
+	server_socket = -1;
+error:
 	DRV_LOG(ERR, "Cannot initialize socket: %s", strerror(errno));
 	return -errno;
 }
@@ -233,11 +234,11 @@ mlx5_pmd_socket_init(void)
 void
 mlx5_pmd_socket_uninit(void)
 {
-	if (!server_socket)
+	if (server_socket == -1)
 		return;
 	mlx5_pmd_interrupt_handler_uninstall();
 	claim_zero(close(server_socket));
-	server_socket = 0;
+	server_socket = -1;
 	MKSTR(path, MLX5_SOCKET_PATH, getpid());
 	claim_zero(remove(path));
 }
-- 
2.23.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] net/mlx5: do not close stdin on error
  2021-10-14 11:37 [dpdk-dev] [PATCH] net/mlx5: do not close stdin on error David Marchand
@ 2021-10-19 20:57 ` Dmitry Kozlyuk
  2021-11-01  8:55 ` Raslan Darawsheh
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Kozlyuk @ 2021-10-19 20:57 UTC (permalink / raw)
  To: David Marchand, dev
  Cc: stable, Matan Azrad, Slava Ovsiienko, Xueming(Steven) Li, Jack Min

> -----Original Message-----
> From: David Marchand <david.marchand@redhat.com>
> Sent: 14 октября 2021 г. 14:37
> To: dev@dpdk.org
> Cc: Dmitry Kozlyuk <dkozlyuk@nvidia.com>; stable@dpdk.org; Matan Azrad
> <matan@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>;
> Xueming(Steven) Li <xuemingl@nvidia.com>; Jack Min <jackmin@nvidia.com>
> Subject: [PATCH] net/mlx5: do not close stdin on error
> 
> External email: Use caution opening links or attachments
> 
> 
> If for any reason, a socket could not be opened, mlx5_pmd_socket_init()
> could close the 0 fd (which is valid, and has a fair chance to be stdin),
> since server_socket == 0 from the variable being in .bss.
> 
> Fixes: e6cdc54cc0ef ("net/mlx5: add socket server for external tools")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Thanks for taking care of this.
Reviewed-by: Dmitry Kozlyuk <dkozlyuk@nvidia.com>

> ---

Depends-on: patch-101572 ("net/mlx5: close tools socket with the last device")

[...]
>         if (mlx5_pmd_interrupt_handler_install()) {
>                 DRV_LOG(WARNING, "cannot register interrupt handler for
> mlx5 socket: %s",
>                         strerror(errno));

Another bug, `errno` doesn't hold the error code here.
I'll fix it in the follow-up.

> -               goto close;
> +               goto remove;
>         }
>         return 0;
> -close:
> +remove:
>         remove(sun.sun_path);
> -error:
> +close:
>         claim_zero(close(server_socket));
> -       server_socket = 0;
> +       server_socket = -1;
> +error:
>         DRV_LOG(ERR, "Cannot initialize socket: %s", strerror(errno));
>         return -errno;
>  }


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] net/mlx5: do not close stdin on error
  2021-10-14 11:37 [dpdk-dev] [PATCH] net/mlx5: do not close stdin on error David Marchand
  2021-10-19 20:57 ` Dmitry Kozlyuk
@ 2021-11-01  8:55 ` Raslan Darawsheh
  1 sibling, 0 replies; 3+ messages in thread
From: Raslan Darawsheh @ 2021-11-01  8:55 UTC (permalink / raw)
  To: David Marchand, dev
  Cc: Dmitry Kozlyuk, stable, Matan Azrad, Slava Ovsiienko,
	Xueming(Steven) Li, Jack Min

Hi,

> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of David Marchand
> Sent: Thursday, October 14, 2021 2:37 PM
> To: dev@dpdk.org
> Cc: Dmitry Kozlyuk <dkozlyuk@nvidia.com>; stable@dpdk.org; Matan Azrad
> <matan@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>;
> Xueming(Steven) Li <xuemingl@nvidia.com>; Jack Min
> <jackmin@nvidia.com>
> Subject: [dpdk-dev] [PATCH] net/mlx5: do not close stdin on error
> 
> If for any reason, a socket could not be opened, mlx5_pmd_socket_init()
> could close the 0 fd (which is valid, and has a fair chance to be stdin), since
> server_socket == 0 from the variable being in .bss.
> 
> Fixes: e6cdc54cc0ef ("net/mlx5: add socket server for external tools")
> Cc: stable@dpdk.org
> 
> Signed-off-by: David Marchand <david.marchand@redhat.com>
> ---
>  drivers/net/mlx5/linux/mlx5_socket.c | 29 ++++++++++++++--------------
>  1 file changed, 15 insertions(+), 14 deletions(-)

Patch rebased and applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-01  8:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-14 11:37 [dpdk-dev] [PATCH] net/mlx5: do not close stdin on error David Marchand
2021-10-19 20:57 ` Dmitry Kozlyuk
2021-11-01  8:55 ` Raslan Darawsheh

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).