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 v3 net-next 13/14] net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver
Date: Sat, 04 Jul 2026 10:43:47 +0000	[thread overview]
Message-ID: <20260704104347.969BB1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260703101328.550714-14-wei.fang@oss.nxp.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Hardware-provided values for TX/RX rings are not bounded against internal fixed-size arrays, leading to out-of-bounds memory writes.
- [High] Missing `cancel_work_sync` for `tx_onestep_tstamp` leads to a Use-After-Free when the device is removed.
--

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

net: enetc: use alloc_etherdev_mqs() to create netdev for VF driver
    
The VF driver uses alloc_etherdev_mq() with ENETC_MAX_NUM_TXQS as the
queue count, which forces the TX and RX queue counts to be equal and
uses a compile-time constant rather than the actual hardware capability.
This patch switches to alloc_etherdev_mqs() so that the TX and RX queue
counts are set independently based on the actual rings assigned.

> diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c
> index 9cdb0a4d6bafb..7dcb4a0246f52 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c
> @@ -317,7 +317,14 @@ static int enetc_vf_probe(struct pci_dev *pdev,
>  
>  	enetc_get_si_caps(si);
>  

[Severity: High]
This isn't a bug introduced by this patch, but can a malicious PF or
hypervisor cause an out-of-bounds write here?

Looking at enetc_get_si_caps(), it reads si->num_tx_rings and
si->num_rx_rings directly from the hardware register ENETC_SICAPR0 and
masks them with 0xff. This allows values up to 255.

While this patch properly bounds the values passed to alloc_etherdev_mqs()
using min(), the driver's internal arrays priv->tx_ring (size 16) and
priv->int_vector (size ENETC_MAX_BDR_INT) are still exposed to these
unbounded hardware values. During initialization, enetc_int_vector_init()
writes to these arrays using the unbounded ring counts, which could
overflow the fixed-size arrays.

Should the hardware capabilities be explicitly bounded against the internal
array sizes when they are read in enetc_get_si_caps()?

> -	ndev = alloc_etherdev_mq(sizeof(*priv), ENETC_MAX_NUM_TXQS);
> +	/* Currently, the supported SoCs have a max of 6 CPUs and the VFs
> +	 * have less than 6 RX/TX rings. So no issues for these supported
> +	 * SoCs, but for future SoCs which have more CPUs or more TX/RX
> +	 * rings, all the related logic needs to be improved.
> +	 */
> +	ndev = alloc_etherdev_mqs(sizeof(*priv),
> +				  min(si->num_tx_rings, ENETC_MAX_NUM_TXQS),
> +				  min(si->num_rx_rings, ENETC_MAX_NUM_TXQS));
>  	if (!ndev) {
>  		err = -ENOMEM;
>  		dev_err(&pdev->dev, "netdev creation failed\n");

[ ... ]

>  err_alloc_si_res:
>  	si->ops->teardown_cbdr(si);
>  err_setup_cbdr:
>  	si->ndev = NULL;
>  	free_netdev(ndev);

[Severity: High]
This is a pre-existing issue, but does this driver have a use-after-free
risk during device removal?

In the device removal path enetc_vf_remove(), which similarly calls
free_netdev(), the driver unregisters and frees the netdev (which also
frees the priv structure) without first calling
cancel_work_sync(&priv->tx_onestep_tstamp).

If a user requests hardware timestamping for outgoing packets and the
device is concurrently unbound, could the background workqueue thread
execute enetc_tx_onestep_tstamp() and dereference the freed priv pointer?

>  err_alloc_netdev:
>  err_get_driver_data:
>  	msg = si->msg;
>  	enetc_pci_remove(pdev);
>  	enetc_msg_dma_free(&pdev->dev, &msg);
>  
>  	return err;
>  }

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

  reply	other threads:[~2026-07-04 10:43 UTC|newest]

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