There are two distinct problems, solved with the same skb_linearize_cow() call. First, enetc_ptp_parse() uses ptp_parse_header(), which does not handle fragmented headers, and expects the entire area between skb_mac_header() and the end of the PTP header to be linear. When the driver fails to parse a fragmented PTP frame to find the offsets to the originTimestamp and correctionField, it falls back to two-step timestamping, which is technically not what user space asked for, and it may not be prepared to receive the timestamped packet through the socket error queue. The problem can be avoided relatively easily by linearizing packets with one-step timestamping requests prior to calling enetc_ptp_parse(). These are infrequent enough that this should not be a performance problem. The second problem is that later in the TX path of these packets, enetc_update_ptp_sync_msg() modifies them by writing to the originTimestamp field of the PTP header. This is not safe from drivers because they may not hold the only copy of the packet, unless something along the lines of skb_unshare() is used. Actually skb_linearize_cow() kills both birds with one stone, as it ensures the skb is linear and writable. Note that modifying ptp_parse_header() to tolerate nonlinear skbs was considered, but it wouldn't have saved us of the need to make it writable, so this is the simpler solution. Fixes: 7294380c5211 ("enetc: support PTP Sync packet one-step timestamping") Link: https://sashiko.dev/#/patchset/20260401172246.1075883-1-vladimir.oltean%40nxp.com Signed-off-by: Vladimir Oltean --- v2->v3: - replace skb_linearize() with skb_linearize_cow(), - improve justification v1->v2: - patch is new --- drivers/net/ethernet/freescale/enetc/enetc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 8a9ba168eab1..62cdcaab3f3f 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1099,6 +1099,11 @@ netdev_tx_t enetc_xmit(struct sk_buff *skb, struct net_device *ndev) /* Fall back to two-step timestamp if not one-step Sync packet */ if (enetc_cb->flag & ENETC_F_TX_ONESTEP_SYNC_TSTAMP) { + if (unlikely(skb_linearize(skb))) { + dev_kfree_skb_any(skb); + return NETDEV_TX_OK; + } + if (enetc_ptp_parse(skb, &udp, &msgtype, &twostep, &offset1, &offset2) || msgtype != PTP_MSGTYPE_SYNC || twostep != 0) { -- 2.43.0