Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: bigeasy@linutronix.de
Cc: netdev@vger.kernel.org, j-rameshbabu@ti.com,
	andrew+netdev@lunn.ch, danishanwar@ti.com, d-qiu@ti.com,
	davem@davemloft.net, fmaurer@redhat.com, kuba@kernel.org,
	neelima@ti.com, pabeni@redhat.com, praneeth@ti.com,
	pratheesh@ti.com, richardcochran@gmail.com, horms@kernel.org,
	vigneshr@ti.com, willemdebruijn.kernel@gmail.com,
	daniel.machon@microchip.com, edumazet@kernel.org
Subject: Re: [PATCH net-next v14 3/8] hsr: Add a magic header for sending PTP packets
Date: Fri, 04 Dec 2026 17:55:51 +0000	[thread overview]
Message-ID: <179640695177.3146.2663103305771169996@kernel.org> (raw)
In-Reply-To: <20261203-hsr_ptp-v14-3-1511ffd4c362@linutronix.de>

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

Critical: 0 · High: 0 · Medium: 3 · 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).

- [Medium] The new UAPI struct hsr_inline_header
  (include/uapi/linux/hsr_ptp.h) is only partly validated, and nothing…
- [Medium] hsr: hsr_ptp_parse_header() breaks transport_header and
  csum/GSO invariants
- [Medium] hsr: missing checksum update on skb_pull() in
  hsr_ptp_parse_header()

--

hsr: Add a magic header for sending PTP packets

This commit adds a UAPI struct hsr_inline_header. It must be prepended to
ETH_P_1588 frames sent through the HSR master device.
hsr_ptp_parse_header() checks the magic and pad fields, extracts the
requested tx port and the has_hsr_header flag, and strips the inline
header before passing both values to hsr_forward_skb().

> diff --git a/include/uapi/linux/hsr_ptp.h b/include/uapi/linux/hsr_ptp.h
> new file mode 100644
> index 0000000000000..95e905441ebdc
> --- /dev/null
> +++ b/include/uapi/linux/hsr_ptp.h

[ ... ]

> +#define HSR_INLINE_HDR  0xaf485352
> +#define HSR_INLINE_HDR_PORT_A	1
> +#define HSR_INLINE_HDR_PORT_B	2
> +
> +struct hsr_inline_header {
> +	__u8 req_tx_port;
> +	__u8 has_hsr_header;
> +	__be32 __pad0;
> +	__be32 magic;
> +	__be16 __pad1;
> +	__be16 eth_type;
> +} __attribute__ ((packed));

[ ... ]

> diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
> index 59df647d2fd45..252646e80f724 100644
> --- a/net/hsr/hsr_device.c
> +++ b/net/hsr/hsr_device.c

[ ... ]

> @@ -221,26 +223,83 @@ static netdev_features_t hsr_fix_features(struct net_device *dev,
>  	return hsr_features_recompute(hsr, features);
>  }
>  
> +static int hsr_ptp_parse_header(struct sk_buff *skb, bool *has_hsr_header,
> +				enum hsr_port_type *req_tx_port)
> +{

[ ... ]

> +	hsr_inline_hdr = (struct hsr_inline_header *)skb_mac_header(skb);
> +	if (hsr_inline_hdr->magic != htonl(HSR_INLINE_HDR))
> +		return -EINVAL;
> +
> +	*has_hsr_header = !!hsr_inline_hdr->has_hsr_header;
> +	*req_tx_port = hsr_inline_hdr->req_tx_port;
> +	if (*req_tx_port != HSR_PT_SLAVE_A && *req_tx_port != HSR_PT_SLAVE_B)
> +		return -EINVAL;
> +
> +	if (hsr_inline_hdr->__pad0 != 0 || hsr_inline_hdr->__pad1 != 0)
> +		return -EINVAL;
> +
> +	hdr_len = ETH_HLEN;
> +	if (*has_hsr_header)
> +		hdr_len += HSR_HLEN;
> +
> +	/* Ensure the real header after the stripped one can be
> +	 * accessed
> +	 */
> +	if (!pskb_may_pull(skb, sizeof(struct hsr_inline_header) +
> +			   hdr_len))
> +		return -EINVAL;
> +
> +	eth_hdr = skb_pull(skb, sizeof(struct hsr_inline_header));
> +	skb_set_network_header(skb, hdr_len);
> +	skb->protocol = eth_hdr->h_proto;
> +	return 0;
> +}

