DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Wodkowski, PawelX" <pawelx.wodkowski@intel.com>
To: "Doherty, Declan" <declan.doherty@intel.com>,
	"dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH] bond: static analysis issues fix
Date: Fri, 12 Dec 2014 18:30:42 +0000	[thread overview]
Message-ID: <F6F2A6264E145F47A18AB6DF8E87425D12B79B0C@IRSMSX102.ger.corp.intel.com> (raw)
In-Reply-To: <1418405982-21407-1-git-send-email-declan.doherty@intel.com>



> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Declan Doherty
> Sent: Friday, December 12, 2014 6:40 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH] bond: static analysis issues fix
> 
> Fixes for link bonding library identified by static analysis tool
> 
> - Overflow check for active_slaves array in activate_slave function
> - Allocation check of pci_id_table in rte_eth_bond_create
> - Use of eth_dev pointer in mac_address_get/set before NULL check
> 
> Signed-off-by: Declan Doherty <declan.doherty@intel.com>
> ---
>  lib/librte_pmd_bond/rte_eth_bond_api.c | 12 ++++++++----
>  lib/librte_pmd_bond/rte_eth_bond_pmd.c |  8 ++++----
>  2 files changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/librte_pmd_bond/rte_eth_bond_api.c
> b/lib/librte_pmd_bond/rte_eth_bond_api.c
> index ef5ddf4..9cb1c1f 100644
> --- a/lib/librte_pmd_bond/rte_eth_bond_api.c
> +++ b/lib/librte_pmd_bond/rte_eth_bond_api.c
> @@ -115,8 +115,11 @@ activate_slave(struct rte_eth_dev *eth_dev, uint8_t
> port_id)
>  	if (internals->mode == BONDING_MODE_8023AD)
>  		bond_mode_8023ad_activate_slave(eth_dev, port_id);
> 
> -	internals->active_slaves[internals->active_slave_count] = port_id;
> -	internals->active_slave_count++;
> +	if (internals->active_slave_count <
> +			RTE_DIM(internals->active_slaves) - 1) {
> +		internals->active_slaves[internals->active_slave_count] =
> port_id;
> +		internals->active_slave_count++;
> +	}
>  }
> 
>  void
> @@ -144,7 +147,8 @@ deactivate_slave(struct rte_eth_dev *eth_dev, uint8_t
> port_id)
>  					sizeof(internals->active_slaves[0]));
>  	}
> 
> -	internals->active_slave_count = active_count;
> +	internals->active_slave_count = active_count < RTE_MAX_ETHPORTS ?
> +			active_count : RTE_MAX_ETHPORTS - 1;

Since port might not be added twice and active_slaves array is (should be)
 proper size to contain every port you can add to bonding and in fact is
one element bigger and active_slave_count should newer overflow, those
changes might only mask real problems in user application and/or library itself.
I think if you want to make this static analysis tool happy it should be changed
to RTE_VERIFY(), assert(), rte_panic() or something like that to indicate
undefined state.

Pawel

  reply	other threads:[~2014-12-12 18:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-12 17:39 Declan Doherty
2014-12-12 18:30 ` Wodkowski, PawelX [this message]
2014-12-15 17:13 ` [dpdk-dev] [PATCH v2] " Declan Doherty
2014-12-16  8:50   ` Wodkowski, PawelX
2014-12-16 17:31   ` Thomas Monjalon
2014-12-17 11:46   ` [dpdk-dev] [PATCH v3 0/3] " Declan Doherty
2014-12-17 11:46     ` [dpdk-dev] [PATCH v3 1/3] bond: add bounds check before assigning active slave count value Declan Doherty
2014-12-17 11:46       ` [dpdk-dev] [PATCH v3 2/3] bond: fix pci_id_table allocation check in rte_eth_bond_create Declan Doherty
2014-12-17 11:46         ` [dpdk-dev] [PATCH v3 3/3] bond: eth_dev parameter used before NULL check in mac_address_get/set Declan Doherty
2014-12-17 23:43     ` [dpdk-dev] [PATCH v3 0/3] bond: static analysis issues fix 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=F6F2A6264E145F47A18AB6DF8E87425D12B79B0C@IRSMSX102.ger.corp.intel.com \
    --to=pawelx.wodkowski@intel.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@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).