Re: [PATCH v2 net 4/4] net: enetc: let core segment GSO skb when headers exceed TSO_HEADER_SIZE
From: Eric Dumazet
Date: Wed Nov 18 2026 - 19:03:37 EST
Le jeu. 19 nov. 2026 à 00:51, Vladimir Oltean
<vladimir.oltean@xxxxxxx> a écrit :
>
> Like many other drivers, the software TSO path (enetc_map_tx_tso_buffs())
> copies the L2+L3+L4 headers of the skb into a fixed-size TSO_HEADER_SIZE
> (256 byte) slot of the per-ring dma_alloc_coherent() header area,
> without checking that they fit.
>
> Sashiko casually points out during review of an unrelated patch:
> https://lore.kernel.org/netdev/179294166520.3134.18097439321876673016@xxxxxxxxxx/
> that TSO_HEADER_SIZE does not constitute the maximum size that packet
> headers can have for GSO skbs, but rather, an essentially arbitrary
> number.
>
> An example where headers can exceed TSO_HEADER_SIZE is with an IPv6
> extension named Segment Routing Header, set through setsockopt(IPV6_RTHDR),
> with a type 4 routing header. With 11 or more segments, the headers of a
> TCP/IPv6 packet exceed 256 bytes:
>
> Ethernet 14
> IPv6 40
> SRH, 12 segments 8 + 12 * 16 = 200
> TCP (with timestamps) 32
> ---
> 286 (30 bytes too many)
>
> No privileges are required to request this socket option (but it will
> cause driver writes outside allocated memory). A reproducer sketch can
> be found at:
> https://gist.github.com/vladimiroltean/7cecf636b788b29f361a2fbdae646010
>
> Bizarrely, enetc is the only affected driver, because the core
> accidentally protects most other drivers against this bug in
> gso_features_check(). There, we have this logic that saves the day:
>
> /* NETIF_F_IPV6_CSUM does not support IPv6 extension headers,
> * so neither does TSO that depends on it.
> */
> if (features & NETIF_F_IPV6_CSUM &&
> skb_has_ipv6_extension_hdr(skb))
> features &= ~(NETIF_F_IPV6_CSUM | NETIF_F_TSO6 | NETIF_F_GSO_UDP_L4);
>
> enetc is the outlier because it only advertises the more complete
> NETIF_F_HW_CSUM, so for it, this fixup does not clear the NETIF_F_TSO6
> and NETIF_F_GSO_UDP_L4 bits.
>
> [ astute reviewers may ask: what if we disable NETIF_F_IPV6_CSUM at
> runtime, via ethtool -k, so as to bypass this fixup, don't we make
> all drivers vulnerable?
> No, because netdev_fix_features() will trigger the code path which
> also prints "Dropping TSO6 features since no CSUM feature.\n".
> So TSO skbs will now be segmented in the stack. ]
>
> Surveying every driver that uses TSO_HEADER_SIZE:
>
> Driver | TSO6 | Checksum feature | Core guard fires? | Verdict
> ---------------|---------------------|-------------------|---------
> enetc | yes | NETIF_F_HW_CSUM | no | vulnerable
> bnxt | yes | NETIF_F_IPV6_CSUM | yes | safe
> nicvf | yes | NETIF_F_IPV6_CSUM | yes | safe
> otx2 | yes | NETIF_F_IPV6_CSUM | yes | safe
> fec | no | NETIF_F_IPV6_CSUM | n/a | safe
> mvneta | no | NETIF_F_IPV6_CSUM | n/a | safe
> mvpp2 | no | NETIF_F_IPV6_CSUM | n/a | safe
> mv643xx | no | NETIF_F_IP_CSUM | n/a | safe
> dpaa2 | no | NETIF_F_IPV6_CSUM | n/a | safe (*)
>
> (*) dpaa2 also uses a fixed-size kmalloc(TSO_HEADER_SIZE) per segment,
> so the identical overflow would apply if it ever gained NETIF_F_TSO6.
>
> The above survey is what influenced the decision to make a localized
> patch in enetc_features_check() rather than create a huge disturbance in
> the core, even though, IMO, TSO_HEADER_SIZE is a huge foot gun.
>
> Note that the LSO path (enetc_lso_map_hdr()) also copies the header into
> the tso_headers buffers for a reason I don't quite understand. However,
> I've excluded it from the discussion because when the GSO header size
> grows to weird sizes, it never gets anywhere near TSO_HEADER_SIZE before
> hardware stops being able to support this offload. There's an earlier
> limit at ENETC_TX_CSUM_MAX_L4_OFFSET at which it stops being able to
> perform HW TX checksumming (a dependency feature).
>
> Fixes: fb8629e2cbfc ("net: enetc: add support for software TSO")
> Signed-off-by: Vladimir Oltean <vladimir.oltean@xxxxxxx>
> ---
> v1->v2:
> - drop word "super" from "GSO super-skb"
> - subtract VLAN_HLEN from maximum permissible GSO header size
> - stop blaming LSO
> ---
> drivers/net/ethernet/freescale/enetc/enetc.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
> index 6cc519eea5bd..2bc65cf6f508 100644
> --- a/drivers/net/ethernet/freescale/enetc/enetc.c
> +++ b/drivers/net/ethernet/freescale/enetc/enetc.c
> @@ -1138,7 +1138,19 @@ netdev_features_t enetc_features_check(struct sk_buff *skb,
> return features;
> }
>
> - if (!skb_is_gso(skb) || enetc_skb_uses_lso(priv, skb))
> + if (!skb_is_gso(skb))
> + return features;
> +
> + /* In case NETIF_F_HW_VLAN_CTAG_TX is disabled, validate_xmit_vlan()
> + * has not yet run and a VLAN may still be in the hwaccel area, so we
> + * need to be one step ahead
> + */
> + if (enetc_lso_get_hdr_len(skb) > TSO_HEADER_SIZE - VLAN_HLEN) {
> + features &= ~NETIF_F_GSO_MASK;
> + return features;
> + }
> +
> + if (enetc_skb_uses_lso(priv, skb))
> return features;
>
> if (enetc_tso_count_descs(skb) >= priv->tx_bd_count)
> --
> 2.53.0
I should probably rework my series :
https://lore.kernel.org/netdev/20260403043237.3909226-1-edumazet@xxxxxxxxxx/