* [PATCH v2 net 1/4] net: enetc: let core segment GSO skb when TSO would not fit the TX ring
2026-11-18 23:50 [PATCH v2 net 0/4] ENETC GSO fixes Vladimir Oltean
@ 2026-11-18 23:50 ` Vladimir Oltean
2026-11-18 23:50 ` [PATCH v2 net 2/4] net: enetc: reserve VLAN extension BDs for software TSO Vladimir Oltean
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Vladimir Oltean @ 2026-11-18 23:50 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Claudiu Manoil, Wei Fang, Clark Wang, Ioana Ciornei,
Willem de Bruijn, imx, linux-kernel
For simplicity reasons, the enetc software GSO implementation waits for
the TX ring to free up sufficiently that all BDs that would be generated
by driver-level segmentation can be enqueued in one go. To pass the time,
it stops the queue and returns NETDEV_TX_BUSY for the core to requeue.
The problem is that without any limits on gso_segs, some GSO skbs can
never be sent, and the aforementioned behaviour results in the queue
stalling (there is also no ndo_tx_timeout implementation).
This was reported by Sashiko, but is a valid issue which can be easily
triggered from any source that can craft gso_segs in a way that
tso_count_descs() can exceed 2047 (the ring size minus the obligatory
free entry). Valid reproduction methods include TCP peers whose MSS is
close to tcp_min_snd_mss plus large (64KB) TSO skbs; UDP GSO using
setsockopt(UDP_SEGMENT); maybe others.
Add an ndo_features_check() that clears the GSO features for skbs that
take the software TSO path and whose descriptor estimate is larger than
the ring could ever provide. The core then segments these skbs itself
before calling ndo_start_xmit().
Capping the segment count with netif_set_tso_max_segs() would be
simpler, but its drawback is that it's static, so it would have to
assume the worst case for every skb (MAX_SKB_FRAGS, and later the
per-segment VLAN and padding BDs). This would reduce TSO sizes even for
skbs that fit.
Fixes: fb8629e2cbfc ("net: enetc: add support for software TSO")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v1->v2: dropped the word "super" from "GSO super-skb"
---
drivers/net/ethernet/freescale/enetc/enetc.c | 31 ++++++++++++++++---
drivers/net/ethernet/freescale/enetc/enetc.h | 3 ++
.../net/ethernet/freescale/enetc/enetc4_pf.c | 1 +
.../net/ethernet/freescale/enetc/enetc_pf.c | 1 +
.../net/ethernet/freescale/enetc/enetc_vf.c | 2 ++
5 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index c6571b5cc842..1606ac57016f 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -695,6 +695,14 @@ static int enetc_lso_get_hdr_len(const struct sk_buff *skb)
return hdr_len;
}
+static bool enetc_skb_uses_lso(const struct enetc_ndev_priv *priv,
+ const struct sk_buff *skb)
+{
+ /* LSO data unit lengths of up to 256KB are supported */
+ return priv->active_offloads & ENETC_F_LSO &&
+ (skb->len - enetc_lso_get_hdr_len(skb)) <= ENETC_LSO_MAX_DATA_LEN;
+}
+
static void enetc_lso_start(struct sk_buff *skb, struct enetc_lso_t *lso)
{
lso->lso_seg_size = skb_shinfo(skb)->gso_size;
@@ -1018,10 +1026,7 @@ static netdev_tx_t enetc_start_xmit(struct sk_buff *skb,
tx_ring = priv->tx_ring[skb->queue_mapping];
if (skb_is_gso(skb)) {
- /* LSO data unit lengths of up to 256KB are supported */
- if (priv->active_offloads & ENETC_F_LSO &&
- (skb->len - enetc_lso_get_hdr_len(skb)) <=
- ENETC_LSO_MAX_DATA_LEN) {
+ if (enetc_skb_uses_lso(priv, skb)) {
if (enetc_bd_unused(tx_ring) < enetc_lso_count_descs(skb)) {
netif_stop_subqueue(ndev, tx_ring->index);
return NETDEV_TX_BUSY;
@@ -1098,6 +1103,24 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev)
}
EXPORT_SYMBOL_GPL(enetc_xmit);
+netdev_features_t enetc_features_check(struct sk_buff *skb,
+ struct net_device *ndev,
+ netdev_features_t features)
+{
+ struct enetc_ndev_priv *priv = netdev_priv(ndev);
+
+ features = vlan_features_check(skb, features);
+
+ if (!skb_is_gso(skb) || enetc_skb_uses_lso(priv, skb))
+ return features;
+
+ if (tso_count_descs(skb) >= priv->tx_bd_count)
+ features &= ~NETIF_F_GSO_MASK;
+
+ return features;
+}
+EXPORT_SYMBOL_GPL(enetc_features_check);
+
static irqreturn_t enetc_msix(int irq, void *data)
{
struct enetc_int_vector *v = data;
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
index d9e91832a9c1..1e3290d1a388 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc.h
@@ -529,6 +529,9 @@ int enetc_close(struct net_device *ndev);
void enetc_start(struct net_device *ndev);
void enetc_stop(struct net_device *ndev);
netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev);
+netdev_features_t enetc_features_check(struct sk_buff *skb,
+ struct net_device *ndev,
+ netdev_features_t features);
struct net_device_stats *enetc_get_stats(struct net_device *ndev);
void enetc_set_features(struct net_device *ndev, netdev_features_t features);
int enetc_ioctl(struct net_device *ndev, struct ifreq *rq, int cmd);
diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
index 71c971618388..bfe0eaf50975 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c
@@ -586,6 +586,7 @@ static const struct net_device_ops enetc4_ndev_ops = {
.ndo_open = enetc_open,
.ndo_stop = enetc_close,
.ndo_start_xmit = enetc_xmit,
+ .ndo_features_check = enetc_features_check,
.ndo_get_stats = enetc_get_stats,
.ndo_set_mac_address = enetc_pf_set_mac_addr,
.ndo_set_rx_mode_async = enetc4_pf_set_rx_mode,
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_pf.c b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
index d77a07cece28..86ca88196a4b 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_pf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_pf.c
@@ -483,6 +483,7 @@ static const struct net_device_ops enetc_ndev_ops = {
.ndo_open = enetc_open,
.ndo_stop = enetc_close,
.ndo_start_xmit = enetc_xmit,
+ .ndo_features_check = enetc_features_check,
.ndo_get_stats = enetc_get_stats,
.ndo_set_mac_address = enetc_pf_set_mac_addr,
.ndo_set_rx_mode = enetc_pf_set_rx_mode,
diff --git a/drivers/net/ethernet/freescale/enetc/enetc_vf.c b/drivers/net/ethernet/freescale/enetc/enetc_vf.c
index f70b6d4290f2..223f974727bc 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc_vf.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc_vf.c
@@ -440,6 +440,7 @@ static const struct net_device_ops enetc_ndev_ops = {
.ndo_open = enetc_open,
.ndo_stop = enetc_close,
.ndo_start_xmit = enetc_xmit,
+ .ndo_features_check = enetc_features_check,
.ndo_get_stats = enetc_get_stats,
.ndo_set_mac_address = enetc_vf_set_mac_addr,
.ndo_set_features = enetc_vf_set_features,
@@ -453,6 +454,7 @@ static const struct net_device_ops enetc4_ndev_ops = {
.ndo_open = enetc_open,
.ndo_stop = enetc_close,
.ndo_start_xmit = enetc_xmit,
+ .ndo_features_check = enetc_features_check,
.ndo_get_stats = enetc_get_stats,
.ndo_set_mac_address = enetc_vf_set_mac_addr,
.ndo_set_features = enetc_vf_set_features,
--
2.53.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 net 2/4] net: enetc: reserve VLAN extension BDs for software TSO
2026-11-18 23:50 [PATCH v2 net 0/4] ENETC GSO fixes Vladimir Oltean
2026-11-18 23:50 ` [PATCH v2 net 1/4] net: enetc: let core segment GSO skb when TSO would not fit the TX ring Vladimir Oltean
@ 2026-11-18 23:50 ` Vladimir Oltean
2026-11-18 23:50 ` [PATCH v2 net 3/4] net: enetc: fall back to software TX csum for too long L3 headers Vladimir Oltean
2026-11-18 23:50 ` [PATCH v2 net 4/4] net: enetc: let core segment GSO skb when headers exceed TSO_HEADER_SIZE Vladimir Oltean
3 siblings, 0 replies; 7+ messages in thread
From: Vladimir Oltean @ 2026-11-18 23:50 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Claudiu Manoil, Wei Fang, Clark Wang, Ioana Ciornei,
Willem de Bruijn, imx, linux-kernel
enetc_start_xmit() uses tso_count_descs() to check whether the TX ring
has enough free BDs for a software TSO frame. That estimates one header
BD and one data BD per segment, plus one BD per frag. However, when the
skb carries a VLAN tag, enetc_map_tx_tso_hdr() also adds an extension
BD to every segment, which is not accounted for.
With a highly segmented VLAN TSO skb and a nearly full ring, the driver
can then write past next_to_clean and overwrite BDs still owned by the
hardware.
Add enetc_tso_count_descs() which accounts for the extension BD of each
segment when VLAN insertion is needed.
Fixes: fb8629e2cbfc ("net: enetc: add support for software TSO")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
This comes from the previous patch set:
https://lore.kernel.org/netdev/20261021145314.1435049-2-vladimir.oltean@nxp.com/
v1->v2: none
old v5->v1: also patch enetc_features_check()
old v4->old v5: patch is new
---
drivers/net/ethernet/freescale/enetc/enetc.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 1606ac57016f..7f089a84d9a6 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -674,6 +674,17 @@ static void enetc_tso_complete_csum(struct enetc_bdr *tx_ring, struct tso_t *tso
}
}
+static int enetc_tso_count_descs(const struct sk_buff *skb)
+{
+ int count = tso_count_descs(skb);
+
+ /* Each segment also needs an extension BD for VLAN insertion */
+ if (skb_vlan_tag_present(skb))
+ count += skb_shinfo(skb)->gso_segs;
+
+ return count;
+}
+
static int enetc_lso_count_descs(const struct sk_buff *skb)
{
/* 4 BDs: 1 BD for LSO header + 1 BD for extended BD + 1 BD
@@ -1034,7 +1045,7 @@ static netdev_tx_t enetc_start_xmit(struct sk_buff *skb,
count = enetc_lso_hw_offload(tx_ring, skb);
} else {
- if (enetc_bd_unused(tx_ring) < tso_count_descs(skb)) {
+ if (enetc_bd_unused(tx_ring) < enetc_tso_count_descs(skb)) {
netif_stop_subqueue(ndev, tx_ring->index);
return NETDEV_TX_BUSY;
}
@@ -1114,7 +1125,7 @@ netdev_features_t enetc_features_check(struct sk_buff *skb,
if (!skb_is_gso(skb) || enetc_skb_uses_lso(priv, skb))
return features;
- if (tso_count_descs(skb) >= priv->tx_bd_count)
+ if (enetc_tso_count_descs(skb) >= priv->tx_bd_count)
features &= ~NETIF_F_GSO_MASK;
return features;
--
2.53.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 net 3/4] net: enetc: fall back to software TX csum for too long L3 headers
2026-11-18 23:50 [PATCH v2 net 0/4] ENETC GSO fixes Vladimir Oltean
2026-11-18 23:50 ` [PATCH v2 net 1/4] net: enetc: let core segment GSO skb when TSO would not fit the TX ring Vladimir Oltean
2026-11-18 23:50 ` [PATCH v2 net 2/4] net: enetc: reserve VLAN extension BDs for software TSO Vladimir Oltean
@ 2026-11-18 23:50 ` Vladimir Oltean
2026-11-18 23:50 ` [PATCH v2 net 4/4] net: enetc: let core segment GSO skb when headers exceed TSO_HEADER_SIZE Vladimir Oltean
3 siblings, 0 replies; 7+ messages in thread
From: Vladimir Oltean @ 2026-11-18 23:50 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Claudiu Manoil, Wei Fang, Clark Wang, Ioana Ciornei,
Willem de Bruijn, imx, linux-kernel
For L4 checksum offload, enetc_map_tx_buffs() programs the following TX
BD fields: ENETC_TX_BD_L3_START <- skb_network_offset(skb) and
ENETC_TX_BD_L3_HDR_LEN <- skb_network_header_len(skb) / 4.
These fields are passed this way so that the hardware simultaneously
knows the L3 header start (for computing the pseudo-header) and the L4
header start (by summing up L3_START + 4 x L3_HDR_SIZE) which is the
csum_start.
Section 106.3.5.1.2.1.3.5 Transmit Checksum Offload of the i.MX95 RM
has this statement:
BD[L3_START] + (BD[L3_HDR_SIZE] x 4) is set to the offset within the
packet to begin checksumming. (BD[L3_START] + (BD[L3_HDR_SIZE] x 4) +
any hardware inserted tags) must be smaller than 127 bytes.
We have no test for this condition, and with IPv6 extension headers it
is possible for that sum to actually exceed 127 bytes. For example, when
using the Segment Routing Header, 4 Segment Identifiers (SIDs) will
produce an L4 header offset of 126 bytes (OK), while 5 SIDs will produce
an L4 offset of 142 bytes (not OK).
The hardware picks up these packets from the TX ring, identifies the
incorrect header length, refuses to send them, updates the TX BD
writeback with the STATUS field set to 1, meaning:
Programming error
An error exists in either the Tx BD, the Tx ring registers, or some
combination of these which meant that this frame could not be
transmitted.
releases the buffer and updates tx_ring->stats.packets and
tx_ring->stats.bytes as if the packets were sent (but no MAC counter
updates).
This error can only be seen through manual code instrumentation, since
the driver only checks the writeback when it sets tx_swbd->check_wb, and
it does that for taprio offload and for 2-step TX timestamping.
Issue found while investigating Sashiko's question "Can a 256-byte
header still break the hardware LSO path because lso->hdr_len is a u8?":
https://lore.kernel.org/imx/sashiko-outbox-211955@kernel.org/
and was reproduced using:
https://gist.github.com/vladimiroltean/7cecf636b788b29f361a2fbdae646010
Turns out, LSO breaks sooner than the assumed 256 byte limit, because of
the checksum offload feature it depends on.
LS1028A also declares the NETIF_F_HW_CSUM feature in order for GSO to be
passed to the driver for software segmentation, but performs the
checksum in software - either through csum_partial()/csum_block_add()
for GSO, or through skb_checksum_help() for non-GSO. Point being, it
does not use the HW offload engine, does not have the limitation, and is
the reason why we need to discern using the ENETC_F_TXCSUM bit from
priv->active_offloads instead.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v1->v2: patch is new
---
drivers/net/ethernet/freescale/enetc/enetc.c | 16 ++++++++++++++++
drivers/net/ethernet/freescale/enetc/enetc.h | 1 +
2 files changed, 17 insertions(+)
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c
index 7f089a84d9a6..6cc519eea5bd 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.c
+++ b/drivers/net/ethernet/freescale/enetc/enetc.c
@@ -1114,6 +1114,16 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev)
}
EXPORT_SYMBOL_GPL(enetc_xmit);
+static bool enetc_skb_l4_too_deep(const struct sk_buff *skb)
+{
+ unsigned int l4_offset = skb_checksum_start_offset(skb);
+
+ if (skb_vlan_tag_present(skb))
+ l4_offset += VLAN_HLEN;
+
+ return l4_offset >= ENETC_TX_CSUM_MAX_L4_OFFSET;
+}
+
netdev_features_t enetc_features_check(struct sk_buff *skb,
struct net_device *ndev,
netdev_features_t features)
@@ -1122,6 +1132,12 @@ netdev_features_t enetc_features_check(struct sk_buff *skb,
features = vlan_features_check(skb, features);
+ if (priv->active_offloads & ENETC_F_TXCSUM &&
+ skb->ip_summed == CHECKSUM_PARTIAL && enetc_skb_l4_too_deep(skb)) {
+ features &= ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
+ return features;
+ }
+
if (!skb_is_gso(skb) || enetc_skb_uses_lso(priv, skb))
return features;
diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h
index 1e3290d1a388..5b8cffd589c7 100644
--- a/drivers/net/ethernet/freescale/enetc/enetc.h
+++ b/drivers/net/ethernet/freescale/enetc/enetc.h
@@ -75,6 +75,7 @@ struct enetc_lso_t {
int total_len; /* total data length, not include LSO header */
};
+#define ENETC_TX_CSUM_MAX_L4_OFFSET 127
#define ENETC_LSO_MAX_DATA_LEN SZ_256K
#define ENETC_RX_MAXFRM_SIZE ENETC_MAC_MAXFRM_SIZE
--
2.53.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 net 4/4] net: enetc: let core segment GSO skb when headers exceed TSO_HEADER_SIZE
2026-11-18 23:50 [PATCH v2 net 0/4] ENETC GSO fixes Vladimir Oltean
` (2 preceding siblings ...)
2026-11-18 23:50 ` [PATCH v2 net 3/4] net: enetc: fall back to software TX csum for too long L3 headers Vladimir Oltean
@ 2026-11-18 23:50 ` Vladimir Oltean
2026-11-19 0:03 ` Eric Dumazet
3 siblings, 1 reply; 7+ messages in thread
From: Vladimir Oltean @ 2026-11-18 23:50 UTC (permalink / raw)
To: netdev
Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Claudiu Manoil, Wei Fang, Clark Wang, Ioana Ciornei,
Willem de Bruijn, imx, linux-kernel
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@kernel.org/
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@nxp.com>
---
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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 net 4/4] net: enetc: let core segment GSO skb when headers exceed TSO_HEADER_SIZE
2026-11-18 23:50 ` [PATCH v2 net 4/4] net: enetc: let core segment GSO skb when headers exceed TSO_HEADER_SIZE Vladimir Oltean
@ 2026-11-19 0:03 ` Eric Dumazet
2026-11-19 8:44 ` Vladimir Oltean
0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2026-11-19 0:03 UTC (permalink / raw)
To: Vladimir Oltean
Cc: netdev, Andrew Lunn, David S . Miller, Jakub Kicinski,
Paolo Abeni, Claudiu Manoil, Wei Fang, Clark Wang, Ioana Ciornei,
Willem de Bruijn, imx, linux-kernel
Le jeu. 19 nov. 2026 à 00:51, Vladimir Oltean
<vladimir.oltean@nxp.com> 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@kernel.org/
> 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@nxp.com>
> ---
> 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@google.com/
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 net 4/4] net: enetc: let core segment GSO skb when headers exceed TSO_HEADER_SIZE
2026-11-19 0:03 ` Eric Dumazet
@ 2026-11-19 8:44 ` Vladimir Oltean
0 siblings, 0 replies; 7+ messages in thread
From: Vladimir Oltean @ 2026-11-19 8:44 UTC (permalink / raw)
To: Eric Dumazet
Cc: netdev, Andrew Lunn, David S . Miller, Jakub Kicinski,
Paolo Abeni, Claudiu Manoil, Wei Fang, Clark Wang, Ioana Ciornei,
Willem de Bruijn, imx, linux-kernel
Hi Eric,
On Thu, Nov 19, 2026 at 01:03:16AM +0100, Eric Dumazet wrote:
> > 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.
>
> I should probably rework my series :
> https://lore.kernel.org/netdev/20260403043237.3909226-1-edumazet@google.com/
Do you disagree with my analysis that only enetc risks corruption? I mean,
for a second layer of defense, having tso_features_check() everywhere
TSO_HEADER_SIZE is used probably makes sense, but I opted for a targeted
fix because I couldn't justify it for the other drivers.
^ permalink raw reply [flat|nested] 7+ messages in thread