DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Wenbo Cao <caowenbo@mucse.com>
Cc: Ferruh Yigit <ferruh.yigit@amd.com>,
	dev@dpdk.org, yaojun@mucse.com, stable@dpdk.org
Subject: Re: [PATCH v2 1/3] net/rnp: add check firmware respond info
Date: Mon, 30 Jun 2025 08:07:10 -0700	[thread overview]
Message-ID: <20250630080710.09047543@hermes.local> (raw)
In-Reply-To: <20250630055753.35445-2-caowenbo@mucse.com>

On Mon, 30 Jun 2025 13:57:51 +0800
Wenbo Cao <caowenbo@mucse.com> wrote:

> Add logic checks at critical points to detect potentially illegal
> firmware information, preventing subsequent logic exceptions.
> 
> Fixes: 52aae4ed4ffb ("net/rnp: add device capabilities")
> Fixes: 52dfb84e14be ("net/rnp: add device init and uninit")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Wenbo Cao <caowenbo@mucse.com>
> Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>

>  int rnp_mbx_fw_get_capability(struct rnp_eth_port *port)
>  {
>  	struct rnp_phy_abilities_rep ability;
> @@ -252,17 +253,29 @@ int rnp_mbx_fw_get_capability(struct rnp_eth_port *port)
>  		hw->nic_mode = ability.nic_mode;
>  		/* get phy<->lane mapping info */
>  		lane_cnt = rte_popcount32(hw->lane_mask);
> +		if (lane_cnt > RNP_MAX_PORT_OF_PF) {
> +			RNP_PMD_LOG(ERR, "firmware invalid lane_mask");
> +			return -EINVAL;
> +		}
>  		temp_mask = hw->lane_mask;
> +		if (temp_mask == 0 || temp_mask > RNP_MAX_LANE_MASK) {
> +			RNP_PMD_LOG(ERR, "lane_mask is invalid 0x%.2x", temp_mask);
> +			return -EINVAL;
> +		}
>  		if (ability.e.ports_is_sgmii_valid)
>  			is_sgmii_bits = ability.e.lane_is_sgmii;
>  		for (idx = 0; idx < lane_cnt; idx++) {
>  			hw->phy_port_ids[idx] = port_ids[idx];
> +			if (temp_mask == 0) {
> +				RNP_PMD_LOG(ERR, "temp_mask is zero at idx=%d", idx);
> +				return -EINVAL;
> +			}
>  			lane_bit = ffs(temp_mask) - 1;
>  			lane_idx = port_ids[idx] % lane_cnt;
>  			hw->lane_of_port[lane_idx] = lane_bit;
>  			is_sgmii = lane_bit & is_sgmii_bits ? 1 : 0;
>  			hw->lane_is_sgmii[lane_idx] = is_sgmii;
> -			temp_mask &= ~RTE_BIT32(lane_bit);
> +			temp_mask &= ~(1ULL << lane_bit);

Rather than using ffs directly better to consistently use rte_bitops
which has rte_ffs32().  You can address it in a future version.


  reply	other threads:[~2025-06-30 15:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-30  5:57 [PATCH v2 0/3] [v2]drivers/net/rnp fixed Coverity issue Wenbo Cao
2025-06-30  5:57 ` [PATCH v2 1/3] net/rnp: add check firmware respond info Wenbo Cao
2025-06-30 15:07   ` Stephen Hemminger [this message]
2025-06-30  5:57 ` [PATCH v2 2/3] net/rnp: fix Tunnel-TSO VLAN header untrusted loop bound Wenbo Cao
2025-06-30  5:57 ` [PATCH v2 3/3] net/rnp: fix TSO segmentation for packets of 64KB Wenbo Cao

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=20250630080710.09047543@hermes.local \
    --to=stephen@networkplumber.org \
    --cc=caowenbo@mucse.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=stable@dpdk.org \
    --cc=yaojun@mucse.com \
    /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).