[Severity: Medium]
The inline header is stripped with a plain skb_pull(), so the checksum
state of the skb is not adjusted. Suppose the skb is CHECKSUM_PARTIAL
and csum_start lies inside the 14 bytes being removed. Then
skb_checksum_start_offset() goes negative while ip_summed stays
CHECKSUM_PARTIAL.

virtio_net_hdr_to_skb() requires a csum_start of at least 20. However,
a tc egress action on the HSR master runs before hsr_dev_xmit() and can
shrink the offset further. For example, TCA_VLAN_ACT_POP_ETH calls
skb_eth_pop(), which uses skb_pull_rcsum(). That leaves an offset of 6
with CHECKSUM_PARTIAL intact. NETIF_F_HW_CSUM is set on the HSR master,
so validate_xmit_skb() does not resolve the checksum there. The pull
here then leaves an offset of -8.

Now the frame reaches a slave without checksum offload.
skb_checksum_help() compares the negative offset as unsigned against
skb_headlen(), dumps the skb and hits WARN_ONCE(). With panic_on_warn
that is a panic. A slave with NETIF_F_HW_CSUM instead gets the bogus
start offset passed straight into its driver.

Would skb_pull_rcsum() be enough here? For CHECKSUM_PARTIAL it only
downgrades the skb to CHECKSUM_NONE when the start offset goes
negative. On transmit that means nobody fills in the checksum. Should
hsr_ptp_parse_header() instead refuse CHECKSUM_PARTIAL skbs outright?

[Severity: Medium]
hsr_dev_setup() advertises NETIF_F_GSO_MASK and NETIF_F_HW_CSUM on the
HSR master, and hsr_features_recompute() keeps them. As a result,
validate_xmit_skb() passes CHECKSUM_PARTIAL and SKB_GSO_DODGY skbs to
hsr_dev_xmit() untouched. An AF_PACKET sender using PACKET_VNET_HDR can
set csum_start to 20, and skb_partial_csum_set() puts transport_header
at the same spot.

After the inline header is pulled here, network_header moves to 14 (or
20 with has_hsr_header) bytes past the new data pointer. Meanwhile
transport_header and csum_start stay where they were, so they now sit
8 or 14 bytes before network_header. Nothing rejects the offload state
or resets transport_header.

In that case skb_network_header_len() and skb_gso_network_seglen()
wrap to roughly 4 GiB, because both are unsigned. A later patch in this
series sends has_hsr_header frames straight to the slave with
dev_queue_xmit(). From then on, drivers such as enetc, mvneta and ena
program skb_network_header_len() into their TX descriptors for
CHECKSUM_PARTIAL frames. A tc egress program on the slave that uses
bpf_skb_check_mtu() with BPF_MTU_CHK_SEGS also sees the wrapped GSO
length.

PACKET_VNET_HDR is not needed to get a bad transport_header.
packet_parse_headers() probes the transport header of the ETH_P_1588
frame, so transport_header is already 14 bytes stale after the pull.

Is there any reason a PTP frame sent this way should carry checksum or
GSO offload state? If not, could hsr_ptp_parse_header() reject
skb->ip_summed == CHECKSUM_PARTIAL and skb_is_gso(skb), and reset
transport_header after the pull?

[Severity: Medium]
This patch makes struct hsr_inline_header part of the UAPI. Should
hsr_ptp_parse_header() be stricter about the values it accepts?

The pad fields are rejected when they are non-zero, but has_hsr_header
is read as:

    *has_hsr_header = !!hsr_inline_hdr->has_hsr_header;

so any value from 1 to 255 means "has header". Could values above 1 be
rejected, so this byte can still carry flags later?

The eth_type field is never checked either. hsr_dev_xmit() decides
whether to parse the inline header from skb->protocol alone:

    if (skb->protocol == htons(ETH_P_1588) &&
        hsr_ptp_parse_header(skb, &has_hsr_header, &req_tx_port))

