From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3519FA00C3; Thu, 14 May 2020 09:11:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 98DE41D643; Thu, 14 May 2020 09:11:24 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id 09AE21D606 for ; Thu, 14 May 2020 09:11:22 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from viacheslavo@mellanox.com) with ESMTPS (AES256-SHA encrypted); 14 May 2020 10:11:22 +0300 Received: from pegasus12.mtr.labs.mlnx (pegasus12.mtr.labs.mlnx [10.210.17.40]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 04E7BMb8029715; Thu, 14 May 2020 10:11:22 +0300 Received: from pegasus12.mtr.labs.mlnx (localhost [127.0.0.1]) by pegasus12.mtr.labs.mlnx (8.14.7/8.14.7) with ESMTP id 04E7BMNb008097; Thu, 14 May 2020 07:11:22 GMT Received: (from viacheslavo@localhost) by pegasus12.mtr.labs.mlnx (8.14.7/8.14.7/Submit) id 04E7BMqd008096; Thu, 14 May 2020 07:11:22 GMT X-Authentication-Warning: pegasus12.mtr.labs.mlnx: viacheslavo set sender to viacheslavo@mellanox.com using -f From: Viacheslav Ovsiienko To: dev@dpdk.org Cc: matan@mellanox.com, rasland@mellanox.com, stephen@networkplumber.org, nelio.laranjeiro@6wind.com, stable@dpdk.org Date: Thu, 14 May 2020 07:11:12 +0000 Message-Id: <1589440272-8058-1-git-send-email-viacheslavo@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20200422223000.16602-1-stephen@networkplumber.org> References: <20200422223000.16602-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v2] common/mlx5: fix netlink buffer allocation from stack X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" 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: nelio.laranjeiro@6wind.com Cc: stable@dpdk.org Reported-by: Stephen Hemminger Signed-off-by: Viacheslav Ovsiienko --- v2: allocation from heap, instead of reducing buffer size v1: http://patches.dpdk.org/patch/69158/ --- drivers/common/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 65efcd3..1a1033a 100644 --- a/drivers/common/mlx5/mlx5_nl.c +++ b/drivers/common/mlx5/mlx5_nl.c @@ -330,10 +330,10 @@ struct mlx5_nl_ifindex_data { 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, @@ -345,6 +345,10 @@ struct mlx5_nl_ifindex_data { int multipart = 0; int ret = 0; + if (!buf) { + rte_errno = ENOMEM; + return -rte_errno; + } do { struct nlmsghdr *nh; int recv_bytes = 0; @@ -353,7 +357,8 @@ struct mlx5_nl_ifindex_data { 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); @@ -365,24 +370,30 @@ struct mlx5_nl_ifindex_data { 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; } -- 1.8.3.1