net: hsr: PRP RedBox (PRP-SAN) support
Subsystems (4)
v4 cover net: hsr: PRP RedBox (PRP-SAN) support
This series adds PRP RedBox support to the hsr driver: a PRP node that proxies one or more SANs sitting behind an interlink port (IEC 62439-3, PRP-SAN). HSR-SAN has been supported since commit 5055cccfc2d1 ("net: hsr:
Provide RedBox support (HSR-SAN)"); this extends the equivalent capability to PRP, reusing the existing protocol-neutral proxy machinery (proxy_node_db, hsr_proxy_announce(), hsr_prune_proxy_nodes()).
A SAN behind the interlink does bidirectional unicast with peers on the PRP network, its source MAC is preserved on the wire, the PRP RCT is correct, and the RedBox announces each proxied SAN with the RedBox-MAC TLV (Type 30) in its supervision frames.
The series is bisect-safe: the datapath, duplicate discard and supervision support are added first; the rtnetlink rejection of "type hsr ... interlink <dev> proto 1" is removed only in patch 3, once the feature is complete.
Design notes:
- prp_drop_frame() does not walk the node tables. The destination classification (PRP-network node vs proxied SAN) is resolved once per frame in fill_frame_info() and cached in struct hsr_frame_info, so the per egress-port drop decision is O(1) in the softIRQ path. The classification is gated on PRP RedBox devices (prot_version == PRP_V1 && hsr->redbox), so HSR RedBox traffic is not affected.
- The LAN A/B duplicate test is factored into prp_is_lan_dup() so the new PRP interlink rules in prp_drop_frame() do not change hsr_drop_frame() behaviour, including the NETIF_F_HW_HSR_FWD path. This is software PRP RedBox only; it adds no new hardware-offload contract.
- The supervision emitter uses pre-reserved tailroom (hsr_init_skb() + skb_put()) on the existing GFP_ATOMIC path; no skb_linearize() or pskb_expand_head(). The RedBox-MAC TLV is followed by an explicit EOT (Type 0, Length 0); padding via skb_put_padto(ETH_ZLEN) and the 6-byte PRP RCT remain at the absolute tail of the egress frame.
- The hsr_get_node() hsr_ethhdr length guard is relaxed only for PRP supervision frames (prot_version == PRP_V1 && ETH_P_PRP && is_sup), which are untagged with mac_len == ETH_HLEN. HSR (ETH_P_HSR) supervision is front-tagged and keeps the original length requirement, so HSR malformed-frame filtering is unchanged.
Testing (on a net-next v7.2-rc2 kernel built from this base, x86-64):
- checkpatch.pl --strict: patches 1-3 clean; patch 4 reports only the expected "added file(s), does MAINTAINERS need updating?" note, which is ignorable here -- MAINTAINERS already lists tools/testing/selftests/net/hsr/ under HSR NETWORK PROTOCOL.
- git diff --check clean; the series git-am's onto the base commit.
- tools/testing/selftests/net/hsr/hsr_prp_redbox.sh: PASS on the patched kernel (bidirectional unicast, SAN MAC preservation, RedBox-MAC TLV + EOT in the proxy-announce).
- HSR regression on the same kernel: hsr_redbox.sh (HSR-SAN/RedBox), hsr_ping.sh and prp_ping.sh all PASS, confirming the PRP changes do not regress the existing HSR/PRP paths.
- netns checks: peer<->SAN 0% loss with no duplicates and a valid PRP RCT on the wire; a silent SAN is pruned from the announce; zero driver WARN/BUG/Oops/RCU-stall during the run.
Beyond the in-tree selftest, this exact series (applied to this base and running as the net-next kernel on x86-64 hardware) was also validated with an out-of-tree IEC 62439-3 conformance harness (supervision TLV chain, duplicate discard, cross-LAN rejection, seqnr rollover, VLAN/multicast/GOOSE frame types with the RCT verified at the absolute frame tail), and interoperability-tested against a commercial PRP RedBox (Siemens SCALANCE X204RNA) over 100 Mbit/s Fast Ethernet with NIC hardware (PTP) timestamping: a mid-stream single-LAN outage of ~2 s at 10 kpps was bridged with zero lost and zero duplicate frames (seamless PRP failover), and the duplicate-discard window held zero lost / zero duplicates under netem asymmetric delay up to 100 ms (~1000 sequence numbers in flight), 25% reorder, and 5% single-LAN loss. The failover and impairment matrix was additionally repeated on a KASAN + lockdep + kmemleak instrumented build of this kernel, including a 72-carrier-event link flap-storm with deliberate double-LAN cuts: zero KASAN, lockdep, or kmemleak findings. This out-of-tree testing is supplementary and not required to evaluate the series.
v4:
- pass rx (enum hsr_port_type) to prp_is_lan_dup() instead of the frame (Fernando Fernandez Mancera)
- restore the original macaddress_redbox indentation (Fernando Fernandez Mancera)
v3: https://lore.kernel.org/netdev/[email protected]/
- no code changes; repost as a new thread (v2 was incorrectly posted in reply to v1)
v2: https://lore.kernel.org/netdev/[email protected]/
- publish the RedBox state before lower RX handlers can learn nodes:
fixes an initialization-ordering race where a node learned during device setup got a single-port sequence block, breaking interlink duplicate discard and letting the supervision merge read beyond the source node's allocated sequence bitmap (reported by the NIPA Sashiko review)
- harden the supervision sequence-block merge against mismatched seq_port_cnt
- align macaddress_redbox for ether_addr_copy() on strict-alignment architectures
- selftest: kill the background ping by exact PID and wrap an overlong line
v1: https://lore.kernel.org/netdev/[email protected]/
Xin Xie (4):
net: hsr: add PRP interlink (RedBox) datapath and duplicate discard
net: hsr: emit RedBox-MAC TLV in PRP RedBox supervision frames
net: hsr: allow PRP RedBox (interlink) creation
selftests: net: hsr: add PRP RedBox test
net/hsr/hsr_device.c | 44 ++++++++- net/hsr/hsr_forward.c | 46 +++++++-- net/hsr/hsr_framereg.c | 27 +++-- net/hsr/hsr_framereg.h | 2 + net/hsr/hsr_main.h | 2 +- net/hsr/hsr_netlink.c | 8 +- tools/testing/selftests/net/hsr/Makefile | 1 + .../selftests/net/hsr/hsr_prp_redbox.sh | 99 +++++++++++++++++++ 8 files changed, 204 insertions(+), 25 deletions(-) create mode 100755 tools/testing/selftests/net/hsr/hsr_prp_redbox.sh
base-commit: f6f3b36c15ed44de1fbb44e645e4fae8c4a4453e --
2.53.0
PATCH v4 1/4 net: hsr: add PRP interlink (RedBox) datapath and duplicate discard
A PRP RedBox proxies SANs that sit behind an interlink port: their frames must reach the PRP network with the SAN source MAC preserved, and PRP unicast must be steered between the LAN and the SAN segment correctly.
Add the PRP interlink forwarding rules to prp_drop_frame() and give RedBox nodes a second duplicate-discard slot so the two LAN copies of a frame destined to a SAN collapse to a single delivery out the interlink.
The destination classification (is the unicast DA a PRP-network node or a proxied SAN) is resolved once per frame in fill_frame_info(), gated to PRP RedBox devices, and cached in struct hsr_frame_info, so prp_drop_frame() stays O(1) and does not walk the node tables for every candidate egress port in the softIRQ path. HSR RedBox frame classification is untouched.
Factor the LAN A/B duplicate test into prp_is_lan_dup() so the new PRP interlink rules do not change hsr_drop_frame() behaviour, including the NETIF_F_HW_HSR_FWD path which keeps using the LAN-duplicate test only.
Publish the RedBox state before the first hsr_add_port(): the slave and interlink rx handlers are live from hsr_add_port() on and rtnl does not stop softirq processing, so a frame could otherwise be handled while hsr->redbox is still false. hsr_add_node() sizes each node's per-port sequence state from hsr->redbox; a node learned in that window would get a single-port sequence block, breaking the interlink duplicate discard (WARN_ON_ONCE plus duplicate delivery to the SAN) and letting the supervision sequence-block merge read beyond the source node's allocated sequence bitmap. Publishing the flag before any port exists makes the per-node sizing uniform by construction. This is safe: the proxy announce timer is only armed from hsr_check_announce() once the master is running, the packet-path readers of hsr->redbox tolerate an empty proxy node database and an absent interlink port, and the prune_proxy_timer is still armed only after the interlink port has been attached successfully.
Additionally bound the supervision sequence-block merge by the smaller of the two nodes' seq_port_cnt as defense in depth against mismatched node sizes.
--- net/hsr/hsr_device.c | 11 ++++++++-- net/hsr/hsr_forward.c | 46 ++++++++++++++++++++++++++++++++++++------ net/hsr/hsr_framereg.c | 14 +++++++++---- net/hsr/hsr_framereg.h | 2 ++ 4 files changed, 61 insertions(+), 12 deletions(-)
net/hsr/hsr_device.c +9 -2
@@ -768,6 +768,15 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],/* Make sure the 1st call to netif_carrier_on() gets through */ netif_carrier_off (hsr_dev); +/* Publish the RedBox state before any port is attached: the rx +* handlers are live from hsr_add_port() on, and hsr_add_node() +* sizes each node's per-port sequence state from hsr->redbox. +*/ +if (interlink) { + hsr->redbox = true; +ether_addr_copy (hsr->macaddress_redbox, interlink->dev_addr); + } + res =hsr_add_port (hsr, hsr_dev,HSR_PT_MASTER , extack);if (res) goto err_add_master;
@@ -805,8 +814,6 @@ int hsr_dev_finalize(struct net_device *hsr_dev, struct net_device *slave[2],if (res) goto err_unregister; - hsr->redbox = true; -ether_addr_copy (hsr->macaddress_redbox, interlink->dev_addr);mod_timer (&hsr->prune_proxy_timer, jiffies +msecs_to_jiffies (PRUNE_PROXY_PERIOD )); }
net/hsr/hsr_forward.c +40 -6
72 lines not on this page · raw message
net/hsr/hsr_framereg.c +10 -4
@@ -199,7 +199,7 @@ static struct hsr_node *hsr_add_node(struct hsr_priv *hsr,spin_lock_init (&new_node->seq_out_lock);if (hsr->prot_version ==PRP_V1 ) - new_node->seq_port_cnt =1 ; + new_node->seq_port_cnt = hsr->redbox ?2 :1 ;else new_node->seq_port_cnt =HSR_PT_PORTS -1 ;
@@ -381,6 +381,7 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)struct ethhdr *ethhdr;unsigned int total_pull_size =0 ;unsigned int pull_size =0 ; +unsigned int seq_port_cnt;unsigned long idx;int i;
@@ -474,6 +475,7 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame) } } + seq_port_cnt =min (node_real->seq_port_cnt, node_curr->seq_port_cnt);xa_for_each (&node_curr->seq_blocks, idx, src_blk) {if (hsr_seq_block_is_old (src_blk))continue ;
@@ -482,7 +484,7 @@ void hsr_handle_sup_frame(struct hsr_frame_info *frame)if (!merge_blk)continue ; merge_blk->time =min (merge_blk->time, src_blk->time); -for (i =0 ; i < node_real->seq_port_cnt; i++) { +for (i =0 ; i < seq_port_cnt; i++) {bitmap_or (merge_blk->seq_nrs[i], merge_blk->seq_nrs[i], src_blk->seq_nrs[i],HSR_SEQ_BLOCK_SIZE ); }
@@ -649,9 +651,13 @@ int prp_register_frame_out(struct hsr_port *port, struct hsr_frame_info *frame)if (frame->port_rcv->type ==HSR_PT_MASTER )return 0 ; -/* for PRP we should only forward frames from the slave ports -* to the master port +/* RedBox: forward LAN frames out the interlink to a SAN, deduping the +* two LAN copies on a dedicated slot. */ +if (port->type ==HSR_PT_INTERLINK ) +return hsr_check_duplicate (frame,1 ); + +/* For PRP only slave-to-master frames are forwarded. */ if (port->type !=HSR_PT_MASTER )return 1 ;
net/hsr/hsr_framereg.h +2 -0
@@ -27,6 +27,8 @@ struct hsr_frame_info {bool is_local_dest;bool is_local_exclusive;bool is_from_san; +bool dst_in_node_db; +bool dst_in_proxy_node_db; };void hsr_del_self_node (struct hsr_priv *hsr);
Signature · 1 line
2.53.0
PATCH v4 2/4 net: hsr: emit RedBox-MAC TLV in PRP RedBox supervision frames
In reply to Xin XieA PRP RedBox must announce the SANs it proxies so peers populate their proxy node tables. The proxy-announce machinery (hsr_proxy_announce(), armed via hsr->redbox) already iterates proxy_node_db under RCU and calls send_sv_frame() once per SAN, but the PRP sender emitted neither the announced SAN MAC nor the RedBox-MAC TLV that IEC 62439-3 requires.
Extend send_prp_supervision_frame() so that, for a proxy-announce (identified by the interlink port, an O(1) test), the frame carries the proxied SAN MAC as MacAddressA followed by the RedBox-MAC TLV (Type 30) and an explicit End-of-TLV marker before padding.
hsr_get_node() must also accept the reinjected proxy-announce: a PRP supervision frame is an untagged ETH_P_PRP frame (mac_len == ETH_HLEN, the RCT is appended only on egress) sourced from macaddress_redbox, which is never learned from data. Exempt only PRP supervision frames from the hsr_ethhdr length guard; HSR (ETH_P_HSR) supervision is front-tagged and keeps the original guard, so HSR malformed-frame filtering is unchanged.
Also align macaddress_redbox so that ether_addr_copy() and ether_addr_equal() on it are safe on architectures without efficient unaligned access.
--- net/hsr/hsr_device.c | 33 ++++++++++++++++++++++++++++++--- net/hsr/hsr_framereg.c | 13 +++++++++++-- net/hsr/hsr_main.h | 2 +- 3 files changed, 42 insertions(+), 6 deletions(-)
net/hsr/hsr_device.c +30 -3
@@ -372,10 +372,21 @@ static void send_prp_supervision_frame(struct hsr_port *master, {struct hsr_priv *hsr = master->hsr;struct hsr_sup_payload *hsr_sp; +struct hsr_sup_tlv *hsr_stlv;struct hsr_sup_tag *hsr_stag;struct sk_buff *skb; +bool redbox_proxy; +int extra =0 ; + + redbox_proxy = hsr->redbox && master->type ==HSR_PT_INTERLINK ; + +/* A proxy-announce carries a RedBox-MAC TLV and an EOT marker. */ +if (redbox_proxy) + extra =sizeof (struct hsr_sup_tlv ) + +sizeof (struct hsr_sup_payload ) + +sizeof (struct hsr_sup_tlv ); - skb =hsr_init_skb (master,0 ); + skb =hsr_init_skb (master, extra);if (!skb) {netdev_warn_once (master->dev,"PRP: Could not send supervision frame\n" );return ;
@@ -393,9 +404,25 @@ static void send_prp_supervision_frame(struct hsr_port *master, hsr_stag->tlv.HSR_TLV_type =PRP_TLV_LIFE_CHECK_DD ; hsr_stag->tlv.HSR_TLV_length =sizeof (struct hsr_sup_payload ); -/* Payload: MacAddressA */ +/* Payload: MacAddressA, the announced node. */ hsr_sp =skb_put (skb,sizeof (struct hsr_sup_payload )); -ether_addr_copy (hsr_sp->macaddress_A, master->dev->dev_addr); +ether_addr_copy (hsr_sp->macaddress_A, addr); + +/* Proxy-announce: append the RedBox-MAC TLV (Type 30) and an explicit +* EOT to terminate the TLV chain before zero padding. +*/ +if (redbox_proxy) { + hsr_stlv =skb_put (skb,sizeof (struct hsr_sup_tlv )); + hsr_stlv->HSR_TLV_type =PRP_TLV_REDBOX_MAC ; + hsr_stlv->HSR_TLV_length =sizeof (struct hsr_sup_payload ); + + hsr_sp =skb_put (skb,sizeof (struct hsr_sup_payload )); +ether_addr_copy (hsr_sp->macaddress_A, hsr->macaddress_redbox); + + hsr_stlv =skb_put (skb,sizeof (struct hsr_sup_tlv )); + hsr_stlv->HSR_TLV_type =HSR_TLV_EOT ; + hsr_stlv->HSR_TLV_length =0 ; + }if (skb_put_padto (skb,ETH_ZLEN )) {spin_unlock_bh (&hsr->seqnr_lock);
net/hsr/hsr_framereg.c +11 -2
@@ -293,8 +293,17 @@ struct hsr_node *hsr_get_node(struct hsr_port *port, struct list_head *node_db,*/ if (ethhdr->h_proto ==htons (ETH_P_PRP ) || ethhdr->h_proto ==htons (ETH_P_HSR )) { -/* Check if skb contains hsr_ethhdr */ -if (skb->mac_len <sizeof (struct hsr_ethhdr )) +bool prp_sup; + +/* A PRP supervision frame is an untagged ETH_P_PRP frame +* (mac_len == ETH_HLEN); its RCT is appended only on egress. +* HSR (ETH_P_HSR) supervision is front-tagged and still must +* contain a struct hsr_ethhdr. +*/ + prp_sup = hsr->prot_version ==PRP_V1 && + ethhdr->h_proto ==htons (ETH_P_PRP ) && is_sup; + +if (!prp_sup && skb->mac_len <sizeof (struct hsr_ethhdr ))return NULL ; }else { rct =skb_get_PRP_rct (skb);
net/hsr/hsr_main.h +1 -1
@@ -211,7 +211,7 @@ struct hsr_priv {*/ bool fwd_offloaded;/* Forwarding offloaded to HW */ bool redbox;/* Device supports HSR RedBox */ -unsigned char macaddress_redbox[ETH_ALEN ]; +unsigned char macaddress_redbox[ETH_ALEN ]__aligned(sizeof(u16)) ;unsigned char sup_multicast_addr[ETH_ALEN ]__aligned(sizeof(u16)) ;/* Align to u16 boundary to avoid unaligned access * in ether_addr_equal
Signature · 1 line
2.53.0
PATCH v4 3/4 net: hsr: allow PRP RedBox (interlink) creation
In reply to Xin XieWith the PRP interlink datapath, duplicate discard and supervision support in place, a PRP device can act as a RedBox. Remove the rtnetlink rejection of "type hsr ... interlink <dev> proto 1"; the feature is implemented unconditionally by the preceding patches.
--- net/hsr/hsr_netlink.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
net/hsr/hsr_netlink.c +1 -7
@@ -121,14 +121,8 @@ static int hsr_newlink(struct net_device *dev, } } -if (proto ==HSR_PROTOCOL_PRP ) { +if (proto ==HSR_PROTOCOL_PRP ) proto_version =PRP_V1 ; -if (interlink) { -NL_SET_ERR_MSG_MOD (extack, -"Interlink only works with HSR" ); -return -EINVAL ; - } - }return hsr_dev_finalize (dev, link, interlink, multicast_spec, proto_version, extack);
Signature · 1 line
2.53.0
PATCH v4 4/4 selftests: net: hsr: add PRP RedBox test
In reply to Xin XieAdd a kselftest that builds a PRP RedBox (interlink) with a SAN behind the interlink and a peer DANP, and checks bidirectional unicast across the interlink, preservation of the SAN source MAC on the PRP network, and that the proxy-announce supervision frame carries the RedBox-MAC TLV (Type 30) terminated by an EOT marker. It reuses the hsr_common.sh / lib.sh helpers and skips cleanly on a kernel or iproute2 without PRP interlink support.
The background ping is killed by its exact PID: ip netns exec does not isolate the PID namespace, so a pattern-based pkill could hit unrelated processes on the host.
--- tools/testing/selftests/net/hsr/Makefile | 1 + .../selftests/net/hsr/hsr_prp_redbox.sh | 99 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100755 tools/testing/selftests/net/hsr/hsr_prp_redbox.sh
tools/testing/selftests/net/hsr/Makefile +1 -0
@@ -4,6 +4,7 @@ top_srcdir = ../../../../.. TEST_PROGS := \ hsr_ping.sh \ + hsr_prp_redbox.sh \ hsr_redbox.sh \ link_faults.sh \ prp_ping.sh \
tools/testing/selftests/net/hsr/hsr_prp_redbox.sh new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
2.53.0
Simon Horman
reviewerRe: [PATCH net-next v4 1/4] net: hsr: add PRP interlink (RedBox) datapath and duplicate discard
In reply to Xin XieThis is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev/#/patchset/[email protected]?part=1
---
--- Patch [1]: [PATCH net-next v4 1/4] net: hsr: add PRP interlink (RedBox) datapath and duplicate discard --- commit 56647cd99caab3cbc966d1e4d258db2aadbec967
Author: Xin Xie <[email protected]>
net: hsr: add PRP interlink (RedBox) datapath and duplicate discard
This commit adds PRP interlink forwarding rules to prp_drop_frame() and gives RedBox nodes a second duplicate-discard slot. It also publishes the RedBox state before the first hsr_add_port() to prevent sequence state sizing issues.
net/hsr/hsr_forward.c static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port, · line 441
Quoted 7 lines
net/hsr/hsr_forward.c +0
-0@@ -440,12 +440,34 @@ static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,return dev_queue_xmit (skb); }
[Severity: High]
This isn't a bug introduced by this patch, but does modifying the MAC header directly in hsr_xmit() corrupt shared packet data?
When an HSR frame is received from a slave port, it is forwarded to both the master and interlink ports. Both ports receive a cloned skb that shares the same underlying data buffer.
If we look at hsr_xmit(), the source MAC is modified directly:
net/hsr/hsr_forward.c:hsr_xmit() {
...
if (port->type == HSR_PT_INTERLINK)
ether_addr_copy(eth_hdr(skb)->h_source,
port->hsr->macaddress_redbox);
...
}At the same time, hsr_deliver_master() modifies the source MAC on its clone before delivering to the local stack via netif_rx().
Since both clones share the same buffer, does this overwrite the exact same memory and corrupt the packet data for whichever interface gets queued first?
Should the skb be unshared before making these direct modifications?
Similarly, does hsr_create_tagged_frame() have the same issue when it modifies the HSR tag path_id directly on frame->skb_hsr (the original received packet)?
Since this path is triggered by incoming frames destined for the Redbox from the network, can this reliable data corruption be reached by unprivileged remote input?
Simon Horman
reviewerRe: [PATCH net-next v4 3/4] net: hsr: allow PRP RedBox (interlink) creation
In reply to Xin XieThis is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev/#/patchset/[email protected]?part=3
---
--- Patch [3]: [PATCH net-next v4 3/4] net: hsr: allow PRP RedBox (interlink) creation --- commit bc0d779cf60ce71e2ec7abbdba515576e82afb69
Author: Xin Xie <[email protected]>
net: hsr: allow PRP RedBox (interlink) creation
With the PRP interlink datapath, duplicate discard and supervision support in place, a PRP device can act as a RedBox. Remove the rtnetlink rejection of "type hsr ... interlink <dev> proto 1"; the feature is implemented unconditionally by the preceding patches.
Quoted 7 lines
net/hsr/hsr_netlink.c +0
-0@@ -121,14 +121,8 @@ static int hsr_newlink(struct net_device *dev, } }
net/hsr/hsr_netlink.c static int hsr_newlink(struct net_device *dev, · line 131
Quoted 10 lines
net/hsr/hsr_netlink.c +1
-7-if (proto ==HSR_PROTOCOL_PRP ) { +if (proto ==HSR_PROTOCOL_PRP ) proto_version =PRP_V1 ; -if (interlink) { -NL_SET_ERR_MSG_MOD (extack, -"Interlink only works with HSR" ); -return -EINVAL ; - } - }
[Severity: Medium]
Since we are enabling interlink here, does this expose an issue with the transmit statistics in hsr_forward_skb() that was added earlier in the series?
When a frame is received on the interlink port from the SAN, or the RedBox generates a proxy supervision frame, we call hsr_forward_skb() with the interlink port.
In net/hsr/hsr_forward.c:hsr_forward_skb():
if (port->type == HSR_PT_MASTER || port->type == HSR_PT_INTERLINK) {
port->dev->stats.tx_packets++;
port->dev->stats.tx_bytes += skb->len;This appears to unconditionally increment the port's tx_packets and tx_bytes, even though the frame was received (not transmitted) or is being transmitted out of the slave ports instead of the interlink port. Will this artificially inflate the network statistics for the physical interlink device?
[Severity: Medium]
This is a pre-existing issue, but does removing this restriction expose a memory leak in the hsr_dev_finalize() error path?
If hsr_add_port() succeeds for the first slave, its RX handler becomes active and can receive frames, dynamically allocating nodes in hsr->node_db or hsr->proxy_node_db via softirqs. If adding the interlink fails shortly after:
net/hsr/hsr_device.c:hsr_dev_finalize():
err_unregister:
hsr_del_ports(hsr);
err_add_master:
hsr_del_self_node(hsr);
if (unregister)
unregister_netdevice(hsr_dev);
return res;The err_unregister path destroys the ports and unregisters the master device, but omits a call to hsr_del_nodes(). Does this cause the rtnl core to free the netdevice and leak the dynamically allocated hsr_node structures?
[Severity: High]
This isn't a bug introduced by this patch, but does allowing tagged frames on the interlink port trigger a silent SKB data corruption?
When an HSR or PRP tagged frame is received on the interlink port, it is forwarded to both slave ports. hsr_forward_do() calls create_tagged_frame() for each slave.
In net/hsr/hsr_forward.c:hsr_create_tagged_frame():
hsr_set_path_id(frame, hsr_ethhdr, port);
return skb_clone(frame->skb_hsr, GFP_ATOMIC);And similarly in net/hsr/hsr_forward.c:prp_create_tagged_frame():
prp_set_lan_id(trailer, port);
return skb_clone(frame->skb_prp, GFP_ATOMIC);Both calls directly modify the path or LAN ID in the data buffer of the original shared SKB before cloning it. Does the second modification for the second slave overwrite the first modification in the same underlying buffer, causing the first slave's cloned SKB to be transmitted with the wrong tag?
Quoted 3 lines
net/hsr/hsr_netlink.c +0
-0return hsr_dev_finalize (dev, link, interlink, multicast_spec, proto_version, extack);
Re: [PATCH net-next v4 1/4] net: hsr: add PRP interlink (RedBox) datapath and duplicate discard
In reply to Simon HormanQuoted 4 lines · On Fri, 24 Jul 2026 14:12:30 +0100 Simon Horman wrote:
[Severity: High]
... does modifying the MAC header directly inhsr_xmit()corrupt shared packet data? [...]
Should the skb be unshared before making these direct modifications?
I checked this against the v4 base and the series diff.
The shared-data write is real. hsr_xmit() writes eth_hdr(skb)->h_source in place - the slave-address substitution for master-originated frames, and the macaddress_redbox substitution for the interlink port - on skbs that can be clones. Multiple consumers can share the same packet data while needing different source addresses: a PRP LAN broadcast or multicast can be delivered to the master (source rewritten via hsr_addr_subst_source()) and forwarded to the interlink (rewritten to macaddress_redbox) from the same underlying buffer.
Two scope facts. This is pre-existing HSR RedBox code, present since v6.11: hsr_xmit() itself is untouched by the series (patch 1/4's hsr_forward.c changes sit below it and do not modify its body), and the series' only h_source-adjacent change moves an existing ether_addr_copy() a few lines earlier in hsr_dev_finalize(), where no skb is involved. But the series does make the existing interlink path reachable for PRP.
I will handle this as an independent fix for the existing HSR/PRP code, posted separately for net with its own Fixes: tag - not folded into this feature series.
Would you like the feature series to wait for that fix, or may v4 proceed while it is reviewed separately?
(The hsr_create_tagged_frame() side question overlaps the third finding in your 3/4 mail; it is answered there.)
--
Xin
Re: [PATCH net-next v4 3/4] net: hsr: allow PRP RedBox (interlink) creation
In reply to Simon HormanQuoted 4 lines · On Fri, 24 Jul 2026 14:12:46 +0100 Simon Horman wrote:
[Severity: Medium]
... unconditionally increment the port'stx_packetsandtx_bytes... inflate the network statistics for the physical interlink device?
Confirmed against the v4 base. hsr_forward_skb() receives the ingress port; when that is the interlink, the interlink device's tx_packets/tx_bytes are incremented for a frame that arrived from a SAN and is forwarded towards LAN A/B - nothing is transmitted on that device. A deterministic accounting error, pre-existing since v6.11; the series does not touch any statistics code. I will send an independent fix for net.
Quoted 2 lines
[Severity: Medium]
...err_unregister... omits a call tohsr_del_nodes(). ...
Confirmed. The earlier hsr_add_port() calls install live RX handlers, and RTNL does not exclude softirq RX, so dynamic nodes can be learned before a later hsr_add_port() fails. err_unregister removes the ports and the self node but never calls hsr_del_nodes(), and unregister_netdevice() does not invoke hsr_dellink(). A real leak, though a narrow one: it needs a partial-initialization failure after traffic has already flowed. Pre-existing (identical in v6.11), unchanged by this series. I will send an independent fix for net.
Quoted 4 lines
[Severity: High]
... directly modify the path or LAN ID in the data buffer of the original shared SKB before cloning it. Does the second modification for the second slave overwrite the first ... ?
This needs two separate answers.
The specific sequence the review describes - tagged input on the interlink forwarded to both slaves - does not occur in the PRP control flow:
* A normal SAN frame received on the interlink is untagged:
handle_std_frame() sets frame->skb_std, and each LAN output goes through the skb_copy_expand() branch, so LAN A and LAN B receive independent packet data.
* An already PRP-tagged frame on the interlink sets frame->skb_prp, but is_from_san remains false, so hsr_forward_do() consults prp_register_frame_out() before any helper runs. For LAN A or LAN B as destination it returns 1 and the loop continues, so neither LAN reaches prp_create_tagged_frame(). (This series touches that gate only to open the interlink destination, which is served by get_untagged_frame(), never by the tagged-frame helper.)
* A PRP-tagged frame received from one LAN is not forwarded to the other LAN either (the same gate), so it cannot produce two slave calls on the same frame->skb_prp.
The underlying pattern is nevertheless reachable, on the master transmit path: a pre-tagged frame transmitted on the master device (for example injected locally via AF_PACKET with a valid RCT; this needs CAP_NET_RAW) passes prp_fill_frame_info() with frame->skb_prp set. With port_rcv == MASTER the gate returns 0, and both slaves then run prp_set_lan_id() + skb_clone() on the same buffer, so the second LAN-id write can land in the first clone's data while it is still queued. hsr_create_tagged_frame() has the analogous shape for HSR.
That path is pre-existing (the helper has had this shape since at least v6.11) and is not introduced by v4, but the concern itself is valid. I will fix it independently for net, together with the other items.
To summarise: all four findings describe pre-existing code that this series does not modify. The interlink-ingress sequence from the last finding does not occur for PRP, but the same modify-before-clone pattern is reachable on the master transmit path, so that concern joins the other three: four independent fixes for net, each with its own verified Fixes: commit - I do not assume they share an originating commit. Would you like v4 to wait for the fixes, or may it proceed while they are reviewed separately?
--
Xin
Simon Horman
reviewerRe: [PATCH net-next v4 1/4] net: hsr: add PRP interlink (RedBox) datapath and duplicate discard
In reply to Xin XieQuoted 26 lines · Xin Xie
Quoted 4 lines · On Fri, 24 Jul 2026 14:12:30 +0100 Simon Horman wrote:
[Severity: High]
... does modifying the MAC header directly inhsr_xmit()corrupt shared packet data? [...]
Should the skb be unshared before making these direct modifications?I checked this against the v4 base and the series diff.
The shared-data write is real.
hsr_xmit()writes eth_hdr(skb)->h_source in place - the slave-address substitution for master-originated frames, and themacaddress_redboxsubstitution for the interlink port - on skbs that can be clones. Multiple consumers can share the same packet data while needing different source addresses: a PRP LAN broadcast or multicast can be delivered to the master (source rewritten viahsr_addr_subst_source()) and forwarded to the interlink (rewritten tomacaddress_redbox) from the same underlying buffer.Two scope facts. This is pre-existing HSR RedBox code, present since v6.11:
hsr_xmit()itself is untouched by the series (patch 1/4'shsr_forward.cchanges sit below it and do not modify its body), and the series' only h_source-adjacent change moves an existingether_addr_copy()a few lines earlier inhsr_dev_finalize(), where no skb is involved. But the series does make the existing interlink path reachable for PRP.
Quoted 6 lines
I will handle this as an independent fix for the existing HSR/PRP code, posted separately for net with its own Fixes: tag - not folded into this feature series.
Would you like the feature series to wait for that fix, or may v4 proceed while it is reviewed separately?
TL;DR: Yes, I think this patchset can proceed and fixes for
pre-existing issues can be addressed separately.
Thanks for the detailed feedback above, and likewise on patch 3/4. It is much appreciated.
My view is that in the age of AI-generated review there is a risk that making corrections pre-existing problems a pre-requisite risks perpetual scope increase. So I think that that unless a pre-existing bug is made materially worse, or fundamentally prevents a patch from reaching it's goals, then fixing the pre-existing bug can be considered as follow-up.
Of course, drawing that line is a subjective matter. But it seems to me that the pre-existing issues flagged both here and in the review I forwarded for 3/4 can be treated as follow-up.
Quoted 2 lines
(The
hsr_create_tagged_frame()side question overlaps the third finding in your 3/4 mail; it is answered there.)
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Fri, 17 Jul 2026 22:14:53 +0200 you wrote:
This series adds PRP RedBox support to the hsr driver: a PRP node that proxies one or more SANs sitting behind an interlink port (IEC 62439-3, PRP-SAN). HSR-SAN has been supported since commit
5055cccfc2d1("net: hsr:
Provide RedBox support (HSR-SAN)"); this extends the equivalent capability to PRP, reusing the existing protocol-neutral proxy machinery (proxy_node_db,hsr_proxy_announce(),hsr_prune_proxy_nodes()).[...]
Here is the summary with links:
- [net-next,v4,1/4] net: hsr: add PRP interlink (RedBox) datapath and duplicate discard
https://git.kernel.org/netdev/net-next/c/841afc9143ee - [net-next,v4,2/4] net: hsr: emit RedBox-MAC TLV in PRP RedBox supervision frames https://git.kernel.org/netdev/net-next/c/852c6a8d7cbe - [net-next,v4,3/4] net: hsr: allow PRP RedBox (interlink) creation https://git.kernel.org/netdev/net-next/c/85abc2db7ba3 - [net-next,v4,4/4] selftests: net: hsr: add PRP RedBox test https://git.kernel.org/netdev/net-next/c/6d548d0fc160
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html