Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: wei.fang@oss.nxp.com
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH v2 net-next 13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver
Date: Fri, 03 Jul 2026 03:27:05 +0000	[thread overview]
Message-ID: <20260703032705.D5EC91F00A3F@smtp.kernel.org> (raw)
In-Reply-To: <20260702025714.456233-14-wei.fang@oss.nxp.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Dynamically allocating netdev queues based on unvalidated hardware ring counts bypasses previous implicit limits, leading to array overflows and unhandled interrupts (interrupt storms) for queues >= 8.
--

commit 25e82eb7e0ae74aa61ceb3d3b3628db74277e9eb
Author: Wei Fang <wei.fang@nxp.com>

net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver

The VF driver currently uses alloc_etherdev_mq() with a fixed queue count.
This commit changes it to use alloc_etherdev_mqs() so that TX and RX queue
counts can be set independently based on actual hardware capabilities.

> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c
> index 9cdb0a4d6bafb..3df515a6e3335 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c
> @@ -317,7 +317,8 @@ static int enetc_vf_probe(struct pci_dev *pdev,
>  
>  	enetc_get_si_caps(si);
>  
> -	ndev = alloc_etherdev_mq(sizeof(*priv), ENETC_MAX_NUM_TXQS);
> +	ndev = alloc_etherdev_mqs(sizeof(*priv), si->num_tx_rings,
> +				  si->num_rx_rings);

[Severity: High]
By dynamically allocating the netdev queues based on unvalidated hardware
ring counts, can this bypass previous limits and cause array overflows?

Previously, alloc_etherdev_mq() capped the queue allocation to
ENETC_MAX_NUM_TXQS, which safely bounded the number of queues and would fail
if the hardware capabilities were excessive. If a PF or hypervisor
configures the VF with excessive queues (for instance, si->num_tx_rings > 8
or si->num_rx_rings > 6), wouldn't this allocation now succeed and lead to
out-of-bounds writes during initialization?

For example, in enetc_int_vector_init():

drivers/net/ethernet/freescale/enetc/enetc.c:enetc_int_vector_init() {
    ...
    priv->int_vector[i] = v;
    ...
    priv->tx_ring[idx] = bdr;
    ...
}

If si->num_rx_rings > 6 and num_online_cpus() > 6, doesn't this overflow
the priv->int_vector[] array? And if si->num_tx_rings > 16, won't this
overflow the fixed 16-element priv->tx_ring[] array?

Furthermore, for TX queues >= 8, it seems the MSI-X handler and NAPI poll
loop still use the hardcoded limit ENETC_MAX_NUM_TXQS (8):

drivers/net/ethernet/freescale/enetc/enetc.c:enetc_msix() {
    ...
    for_each_set_bit(i, &v->tx_rings_map, ENETC_MAX_NUM_TXQS)
    ...
}

And similarly in enetc_poll():

drivers/net/ethernet/freescale/enetc/enetc.c:enetc_poll() {
    ...
    for_each_set_bit(i, &v->tx_rings_map, ENETC_MAX_NUM_TXQS)
    ...
}

Will this fail to clear or re-enable interrupts for TX queues >= 8,
resulting in unhandled interrupts and an immediate system lockup?

Should we validate si->num_tx_rings and si->num_rx_rings against the
maximum sizes supported by the driver structures before allocating the
netdev?

>  	if (!ndev) {
>  		err = -ENOMEM;
>  		dev_err(&pdev->dev, "netdev creation failed\n");

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260702025714.456233-1-wei.fang@oss.nxp.com?part=13

  reply	other threads:[~2026-07-03  3:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  2:57 [PATCH v2 net-next 00/14] net: enetc: cleanups and improvements wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 01/14] net: enetc: extract common helpers for MAC promiscuous mode setting wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 02/14] net: enetc: extract common helpers for MAC hash filter configuration wei.fang
2026-07-03  3:27   ` sashiko-bot
2026-07-03  7:02     ` Wei Fang (OSS)
2026-07-02  2:57 ` [PATCH v2 net-next 03/14] net: enetc: convert ndo_set_rx_mode() to ndo_set_rx_mode_async() wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 04/14] net: enetc: improve MAFT entry management with bitmap tracking wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 05/14] net: enetc: use PCI device name for debugfs directory wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 06/14] net: enetc: simplify enetc4_set_port_speed() wei.fang
2026-07-02 17:32   ` Maxime Chevallier
2026-07-03  3:27   ` sashiko-bot
2026-07-02  2:57 ` [PATCH v2 net-next 07/14] net: enetc: differentiate phylink capabilities for pseudo-MAC and standalone MAC wei.fang
2026-07-02 17:30   ` Maxime Chevallier
2026-07-03  3:27   ` sashiko-bot
2026-07-02  2:57 ` [PATCH v2 net-next 08/14] net: enetc: remove invalid code from enetc4_pl_mac_link_up() wei.fang
2026-07-02 17:35   ` Maxime Chevallier
2026-07-02  2:57 ` [PATCH v2 net-next 09/14] net: enetc: remove enetc4_set_default_si_vlan_promisc() wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 10/14] net: enetc: refactor SI VLAN promiscuous mode configuration wei.fang
2026-07-03  3:27   ` sashiko-bot
2026-07-02  2:57 ` [PATCH v2 net-next 11/14] net: enetc: move enetc_set_si_vlan_promisc() to enetc_pf_common.c wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 12/14] net: enetc: remove redundant num_vsi field from enetc_port_caps wei.fang
2026-07-02  2:57 ` [PATCH v2 net-next 13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver wei.fang
2026-07-03  3:27   ` sashiko-bot [this message]
2026-07-02  2:57 ` [PATCH v2 net-next 14/14] net: enetc: use kzalloc_flex() for enetc_psfp_gate allocation wei.fang
2026-07-03  3:27   ` sashiko-bot

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=20260703032705.D5EC91F00A3F@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wei.fang@oss.nxp.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