DPDK patches and discussions
 help / color / mirror / Atom feed
From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
To: Jasvinder Singh <jasvinder.singh@intel.com>,
	Cristian Dumitrescu <cristian.dumitrescu@intel.com>,
	dapengx.yu@intel.com
Cc: dev@dpdk.org, stable@dpdk.org
Subject: Re: [dpdk-dev] [PATCH] net/softnic: fix memory leak in parsing arguments
Date: Tue, 13 Jul 2021 11:44:00 +0300	[thread overview]
Message-ID: <14cca625-2d2e-4949-ef8f-a4ac2570c085@oktetlabs.ru> (raw)
In-Reply-To: <20210708084457.690538-1-dapengx.yu@intel.com>

@Jasvinder, @Cristian, could you the patch, please.

On 7/8/21 11:44 AM, dapengx.yu@intel.com wrote:
> From: Dapeng Yu <dapengx.yu@intel.com>
> 
> 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")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Dapeng Yu <dapengx.yu@intel.com>
> ---
>  drivers/net/softnic/rte_eth_softnic.c           | 9 ++++++---
>  drivers/net/softnic/rte_eth_softnic_internals.h | 4 ++--
>  2 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c
> index f64023256d..4d2f93e9c6 100644
> --- a/drivers/net/softnic/rte_eth_softnic.c
> +++ b/drivers/net/softnic/rte_eth_softnic.c
> @@ -440,6 +440,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)
> @@ -447,7 +448,7 @@ pmd_parse_args(struct pmd_params *p, const char *params)
>  
>  	/* Set default values */
>  	memset(p, 0, sizeof(*p));
> -	p->firmware = SOFTNIC_FIRMWARE;
> +	snprintf(p->firmware, sizeof(p->firmware), "%s", SOFTNIC_FIRMWARE);

Looking at strlcpy(), rte_strlcpy() and rte_strscpy() I think
that rte_strscpy() is the best option here since it is easier
to check return value to protect against buffer overflow and
shortened result.

>  	p->cpu_id = SOFTNIC_CPU_ID;
>  	p->sc = SOFTNIC_SC;
>  	p->tm.n_queues = SOFTNIC_TM_N_QUEUES;
> @@ -468,10 +469,12 @@ 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;
>  	}
> +	snprintf(p->firmware, sizeof(p->firmware), "%s", firmware);

Same here.

> +	free(firmware);
>  
>  	/* Connection listening port (optional) */
>  	if (rte_kvargs_count(kvlist, PMD_PARAM_CONN_PORT) == 1) {
> @@ -621,7 +624,7 @@ pmd_probe(struct rte_vdev_device *vdev)
>  	if (status)
>  		return status;
>  
> -	p.name = name;
> +	snprintf(p.name, sizeof(p.name), "%s", name);

Same here.

>  
>  	/* 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 1b3186ef0b..a13d67b7c1 100644
> --- a/drivers/net/softnic/rte_eth_softnic_internals.h
> +++ b/drivers/net/softnic/rte_eth_softnic_internals.h
> @@ -34,8 +34,8 @@
>   */
>  
>  struct pmd_params {
> -	const char *name;
> -	const char *firmware;
> +	char name[RTE_DEV_NAME_MAX_LEN];
> +	char firmware[PATH_MAX];
>  	uint16_t conn_port;
>  	uint32_t cpu_id;
>  	int sc; /**< Service cores. */
> 


  reply	other threads:[~2021-07-13  8:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-08  8:44 dapengx.yu
2021-07-13  8:44 ` Andrew Rybchenko [this message]
2021-07-13 10:08 ` [dpdk-dev] [PATCH v2] " dapengx.yu
2021-07-13 10:10   ` Andrew Rybchenko
     [not found]     ` <PH0PR11MB512563E3EA51977861DF77CF8C149@PH0PR11MB5125.namprd11.prod.outlook.com>
2021-07-13 10:29       ` Andrew Rybchenko
2021-07-14  5:47   ` [dpdk-dev] [PATCH v3] " dapengx.yu
2021-07-14 11:07     ` Singh, Jasvinder
2021-07-15  1:42       ` Yu, DapengX
2021-07-15  5:38     ` [dpdk-dev] [PATCH v4] " dapengx.yu
2021-07-16 12:04       ` Singh, Jasvinder
2021-07-23  8:11         ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14cca625-2d2e-4949-ef8f-a4ac2570c085@oktetlabs.ru \
    --to=andrew.rybchenko@oktetlabs.ru \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dapengx.yu@intel.com \
    --cc=dev@dpdk.org \
    --cc=jasvinder.singh@intel.com \
    --cc=stable@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).