From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796406953; b=Qdlp8X0Droc6BVEKIGUG0uFwE5dvDIyJt6v9QHkzlkbSd5I9O3OHRZFHL4yXaUOLDMrT /6XMSolLb5RbPpplFELqPsnyKQzwnUQSNl6W83YVqIgU6YathCZcOpPMBAO5qKKVmElfR VePOjUA2lf2A4Ol0rWM5Ri6n4kmoE25HHNhvyB6iiJkpMjyZSFqXNyV0/1t5lXPZsKCDm UMHc+RLkC9OGE8ma+8ksyUM//mpMtbXOQy6RreOfCXuJecHyn05dQGuC+iNiHdKgtRk0w 3JSvVeeemYcSwrICgTPCiJ+tnnXpu8xR8DNc5IExnwgAENpFXg1IJD1ST8E+rrfo04A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796406953; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=3mXFaIm+cgkr7tFDwwjF1DKzl/SDxtrL5ZdigExFgv4=; b=w6Obe3QuBaRbOrAOLqMrNDY4Fge7+3BMmgEj77r4TVoArPMCDtyUCLOohRpLUZ8v7FMY GDWK2+HT1eiKKz4Xnp41V7ztq0ngmm8mN/zVUwq1t4Btw5cupiSPmY1CN5YGeg2VMEZPo niOHBVVminCBLc/hsibLW+DhrfiQjO2iFN9dGqtS+BhXLi62RTLSQLockjnKIHMxbtXRI FLeXVPhtGTHwCVJ3yB1jjmH3S1YaCpgU+Minl7K+FUYDREQF/j4w5Efh1TxTan09YQxyp OoRTk9U2YRQaY853zoamrYLIrihXNu1rcnHGIN7Xh49n+/tvLCtuzazrfSuLWGt/DJw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CYB69brN; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDCD7606A322 for ; Fri, 4 Dec 2026 17:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=CYB69brN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A3581F00A07; Fri, 4 Dec 2026 17:55:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796406953; bh=3mXFaIm+cgkr7tFDwwjF1DKzl/SDxtrL5ZdigExFgv4=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=CYB69brNEz4Wbh5SrMYvXOTezYHlBuID5S0RD3tvyRM9pzdNQE68P9dPO5TR2XPSA wT1UYlihvlpmhCudoCbwlpuTSPRp4quqHP1h3JWDfQM1ldpDK73sXYLzt1VZjpgr4W dd4rTlZg3ZXY/7GrVRwdhFqvrVRgzRjWXSg8cI7qc5cCtaC2sIioX8/Z7sUNz55Rpa YpscGd7x0VFHvJppadLnsxU+8RwaR7Q2OVJEbQbK0cfTJMYeIkal8mcG25Njb3W7WJ r2iniSse9kjXASjYZNdtLmp+4naLDM7bf68RN9A/ABHf1yzb7Mn4GSsFVnLFx+/xyB DosN7fDpVA3+g== Subject: Re: [PATCH net-next v14 3/8] hsr: Add a magic header for sending PTP packets 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 Date: Fri, 04 Dec 2026 17:55:51 +0000 Message-ID: <179640695177.3146.2663103305771169996@kernel.org> In-Reply-To: <20261203-hsr_ptp-v14-3-1511ffd4c362@linutronix.de> References: <20261203-hsr_ptp-v14-3-1511ffd4c362@linutronix.de> X-sashiko-severity: Medium Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 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