af_packet fills skb->protocol from offset 12 via
hsr_header_ops.parse_protocol only when the sender gave protocol 0 or
ETH_P_ALL. packet_snd() and tpacket_fill_skb() skip the assignment for
ETH_P_ALL.

So if sll_protocol is ETH_P_1588, the inline header is accepted no
matter what eth_type contains. If a different concrete protocol is
given, a well-formed inline header is sent on the wire unchanged as
the Ethernet header.

Should hsr_ptp_parse_header() also check that
hsr_inline_hdr->eth_type == htons(ETH_P_1588)?

What happens when has_hsr_header is set on a PRP_V1 device, or on an
HSR device when the inner frame is not ETH_P_HSR (or ETH_P_PRP for
HSRv0)?

PRP carries its redundancy information in an RCT trailer, not a
header, yet hdr_len becomes ETH_HLEN + HSR_HLEN. That gives
skb_set_network_header(skb, 20), and skb_reset_mac_len() in
hsr_dev_xmit() then sets mac_len to 20 for a plain 14 byte Ethernet
frame. Should has_hsr_header be checked against hsr->prot_version and
the inner h_proto?

This matters more later in the series. After "hsr: Use the port and
header information in hsr_forward_skb()", has_hsr_header=1 skips
hsr_get_node(), sequence numbering and tagging. hsr_forward_do() then
sends a clone of skb_std as is:

    if (frame->has_hsr_header && frame->skb_std) {
        skb = skb_clone(frame->skb_std, GFP_ATOMIC);
        ...
        goto inject_into_stack;
    }

so the flag is trusted without any check that the frame really carries
an HSR tag. hsr_ptp_parse_header() and hsr_ptp.h are unchanged at the
end of the series.

The new UAPI header also has no comments, and nothing under
Documentation/ describes the format. That includes the magic value,
the port encoding, the PRP behaviour, and the rule that the header is
mandatory for ETH_P_1588 frames sent through the HSR master. Could
this be documented, in hsr_ptp.h or under Documentation/?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-hsr_ptp-v14-0-1511ffd4c362%40linutronix.de

  reply	other threads:[~2026-12-04 17:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 17:44 [PATCH net-next v14 0/8] hsr: Allow to send packets on specific port and pass the timestamp Sebastian Andrzej Siewior
2026-12-03 17:44 ` [PATCH net-next v14 1/8] hsr: Add header_ops::parse_protocol Sebastian Andrzej Siewior
2026-12-03 17:44 ` [PATCH net-next v14 2/8] hsr: Use skb_clone() while adding the HSR header Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko
2026-12-03 17:44 ` [PATCH net-next v14 3/8] hsr: Add a magic header for sending PTP packets Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko [this message]
2026-12-03 17:44 ` [PATCH net-next v14 4/8] hsr: Drop received " Sebastian Andrzej Siewior
2026-12-03 17:44 ` [PATCH net-next v14 5/8] hsr: Use the port and header information in hsr_forward_skb() Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko
2026-12-03 17:44 ` [PATCH net-next v14 6/8] hsr: Assign a socket for cloned skbs Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko
2026-12-03 17:44 ` [PATCH net-next v14 7/8] hsr: Move struct hsr_ethhdr to a global header Sebastian Andrzej Siewior
2026-12-03 17:44 ` [PATCH net-next v14 8/8] selftests: hsr: Add test for the inline PTP header on HSR Sebastian Andrzej Siewior
2026-12-04 17:55   ` netdev-bot+sashiko

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=179640695177.3146.2663103305771169996@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=bigeasy@linutronix.de \
    --cc=d-qiu@ti.com \
    --cc=daniel.machon@microchip.com \
    --cc=danishanwar@ti.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fmaurer@redhat.com \
    --cc=horms@kernel.org \
    --cc=j-rameshbabu@ti.com \
    --cc=kuba@kernel.org \
    --cc=neelima@ti.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=praneeth@ti.com \
    --cc=pratheesh@ti.com \
    --cc=richardcochran@gmail.com \
    --cc=vigneshr@ti.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /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