[dpdk-stable] patch 'common/mlx5: fix netlink buffer allocation from stack' has been queued to stable release 19.11.3

luca.boccassi at gmail.com luca.boccassi at gmail.com
Fri May 22 11:40:06 CEST 2020


Hi,

FYI, your patch has been queued to stable release 19.11.3

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 05/24/20. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Thanks.

Luca Boccassi

---
>From 070a7b832dacc6a633585f3ec963682783c69b9b Mon Sep 17 00:00:00 2001
From: Viacheslav Ovsiienko <viacheslavo at mellanox.com>
Date: Thu, 14 May 2020 07:11:12 +0000
Subject: [PATCH] common/mlx5: fix netlink buffer allocation from stack

[ upstream commit 3acf1071958185d2a299b9765e0c5c82e67ff416 ]

The buffer size to receive netlink reply messages is relatively
large (32K), and it is allocated on the stack and it might
break in application is using smaller per-thread stacks.
This patch allocates temporary buffer from heap.

Fixes: ccdcba53a3f4 ("net/mlx5: use Netlink to add/remove MAC addresses")

Reported-by: Stephen Hemminger <stephen at networkplumber.org>
Signed-off-by: Viacheslav Ovsiienko <viacheslavo at mellanox.com>
Acked-by: Matan Azrad <matan at mellanox.com>
---
 drivers/net/mlx5/mlx5_nl.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index e7ba03471d..64580b9e6a 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -269,10 +269,10 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
 	     void *arg)
 {
 	struct sockaddr_nl sa;
-	char buf[MLX5_RECV_BUF_SIZE];
+	void *buf = malloc(MLX5_RECV_BUF_SIZE);
 	struct iovec iov = {
 		.iov_base = buf,
-		.iov_len = sizeof(buf),
+		.iov_len = MLX5_RECV_BUF_SIZE,
 	};
 	struct msghdr msg = {
 		.msg_name = &sa,
@@ -284,6 +284,10 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
 	int multipart = 0;
 	int ret = 0;
 
+	if (!buf) {
+		rte_errno = ENOMEM;
+		return -rte_errno;
+	}
 	do {
 		struct nlmsghdr *nh;
 		int recv_bytes = 0;
@@ -292,7 +296,8 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
 			recv_bytes = recvmsg(nlsk_fd, &msg, 0);
 			if (recv_bytes == -1) {
 				rte_errno = errno;
-				return -rte_errno;
+				ret = -rte_errno;
+				goto exit;
 			}
 			nh = (struct nlmsghdr *)buf;
 		} while (nh->nlmsg_seq != sn);
@@ -304,24 +309,30 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
 
 				if (err_data->error < 0) {
 					rte_errno = -err_data->error;
-					return -rte_errno;
+					ret = -rte_errno;
+					goto exit;
 				}
 				/* Ack message. */
-				return 0;
+				ret = 0;
+				goto exit;
 			}
 			/* Multi-part msgs and their trailing DONE message. */
 			if (nh->nlmsg_flags & NLM_F_MULTI) {
-				if (nh->nlmsg_type == NLMSG_DONE)
-					return 0;
+				if (nh->nlmsg_type == NLMSG_DONE) {
+					ret =  0;
+					goto exit;
+				}
 				multipart = 1;
 			}
 			if (cb) {
 				ret = cb(nh, arg);
 				if (ret < 0)
-					return ret;
+					goto exit;
 			}
 		}
 	} while (multipart);
+exit:
+	free(buf);
 	return ret;
 }
 
-- 
2.20.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2020-05-22 10:37:40.262884873 +0100
+++ 0027-common-mlx5-fix-netlink-buffer-allocation-from-stack.patch	2020-05-22 10:37:39.144413000 +0100
@@ -1,28 +1,29 @@
-From 3acf1071958185d2a299b9765e0c5c82e67ff416 Mon Sep 17 00:00:00 2001
+From 070a7b832dacc6a633585f3ec963682783c69b9b Mon Sep 17 00:00:00 2001
 From: Viacheslav Ovsiienko <viacheslavo at mellanox.com>
 Date: Thu, 14 May 2020 07:11:12 +0000
 Subject: [PATCH] common/mlx5: fix netlink buffer allocation from stack
 
+[ upstream commit 3acf1071958185d2a299b9765e0c5c82e67ff416 ]
+
 The buffer size to receive netlink reply messages is relatively
 large (32K), and it is allocated on the stack and it might
 break in application is using smaller per-thread stacks.
 This patch allocates temporary buffer from heap.
 
 Fixes: ccdcba53a3f4 ("net/mlx5: use Netlink to add/remove MAC addresses")
-Cc: stable at dpdk.org
 
 Reported-by: Stephen Hemminger <stephen at networkplumber.org>
 Signed-off-by: Viacheslav Ovsiienko <viacheslavo at mellanox.com>
 Acked-by: Matan Azrad <matan at mellanox.com>
 ---
- drivers/common/mlx5/mlx5_nl.c | 27 +++++++++++++++++++--------
+ drivers/net/mlx5/mlx5_nl.c | 27 +++++++++++++++++++--------
  1 file changed, 19 insertions(+), 8 deletions(-)
 
-diff --git a/drivers/common/mlx5/mlx5_nl.c b/drivers/common/mlx5/mlx5_nl.c
-index 65efcd3df2..1a1033a40b 100644
---- a/drivers/common/mlx5/mlx5_nl.c
-+++ b/drivers/common/mlx5/mlx5_nl.c
-@@ -330,10 +330,10 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
+diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
+index e7ba03471d..64580b9e6a 100644
+--- a/drivers/net/mlx5/mlx5_nl.c
++++ b/drivers/net/mlx5/mlx5_nl.c
+@@ -269,10 +269,10 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
  	     void *arg)
  {
  	struct sockaddr_nl sa;
@@ -35,7 +36,7 @@
  	};
  	struct msghdr msg = {
  		.msg_name = &sa,
-@@ -345,6 +345,10 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
+@@ -284,6 +284,10 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
  	int multipart = 0;
  	int ret = 0;
  
@@ -46,7 +47,7 @@
  	do {
  		struct nlmsghdr *nh;
  		int recv_bytes = 0;
-@@ -353,7 +357,8 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
+@@ -292,7 +296,8 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
  			recv_bytes = recvmsg(nlsk_fd, &msg, 0);
  			if (recv_bytes == -1) {
  				rte_errno = errno;
@@ -56,7 +57,7 @@
  			}
  			nh = (struct nlmsghdr *)buf;
  		} while (nh->nlmsg_seq != sn);
-@@ -365,24 +370,30 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
+@@ -304,24 +309,30 @@ mlx5_nl_recv(int nlsk_fd, uint32_t sn, int (*cb)(struct nlmsghdr *, void *arg),
  
  				if (err_data->error < 0) {
  					rte_errno = -err_data->error;


More information about the stable mailing list