BPF List
 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 v3 06/13] net: lan966x: add FDMA ops dispatch for PCIe support
Date: Tue, 05 May 2026 18:22:56 +0000	[thread overview]
Message-ID: <20260505182257.623CAC2BCB4@smtp.kernel.org> (raw)
In-Reply-To: <20260504-lan966x-pci-fdma-v3-6-a56f5740d870@microchip.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Teardown asymmetry in `lan966x_remove()` frees FDMA memory before network devices are unregistered, creating a UAF window.
- [High] Premature network device registration exposes the interface before FDMA structures are allocated.
- [High] If `fdma_init()` fails during probe, the NAPI context is deleted while still enabled, violating networking subsystem rules.
--

commit 26b4dc8869b3940c369a8ef84d983f66881dd6b2
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 based on runtime PCI bus detection.

> diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
> index 47752d3fde0b1..9f69634ebb0ae 100644
> --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.c
> +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.c

[ ... ]

> @@ -1232,7 +1247,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);

While reviewing this refactor, I noticed an existing issue regarding the
initialization order. Earlier in the probe sequence, the driver loops over
child nodes and calls lan966x_probe_port(), which executes register_netdev().

Once register_netdev() returns, the network device is fully visible to the
system and transmission can be initiated.

However, the FDMA memory arrays (like tx.dcbs_buf) are not allocated until
lan966x->ops->fdma_init(lan966x) is called here.

If a packet is sent between register_netdev() and fdma_init(), could
lan966x->ops->fdma_xmit() execute and dereference the unallocated tx->dcbs_buf
array?

Additionally, if lan966x->ops->fdma_init() fails, the error path jumps to
cleanup_ptp. This explicitly bypasses cleanup_fdma and skips
lan966x->ops->fdma_deinit().

Since NAPI is enabled early inside lan966x_probe_port() via
lan966x_fdma_netdev_init(), and fdma_deinit() (which contains the
napi_disable() call) is skipped, the NAPI context remains active.

The error path then proceeds to lan966x_cleanup_ports(), which ultimately
calls netif_napi_del().

Can deleting an active NAPI context without disabling it first lead to crashes
if the background polling task is concurrently scheduled?

>  	if (err)
>  		goto cleanup_ptp;

[ ... ]

> @@ -1273,7 +1288,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);

There also appears to be a similar pre-existing issue here during teardown.

lan966x->ops->fdma_deinit() cleanly frees the FDMA RX/TX structures, but the
network interfaces are still active because lan966x_cleanup_ports() (which
unregisters the netdevs) has not executed yet.

During this window, if userspace or the network stack triggers a transmission,
lan966x_port_xmit() will see port->lan966x->fdma as true and invoke
lan966x->ops->fdma_xmit().

Could this transmission routine dereference the recently freed tx->dcbs_buf
buffers, resulting in a use-after-free?

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

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260504-lan966x-pci-fdma-v3-0-a56f5740d870@microchip.com?part=6

  reply	other threads:[~2026-05-05 18:22 UTC|newest]

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

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=20260505182257.623CAC2BCB4@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel.machon@microchip.com \
    --cc=sashiko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox