Re: [PATCH net-next v3 5/9] net: sparx5/lan969x: size the FDMA buffers from the port MTUs

From: netdev-bot+sashiko

Date: Mon Nov 23 2026 - 09:59:25 EST


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

Critical: 0 (1) · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] net: sparx5: UAF of two-step PTP skb on TX drop in
sparx5_port_xmit_impl()

Pre-existing issues:
- [Critical] Use-after-free and double free of two-step PTP skbs on the
Sparx5 TX drop path.

--

net: sparx5/lan969x: size the FDMA buffers from the port MTUs

This commit sizes the Sparx5 and lan969x FDMA buffers from the largest port
MTU plus the Ethernet header, FCS, IFH and two VLAN tags, rather than a
fixed single page. On Sparx5 the RX and TX DB size is that length rounded
up to 128 bytes, and sparx5_fdma_xmit() now drops frames that do not fit.
On lan969x the page_pool page order is derived from the max frame size.

> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
> index 537c945409bba..b92d249777f0b 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c

[ ... ]

> @@ -224,6 +223,10 @@ int sparx5_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb,
> struct fdma *fdma = &tx->fdma;
> void *virt_addr;
>
> + /* Drop frames that do not fit in the TX buffers */
> + if (unlikely(IFH_LEN * 4 + skb->len + ETH_FCS_LEN > fdma->db_size))
> + return -EMSGSIZE;
> +

[Severity: High]
This is a pre-existing problem in sparx5_port_xmit_impl(), but the
new -EMSGSIZE return makes it much easier to hit. What happens to a
two-step PTP skb that fails here?

sparx5_port_xmit_impl() calls sparx5_ptp_txtstamp_request() before
ops->fdma_xmit(). For two-step PTP, that puts the skb on
port->tx_skbs with skb_queue_tail() without taking an extra
reference. It also increments sparx5->ptp_skbs and port->ts_id.

If fdma_xmit() then returns anything other than -EBUSY, the code
jumps to the drop label, which only calls dev_kfree_skb_any(skb).
Only the busy label calls sparx5_ptp_txtstamp_release(port, skb). The
freed skb is therefore still linked on port->tx_skbs.

Later walks of port->tx_skbs happen in
sparx5_ptp_txtstamp_old_release(), in the sparx5 and lan969x PTP IRQ
handlers, and in sparx5_ptp_deinit(). These read SPARX5_SKB_CB() from
freed memory, call __skb_unlink() through stale list pointers, and
call dev_kfree_skb_any() on the same skb again. Isn't that a
use-after-free and a double free?

sparx5->ptp_skbs is also never decremented for these skbs. After
SPARX5_MAX_PTP_ID such drops, sparx5_ptp_txtstamp_request() returns
-EBUSY forever, and two-step TX timestamping on the switch stalls.

Before this patch the Sparx5 TX DB was PAGE_SIZE. The drop path could
only be reached through the -EINVAL ring-full return here, or through
the -ENOMEM DMA mapping failure in lan969x_fdma_xmit(). With the
default MTU of 1500, db_size is now
ALIGN(1518 + 36 + 8, 128) = 1664. Any two-step frame with skb->len
above 1624 now takes the drop path every time.

Such frames can still reach a 1500 MTU port, for example through tc
mirred or bpf_redirect from a device with a larger MTU. They can also
arrive when the MTU is lowered while larger skbs are already queued,
which becomes possible later in this series.

The commit message relies on this drop path. Should the drop label in
sparx5_port_xmit_impl() release two-step PTP skbs the same way the
busy label does? Or would you rather check the length before
sparx5_ptp_txtstamp_request() is called?

[Severity: Critical]
This is a pre-existing issue, but this new return gives a second,
deterministic way to hit it. What happens to a two-step PTP skb that gets
-EMSGSIZE here?

By this point, sparx5_port_xmit_impl()->sparx5_ptp_txtstamp_request() has
already put the skb on port->tx_skbs without taking a reference:

sparx5_ptp.c:sparx5_ptp_txtstamp_request() {
...
skb_queue_tail(&port->tx_skbs, skb);
SPARX5_SKB_CB(skb)->ts_id = port->ts_id;
SPARX5_SKB_CB(skb)->jiffies = jiffies;

sparx5->ptp_skbs++;
port->ts_id++;
...
}

Back in sparx5_port_xmit_impl(), only -EBUSY goes through
sparx5_ptp_txtstamp_release(). Any other negative return frees the skb
while it is still on the list:

sparx5_packet.c:sparx5_port_xmit_impl() {
...
if (ret == -EBUSY)
goto busy;
if (ret < 0)
goto drop;
...
drop:
stats->tx_dropped++;
sparx5->tx.dropped++;
dev_kfree_skb_any(skb);
return NETDEV_TX_OK;
busy:
if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&
SPARX5_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP)
sparx5_ptp_txtstamp_release(port, skb);
return NETDEV_TX_BUSY;
}

The next two-step request then walks the list in
sparx5_ptp_txtstamp_old_release():

skb_queue_walk_safe(&port->tx_skbs, skb, skb_tmp) {
if time_after(SPARX5_SKB_CB(skb)->jiffies + SPARX5_PTP_TIMEOUT,
jiffies)
break;

__skb_unlink(skb, &port->tx_skbs);
dev_kfree_skb_any(skb);

Does this read the cb of the freed skb and then free it again? The TX
timestamp IRQ handler can also find the stale entry. ptp_skbs and ts_id
also stay incremented, so can the PTP ID pool run out?

This path could already be reached through the -EINVAL return when the
next TX DB is not done, i.e. when the TX ring is full.

With this patch and the default MTU of 1500, db_size goes from 4096 to
ALIGN(1518 + 36 + 8, 128) = 1664. A two-step timestamped frame longer
than 1624 bytes used to be sent, but now it always takes the drop path.
Such frames can still reach a 1500 MTU port, for example through tc
mirred or bpf_redirect from a device with a larger MTU.

The commit message says it will "make sparx5_fdma_xmit() drop frames that
do not fit", so it depends on this drop path. Should the drop label in
sparx5_port_xmit_impl() call sparx5_ptp_txtstamp_release() for two-step
PTP skbs, the same way the busy label does? sparx5_port_xmit_impl() is
still unchanged at the end of the series.

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120-sparx5-mtu-change-v3-0-55c272fe1acc%40microchip.com