All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Machon" <daniel.machon@microchip.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH net-next v6 07/14] net: lan966x: add FDMA ops dispatch for PCIe support
Date: Thu, 10 Sep 2026 13:01:47 +0000	[thread overview]
Message-ID: <20260910130147.9D94F1F00899@smtp.kernel.org> (raw)
In-Reply-To: <20260909-lan966x-pci-fdma-v6-7-6f48dab9d671@microchip.com>

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

Pre-existing issues:
- [High] Network device is registered and exposed before FDMA initialization completes, leading to NULL pointer dereference.
- [High] FDMA data structures are freed before network devices are unregistered, causing Use-After-Free on concurrent transmission.
- [High] Missing NULL check for partially populated `lan966x->ports` array when processing received frames.
--

commit ac4a299eb602b1195f379c3cd6e7672750ac4f72
Author: Daniel Machon <daniel.machon@microchip.com>

net: lan966x: add FDMA ops dispatch for PCIe support

Introduce lan966x_fdma_ops to support different FDMA implementations
for platform and PCIe. Plumb fdma_init, fdma_deinit, fdma_xmit,
fdma_poll and fdma_resize through the ops table, and select the
implementation at probe time. Only the platform implementation exists
at this point; the PCIe implementation is added in a later patch.

> diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> index 15fc59cb4ad79..2695bc41e52a9 100644
> --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c
> @@ -947,7 +947,7 @@ void lan966x_fdma_netdev_init(struct lan966x *lan966x, struct net_device *dev)
>  		return;
>  
>  	lan966x->fdma_ndev = dev;
> -	netif_napi_add(dev, &lan966x->napi, lan966x_fdma_napi_poll);
> +	netif_napi_add(dev, &lan966x->napi, lan966x->ops->fdma_poll);
>  	napi_enable(&lan966x->napi);
>  }

[Severity: High]
This is a pre-existing issue, but looking at the RX path in
lan966x_fdma_rx_check_frame(), is there a missing NULL check for the port
array?

The lan966x->ports array is sparsely populated in lan966x_probe() depending on
the provided device tree nodes. When checking the frame, the src_port is
extracted from the Inter-Frame Header (IFH):

lan966x_fdma.c:lan966x_fdma_rx_check_frame() {
    ...
    if (WARN_ON(*src_port >= lan966x->num_phys_ports))
        return FDMA_ERROR;

    port = lan966x->ports[*src_port];
    if (!lan966x_xdp_port_present(port))
    ...
}

While src_port is checked against lan966x->num_phys_ports, there is no check to
ensure lan966x->ports[*src_port] is non-NULL before passing it to
lan966x_xdp_port_present(port).

If the switch hardware generates or loops back a frame with an IFH source port
corresponding to an unconfigured physical port, could this cause a NULL pointer
dereference?

> diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
> index 2741f7c9fa4c0..6e6c08bb8eeab 100644
> --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
> +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c

[ ... ]

> @@ -1250,7 +1260,7 @@ static int lan966x_probe(struct platform_device *pdev)
>  	if (err)
>  		goto cleanup_fdb;
>  
> -	err = lan966x_fdma_init(lan966x);
> +	err = lan966x->ops->fdma_init(lan966x);

[Severity: High]
This isn't a bug introduced by this patch, but I noticed a potential race
condition here during probe.

The network device is registered and exposed to userspace earlier in
lan966x_probe() via lan966x_probe_port() -> register_netdev().
NAPI is also enabled. However, fdma_init() is called only here, which means
there is a window where the netdev is up before the FDMA ring structures
like tx->dcbs_buf are allocated.

If a user-space application configures the interface up and initiates a
transmission concurrently before fdma_init() finishes allocating the DCB
buffers, could lan966x_fdma_get_next_dcb() access a NULL pointer?

>  	if (err)
>  		goto cleanup_ptp;
>  

[ ... ]

> @@ -1291,7 +1301,7 @@ static void lan966x_remove(struct platform_device *pdev)
>  
>  	lan966x_taprio_deinit(lan966x);
>  	lan966x_vcap_deinit(lan966x);
> -	lan966x_fdma_deinit(lan966x);
> +	lan966x->ops->fdma_deinit(lan966x);

