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 590B8A0C47 for ; Mon, 26 Jul 2021 15:55:25 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 51E97410EF; Mon, 26 Jul 2021 15:55:25 +0200 (CEST) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) by mails.dpdk.org (Postfix) with ESMTP id A768840DDA for ; Mon, 26 Jul 2021 15:55:23 +0200 (CEST) Received: by mail-wr1-f47.google.com with SMTP id r2so11244357wrl.1 for ; Mon, 26 Jul 2021 06:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LmvTfBPwcdyurq1hu/C88J/fbHztzFLBoCicND7+3Nk=; b=g3VcLiSk6Pdlt4ISWhEGlnHESyyaT+3a6EF/NUBllBWnpUI36ddHDnOW8C7E8pMJLl L8strFQxW3+xVMvTzDtJGgu4cRBFM/Gf8QAFRrOUEfoKcLtn4EvfeGtBnhvvMy/TyYiw NMVR+1q/TxJ2ecncaASVIoOkjNY+Y4krYhzR/uXwyWb2N83b692PHuppRj54XKff5H51 aGbpGn9FCyEL6AqZrPnwZOWnIlKtINLfYGRYoLOKY6G0XqqiGa+tVXHLlUhBV80WT/7R wzaA8LS8aq3cIVZ0omDv6ZvezexI4FSoozwuRmSQmHRXjNMtE5ebr5EuhdEjLF1SKE6l 8q5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LmvTfBPwcdyurq1hu/C88J/fbHztzFLBoCicND7+3Nk=; b=s+zCLxnRCpziBo2r28ekadZii5TsY5+cEo1Uv3dWnaCRRswyAfjcgL+0J+AKjnwKg+ EkaFN0Hx8caFQUgpZ7kt5ktY7zc5Z5vlVCszkhZ3Se5EhWN3xpKovXshQXBdFU+RIUTm HC+SQqqWHcyL8YVnNKGsmtp5bBK7QK5xuwnwbi0VrWZlVvTaY+/O7piQS6RaxS0eQSki tup9Ah94g9hSziqGy+ZGRobAZiCwwtnlfUxPjD9tD0TZV0TUzigxNvUgGMcPCHttlyny X81rQvTIf/VHEI3U/Im4ahNKQqnyIZBUknttswHkk4R2NjP+p3UbpfV4iKhQSZX/newF gjsg== X-Gm-Message-State: AOAM530N5Tm/c4t9Q6Vi/AWpwRzsKxb7kuGrTenaytEaY/FhFKiDYrCP ACa9fK/obT2pPR5rPK4JIZpF2Tsq1qKCad52 X-Google-Smtp-Source: ABdhPJzzu8t/GeSzUqPREhBunf/26idYLeKkRVtaI+8R2MO+73ti5/AV9ed5RSyPkOIRARqsKbwJRg== X-Received: by 2002:adf:f288:: with SMTP id k8mr1605737wro.350.1627307723475; Mon, 26 Jul 2021 06:55:23 -0700 (PDT) Received: from localhost ([137.220.125.106]) by smtp.gmail.com with ESMTPSA id a8sm42554210wrt.61.2021.07.26.06.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jul 2021 06:55:23 -0700 (PDT) From: luca.boccassi@gmail.com To: Dapeng Yu Cc: Jasvinder Singh , dpdk stable Date: Mon, 26 Jul 2021 14:53:02 +0100 Message-Id: <20210726135322.149850-39-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210726135322.149850-1-luca.boccassi@gmail.com> References: <20210712130551.2462159-1-luca.boccassi@gmail.com> <20210726135322.149850-1-luca.boccassi@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-stable] patch 'net/softnic: fix memory leak in arguments parsing' has been queued to stable release 20.11.3 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" Hi, FYI, your patch has been queued to stable release 20.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 07/28/21. 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. Queued patches are on a temporary branch at: https://github.com/bluca/dpdk-stable This queued commit can be viewed at: https://github.com/bluca/dpdk-stable/commit/752b19f91f53bb093d7081ac8a16e80872b82061 Thanks. Luca Boccassi --- >From 752b19f91f53bb093d7081ac8a16e80872b82061 Mon Sep 17 00:00:00 2001 From: Dapeng Yu Date: Thu, 15 Jul 2021 13:38:14 +0800 Subject: [PATCH] net/softnic: fix memory leak in arguments parsing [ upstream commit d8f852f5f3692bbf15743d1aca25e6abcbe652ad ] In function pmd_parse_args(), firmware path is duplicated from device arguments as character string, but is never freed, which cause memory leak. This patch changes the type of firmware member of struct pmd_params to character array, to make memory resource release unnecessary, and changes the type of name member to character array, to keep the consistency of character string handling in struct pmd_params. Fixes: 7e68bc20f8c8 ("net/softnic: restructure") Signed-off-by: Dapeng Yu Acked-by: Jasvinder Singh --- drivers/net/softnic/rte_eth_softnic.c | 30 ++++++++++++++++--- .../net/softnic/rte_eth_softnic_internals.h | 5 ++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c index 3387ab485f..ceed6bf96d 100644 --- a/drivers/net/softnic/rte_eth_softnic.c +++ b/drivers/net/softnic/rte_eth_softnic.c @@ -447,6 +447,7 @@ pmd_parse_args(struct pmd_params *p, const char *params) { struct rte_kvargs *kvlist; int ret = 0; + char *firmware = NULL; kvlist = rte_kvargs_parse(params, pmd_valid_args); if (kvlist == NULL) @@ -454,7 +455,14 @@ pmd_parse_args(struct pmd_params *p, const char *params) /* Set default values */ memset(p, 0, sizeof(*p)); - p->firmware = SOFTNIC_FIRMWARE; + if (rte_strscpy(p->firmware, SOFTNIC_FIRMWARE, + sizeof(p->firmware)) < 0) { + PMD_LOG(WARNING, + "\"%s\": firmware path should be shorter than %zu", + SOFTNIC_FIRMWARE, sizeof(p->firmware)); + ret = -EINVAL; + goto out_free; + } p->cpu_id = SOFTNIC_CPU_ID; p->sc = SOFTNIC_SC; p->tm.n_queues = SOFTNIC_TM_N_QUEUES; @@ -475,11 +483,20 @@ pmd_parse_args(struct pmd_params *p, const char *params) /* Firmware script (optional) */ if (rte_kvargs_count(kvlist, PMD_PARAM_FIRMWARE) == 1) { ret = rte_kvargs_process(kvlist, PMD_PARAM_FIRMWARE, - &get_string, &p->firmware); + &get_string, &firmware); if (ret < 0) goto out_free; } - + if (rte_strscpy(p->firmware, firmware, + sizeof(p->firmware)) < 0) { + PMD_LOG(WARNING, + "\"%s\": firmware path should be shorter than %zu", + firmware, sizeof(p->firmware)); + free(firmware); + ret = -EINVAL; + goto out_free; + } + free(firmware); /* Connection listening port (optional) */ if (rte_kvargs_count(kvlist, PMD_PARAM_CONN_PORT) == 1) { ret = rte_kvargs_process(kvlist, PMD_PARAM_CONN_PORT, @@ -628,7 +645,12 @@ pmd_probe(struct rte_vdev_device *vdev) if (status) return status; - p.name = name; + if (rte_strscpy(p.name, name, sizeof(p.name)) < 0) { + PMD_LOG(WARNING, + "\"%s\": device name should be shorter than %zu", + name, sizeof(p.name)); + return -EINVAL; + } /* Allocate and initialize soft ethdev private data */ dev_private = pmd_init(&p); diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h index 9c8737c9e2..263c48ba3b 100644 --- a/drivers/net/softnic/rte_eth_softnic_internals.h +++ b/drivers/net/softnic/rte_eth_softnic_internals.h @@ -28,14 +28,15 @@ #include "conn.h" #define NAME_SIZE 64 +#define SOFTNIC_PATH_MAX 4096 /** * PMD Parameters */ struct pmd_params { - const char *name; - const char *firmware; + char name[NAME_SIZE]; + char firmware[SOFTNIC_PATH_MAX]; uint16_t conn_port; uint32_t cpu_id; int sc; /**< Service cores. */ -- 2.30.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2021-07-26 13:53:17.924036838 +0100 +++ 0039-net-softnic-fix-memory-leak-in-arguments-parsing.patch 2021-07-26 13:53:15.897293631 +0100 @@ -1 +1 @@ -From d8f852f5f3692bbf15743d1aca25e6abcbe652ad Mon Sep 17 00:00:00 2001 +From 752b19f91f53bb093d7081ac8a16e80872b82061 Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit d8f852f5f3692bbf15743d1aca25e6abcbe652ad ] + @@ -16 +17,0 @@ -Cc: stable@dpdk.org @@ -26 +27 @@ -index f64023256d..0aa7147b13 100644 +index 3387ab485f..ceed6bf96d 100644 @@ -29 +30 @@ -@@ -440,6 +440,7 @@ pmd_parse_args(struct pmd_params *p, const char *params) +@@ -447,6 +447,7 @@ pmd_parse_args(struct pmd_params *p, const char *params) @@ -37 +38 @@ -@@ -447,7 +448,14 @@ pmd_parse_args(struct pmd_params *p, const char *params) +@@ -454,7 +455,14 @@ pmd_parse_args(struct pmd_params *p, const char *params) @@ -53 +54 @@ -@@ -468,11 +476,20 @@ pmd_parse_args(struct pmd_params *p, const char *params) +@@ -475,11 +483,20 @@ pmd_parse_args(struct pmd_params *p, const char *params) @@ -76 +77 @@ -@@ -621,7 +638,12 @@ pmd_probe(struct rte_vdev_device *vdev) +@@ -628,7 +645,12 @@ pmd_probe(struct rte_vdev_device *vdev) @@ -91 +92 @@ -index 1b3186ef0b..07285ca315 100644 +index 9c8737c9e2..263c48ba3b 100644