[Severity: High]
This is a pre-existing issue, but I see a potential use-after-free in the
unload path.

In lan966x_remove(), ops->fdma_deinit() is called before
lan966x_cleanup_ports() unregisters the network devices. For the platform
implementation, lan966x_fdma_deinit() frees tx->dcbs_buf without stopping the
netdev transmission queues using netif_tx_disable().

If a packet is transmitted concurrently from userspace via ndo_start_xmit
while the module is unloading, could lan966x_fdma_xmit() dereference the
already freed tx->dcbs_buf buffer?

>  	lan966x_cleanup_ports(lan966x);
>  
>  	cancel_delayed_work_sync(&lan966x->stats_work);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909-lan966x-pci-fdma-v6-0-6f48dab9d671@microchip.com?part=7

  reply	other threads:[~2026-09-10 13:01 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 13:00 [PATCH net-next v6 00/14] net: lan966x: add support for PCIe FDMA Daniel Machon
2026-09-09 13:00 ` [PATCH net-next v6 01/14] MAINTAINERS: add FDMA library to Sparx5 SoC entry Daniel Machon
2026-09-09 13:00 ` [PATCH net-next v6 02/14] net: microchip: fdma: rename contiguous dataptr helpers Daniel Machon
2026-09-09 13:00 ` [PATCH net-next v6 03/14] net: microchip: fdma: add PCIe ATU support Daniel Machon
2026-09-10 13:05   ` netdev-bot+sashiko
2026-09-09 13:00 ` [PATCH net-next v6 04/14] net: lan966x: add FDMA LLP register write helper Daniel Machon
2026-09-10 13:01   ` sashiko-bot
2026-09-09 13:00 ` [PATCH net-next v6 05/14] net: lan966x: export FDMA helpers for reuse Daniel Machon
2026-09-09 13:00 ` [PATCH net-next v6 06/14] net: lan966x: use a dedicated device for DMA operations Daniel Machon
2026-09-10 13:01   ` sashiko-bot
2026-09-09 13:00 ` [PATCH net-next v6 07/14] net: lan966x: add FDMA ops dispatch for PCIe support Daniel Machon
2026-09-10 13:01   ` sashiko-bot [this message]
2026-09-09 13:00 ` [PATCH net-next v6 08/14] net: lan966x: clear FDMA interrupt stickies after switch reset Daniel Machon
2026-09-10 13:05   ` netdev-bot+sashiko
2026-09-09 13:00 ` [PATCH net-next v6 09/14] net: lan966x: add shutdown callback to stop FDMA on reboot Daniel Machon
2026-09-10 13:01   ` sashiko-bot
2026-09-10 13:05   ` netdev-bot+sashiko
2026-09-09 13:00 ` [PATCH net-next v6 10/14] net: lan966x: add PCIe FDMA support Daniel Machon
2026-09-10 13:01   ` sashiko-bot
2026-09-10 13:05   ` netdev-bot+sashiko
2026-09-09 13:00 ` [PATCH net-next v6 11/14] net: lan966x: add PCIe FDMA MTU change support Daniel Machon
2026-09-10 13:01   ` sashiko-bot
2026-09-10 13:05   ` netdev-bot+sashiko
2026-09-09 13:00 ` [PATCH net-next v6 12/14] net: lan966x: add PCIe FDMA XDP support Daniel Machon
2026-09-10 13:05   ` netdev-bot+sashiko
2026-09-09 13:00 ` [PATCH net-next v6 13/14] misc: lan966x-pci: dts: extend cpu reg to cover PCIE DBI space Daniel Machon
2026-09-10 13:05   ` netdev-bot+sashiko
2026-09-09 13:00 ` [PATCH net-next v6 14/14] misc: lan966x-pci: dts: add fdma interrupt to overlay Daniel Machon
2026-09-10 13:05   ` netdev-bot+sashiko

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=20260910130147.9D94F1F00899@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel.machon@microchip.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.