Skip to contentSkip to conversation

net: hsr: fix shared-skb mutations in the forwarding path

PATCH In review Xin Xie 2 participants 16 messages Aug 8 – Sep 18

Subsystems (4)
lore
Share & tools
lore

Xin Xie

author
#0 lore raw

v3 cover net: hsr: fix shared-skb mutations in the forwarding path

Two existing HSR/PRP forwarding paths modify data shared by multiple skbs. One changes RedBox interlink source addresses, and the other updates per-egress HSR path or PRP LAN IDs. A later consumer can then observe another consumer's value.

Patch 1 makes interlink address substitution private. Patch 2 uses one clone/COW helper for tagged HSR/PRP frames and both hardware tag-insertion branches. Patch 3 adds regressions for both corruptions.

The series is independent of the posted GRO/GSO v5 series:
https://lore.kernel.org/all/[email protected]/
Both orders apply to current net. On current net-next, patch 3 needs git am -3 because hsr_prp_redbox.sh is already in the same Makefile block; the merged list remains sorted and validates.

Validation:
- the targeted test fails both cases on the base and passes on the candidate
- the affected HSR/PRP regression tests pass
- base-versus-candidate W=1 allmodconfig and allyesconfig add no diagnostics
- no TAG_INS hardware was available; those branches have source review only

Changes since v2, including official Sashiko dispositions:
- use a shared clone/COW helper and cover both TAG_INS branches
- correct the helper comment and interlink eligibility wording
- fix HSR LSDU encoding, capture draining, and result aggregation
- defer the existing dev->stats races per Paolo
- leave VLAN/non-linear receive parsing and receive-side tap aliases unchanged

Previous postings:
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Xin Xie (3):
net: hsr: privatize interlink-bound skbs before address mutation
net: hsr: return private clones from the tagged-frame helpers
selftests: net: hsr: add shared-mutation regression test

 net/hsr/hsr_forward.c                         |  65 ++++-
 tools/testing/selftests/net/hsr/Makefile      |   1 +
 .../selftests/net/hsr/hsr_shared_mutation.sh  | 242 ++++++++++++++++++
 3 files changed, 299 insertions(+), 9 deletions(-)
 create mode 100755 tools/testing/selftests/net/hsr/hsr_shared_mutation.sh

base-commit: 594d905195024b228c962627ae5ae7c17bd582a4

Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v3 1/3 net: hsr: privatize interlink-bound skbs before address mutation

An skb sent to a RedBox interlink can share data with master delivery or the original TX skb. hsr_deliver_master() and hsr_xmit() then write different source addresses, so one consumer can observe the other's address.

Use skb_cow() before interlink address substitution when those paths can share the data. Drop that egress on COW failure. Other interlink traffic keeps its zero-copy behavior.

Fixes 5055cccfc2d1 ("net: hsr: Provide RedBox support (HSR-SAN)")
---
 net/hsr/hsr_forward.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
net/hsr/hsr_forward.c +16 -0
index 0774981a65c1..67aaf5a8622b 100644
@@ -420,6 +420,22 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
 static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,
 		    struct hsr_frame_info *frame)
 {
+	/* An interlink-bound skb from get_untagged_frame() can still alias
+	 * another live consumer: for master-originated frames the clone
+	 * shares the original TX skb (which taps or the TX path may still
+	 * hold); for ring frames the master also consumes them when they
+	 * are destined to the local node without being exclusive to it.
+	 * Privatize before any address mutation.
+	 */
+	if (port->type == HSR_PT_INTERLINK &&
+	    (frame->port_rcv->type == HSR_PT_MASTER ||
+	     (frame->is_local_dest && !frame->is_local_exclusive)) &&
+	    skb_cow(skb, 0)) {
+		frame->port_rcv->dev->stats.rx_dropped++;
+		kfree_skb(skb);
+		return NET_XMIT_DROP;
+	}
+
 	if (frame->port_rcv->type == HSR_PT_MASTER) {
 		hsr_addr_subst_dest(frame->node_src, skb, port);
 
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH net v3 1/3] net: hsr: privatize interlink-bound skbs before address mutation

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: hsr: privatize interlink-bound skbs before address mutation

This adds an skb_cow() call in hsr_xmit() for interlink egress when the frame either came in on the master port or is locally destined without being local-exclusive, dropping the egress if the copy fails. The stated goal is to stop hsr_deliver_master() and hsr_xmit() from writing different source addresses into shared data.

Quoted 14 lines
net/hsr/hsr_forward.c +6 -0
index 0774981a65c1..67aaf5a8622b 100644
@@ -420,6 +420,22 @@ static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev,
 static int hsr_xmit(struct sk_buff *skb, struct hsr_port *port,
 		    struct hsr_frame_info *frame)
 {
+	/* An interlink-bound skb from get_untagged_frame() can still alias
+	 * another live consumer: for master-originated frames the clone
+	 * shares the original TX skb (which taps or the TX path may still
+	 * hold); for ring frames the master also consumes them when they
+	 * are destined to the local node without being exclusive to it.
+	 * Privatize before any address mutation.

net/hsr/hsr_forward.c static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev, · line 438

Quoted 10 lines
net/hsr/hsr_forward.c +10 -0
+	 */
+	if (port->type == HSR_PT_INTERLINK &&
+	    (frame->port_rcv->type == HSR_PT_MASTER ||
+	     (frame->is_local_dest && !frame->is_local_exclusive)) &&
+	    skb_cow(skb, 0)) {
+		frame->port_rcv->dev->stats.rx_dropped++;
+		kfree_skb(skb);
+		return NET_XMIT_DROP;
+	}
+

[Severity: Medium]
Is the enumeration in this comment complete? The unconditional interlink source-address rewrite is pre-existing and was not introduced by this patch, but the new guard and the commit message claim ("Other interlink traffic keeps its zero-copy behavior") assert that the uncovered cases are safe, and there looks to be one that isn't.

For an untagged ring frame, handle_std_frame() keeps the received skb:

net/hsr/hsr_forward.c:handle_std_frame() {
	frame->skb_hsr = NULL;
	frame->skb_prp = NULL;
	frame->skb_std = skb;
	...
}

and hsr_get_untagged_frame() hands the interlink a plain clone of that skb. So the interlink egress skb shares the receive head with any clone already taken by a ptype_all tap, since __netif_receive_skb_core() runs the deliver_skb() loop over skb->dev->ptype_all before it dereferences skb->dev->rx_handler, and packet_rcv() then queues its skb_share_check() clone on sk_receive_queue where the bytes are copied to userspace only later.

For a remote unicast frame addressed to a SAN behind the RedBox, check_local_dest() leaves frame->is_local_dest false (pkt_type is PACKET_OTHERHOST) and frame->port_rcv->type is SLAVE_A or SLAVE_B, so the new predicate is false, no copy happens, and the rewrite lower down in hsr_xmit() still touches the shared data:

	if (port->type == HSR_PT_INTERLINK)
		ether_addr_copy(eth_hdr(skb)->h_source,
				port->hsr->macaddress_redbox);

Would the tap consumer on the ring slave then read the RedBox MAC instead of the real source MAC? Reaching this needs an HSR RedBox whose ring slave advertises NETIF_F_HW_HSR_TAG_RM, so that untagged ring ingress is forwarded rather than passed up:

net/hsr/hsr_slave.c:hsr_handle_frame() {
	if (!(port->dev->features & NETIF_F_HW_HSR_TAG_RM) &&
	    port->type != HSR_PT_INTERLINK &&
	    hsr->proto_ops->invalid_dan_ingress_frame &&
	    hsr->proto_ops->invalid_dan_ingress_frame(protocol))
		goto finish_pass;
	...
}

At this patch alone the same case also mutates a real on-wire frame, because hsr_create_tagged_frame() and prp_create_tagged_frame() return a bare clone of frame->skb_std for NETIF_F_HW_HSR_TAG_INS devices:

	} else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
		return skb_clone(frame->skb_std, GFP_ATOMIC);
	}

That second aliasing consumer is removed later in the series by "net: hsr:
return private clones from the tagged-frame helpers", which switches those helpers to hsr_clone_private(), so only the tap aliasing remains at the end of the series.

Since skb_cow(skb, 0) is a no-op for a non-cloned skb (__skb_cow() only calls pskb_expand_head() when skb_cloned() or extra headroom is needed), could the call be keyed on the actual sharing state, or simply made unconditional for HSR_PT_INTERLINK, instead of on the topology predicate?

Signature · 1 line
pw-bot: cr
author
#3 lore raw

Re: [PATCH net v3 1/3] net: hsr: privatize interlink-bound skbs before address mutation

Quoted 11 lines · Jakub Kicinski

[Severity: Medium]
Is the enumeration in this comment complete? The unconditional interlink source-address rewrite is pre-existing and was not introduced by this patch, but the new guard and the commit message claim ("Other interlink traffic keeps its zero-copy behavior") assert that the uncovered cases are safe, and there looks to be one that isn't.
...
Since skb_cow(skb, 0) is a no-op for a non-cloned skb (__skb_cow() only calls pskb_expand_head() when skb_cloned() or extra headroom is needed), could the call be keyed on the actual sharing state, or simply made unconditional for HSR_PT_INTERLINK, instead of on the topology predicate?

Correct, the enumeration is incomplete. For TAG_RM ingress retained in frame->skb_std, a queued packet-socket clone can still share its data even when the frame is not locally destined. The interlink source rewrite can then change that clone.

I'll remove the topology-based assumption when revising the COW handling for v4.

Signature · 1 line
Xin
maintainer
#4 lore raw

Re: [PATCH net v3 1/3] net: hsr: privatize interlink-bound skbs before address mutation

In reply to Xin Xie

net/hsr/hsr_forward.c static void hsr_deliver_master(struct sk_buff *skb, struct net_device *dev, · line 433

Quoted 4 lines · On Sat, 8 Aug 2026 02:45:22 +0200 Xin Xie wrote:
net/hsr/hsr_forward.c +4 -0
+	if (port->type == HSR_PT_INTERLINK &&
+	    (frame->port_rcv->type == HSR_PT_MASTER ||
+	     (frame->is_local_dest && !frame->is_local_exclusive)) &&
+	    skb_cow(skb, 0)) {

Would skb_cow_head() be sufficient? It's much cheaper, at least for TCP.

author
#5 lore raw

Re: [PATCH net v3 1/3] net: hsr: privatize interlink-bound skbs before address mutation

Quoted 2 lines · Jakub Kicinski

Would skb_cow_head() be sufficient? It's much cheaper, at least for TCP.

I am currently on annual leave until the middle of September. I will continue this topic when I return.

Signature · 1 line
Xin
author
#6 lore raw

Re: [PATCH net v3 1/3] net: hsr: privatize interlink-bound skbs before address mutation

In reply to Jakub Kicinski
Quoted 1 line · Jakub Kicinski

Would skb_cow_head() be sufficient? It's much cheaper, at least for TCP.

Yes, skb_cow_head() is sufficient for these Ethernet-address writes. I'll revise the ownership handling for v4, taking the remaining aliases in your other replies into account.

Signature · 1 line
Xin
author
#7 lore raw

PATCH v3 2/3 net: hsr: return private clones from the tagged-frame helpers

In reply to Xin Xie

The tagged-frame helpers can return skbs whose data is still shared. Later path, LAN ID, or source-address updates may then modify another queued clone or the original TX skb.

Add hsr_clone_private() and use it for HSR, PRP, and both hardware tag-insertion branches. Reacquire tag and trailer pointers after COW; the PRP RCT is in the copied linear area.

This adds one linear-data copy per affected egress. Untagged software forwarding is unchanged.

Fixes 451d8123f897 ("net: prp: add packet handling support")
Fixes dcf0cd1cc58b ("net: hsr: add offloading support")
---
 net/hsr/hsr_forward.c | 49 +++++++++++++++++++++++++++++++++++--------
 1 file changed, 40 insertions(+), 9 deletions(-)
net/hsr/hsr_forward.c +40 -9
index 67aaf5a8622b..efcbf3cf26f9 100644
@@ -325,8 +325,29 @@ static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,
 	return skb;
 }
 
-/* If the original frame was an HSR tagged frame, just clone it to be sent
- * unchanged. Otherwise, create a private frame especially tagged for 'port'.
+/* Clone an skb and make the clone's data private, so that per-egress
+ * writes cannot corrupt the original skb or other clones of it.
+ * Returns NULL on allocation failure.
+ */
+static struct sk_buff *hsr_clone_private(struct sk_buff *skb)
+{
+	struct sk_buff *clone;
+
+	clone = skb_clone(skb, GFP_ATOMIC);
+	if (!clone)
+		return NULL;
+	if (skb_cow(clone, 0)) {
+		kfree_skb(clone);
+		return NULL;
+	}
+
+	return clone;
+}
+
+/* If the original frame was an HSR tagged frame, return a private clone
+ * of it with the path id updated for 'port'. Otherwise, return a private
+ * clone for hardware tag insertion, or create a private frame especially
+ * tagged for 'port'.
  */
 struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
 					struct hsr_port *port)
@@ -336,14 +357,18 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
 	int movelen;
 
 	if (frame->skb_hsr) {
-		struct hsr_ethhdr *hsr_ethhdr =
-			(struct hsr_ethhdr *)skb_mac_header(frame->skb_hsr);
+		struct hsr_ethhdr *hsr_ethhdr;
+
+		skb = hsr_clone_private(frame->skb_hsr);
+		if (!skb)
+			return NULL;
 
 		/* set the lane id properly */
+		hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
 		hsr_set_path_id(frame, hsr_ethhdr, port);
-		return skb_clone(frame->skb_hsr, GFP_ATOMIC);
+		return skb;
 	} else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
-		return skb_clone(frame->skb_std, GFP_ATOMIC);
+		return hsr_clone_private(frame->skb_std);
 	}
 
 	/* Create the new skb with enough headroom to fit the HSR tag */
@@ -377,17 +402,23 @@ struct sk_buff *prp_create_tagged_frame(struct hsr_frame_info *frame,
 	struct sk_buff *skb;
 
 	if (frame->skb_prp) {
-		struct prp_rct *trailer = skb_get_PRP_rct(frame->skb_prp);
+		struct prp_rct *trailer;
 
+		skb = hsr_clone_private(frame->skb_prp);
+		if (!skb)
+			return NULL;
+
+		trailer = skb_get_PRP_rct(skb);
 		if (trailer) {
 			prp_set_lan_id(trailer, port);
 		} else {
 			WARN_ONCE(!trailer, "errored PRP skb");
+			kfree_skb(skb);
 			return NULL;
 		}
-		return skb_clone(frame->skb_prp, GFP_ATOMIC);
+		return skb;
 	} else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
-		return skb_clone(frame->skb_std, GFP_ATOMIC);
+		return hsr_clone_private(frame->skb_std);
 	}
 
 	skb = skb_copy_expand(frame->skb_std, skb_headroom(frame->skb_std),
Signature · 1 line
2.43.0
maintainer
#8 lore raw

Re: [PATCH net v3 2/3] net: hsr: return private clones from the tagged-frame helpers

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
net: hsr: return private clones from the tagged-frame helpers

This adds hsr_clone_private() (skb_clone() followed by skb_cow()) and uses it in hsr_create_tagged_frame() and prp_create_tagged_frame(), including both NETIF_F_HW_HSR_TAG_INS branches, so that per-egress path/LAN id writes land in private linear data. Tag and trailer pointers are reacquired after the copy.

Quoted 49 lines
net/hsr/hsr_forward.c +28 -4
index 67aaf5a8622b..efcbf3cf26f9 100644
@@ -325,8 +325,29 @@ static struct sk_buff *hsr_fill_tag(struct sk_buff *skb,
 	return skb;
 }
 
-/* If the original frame was an HSR tagged frame, just clone it to be sent
- * unchanged. Otherwise, create a private frame especially tagged for 'port'.
+/* Clone an skb and make the clone's data private, so that per-egress
+ * writes cannot corrupt the original skb or other clones of it.
+ * Returns NULL on allocation failure.
+ */
+static struct sk_buff *hsr_clone_private(struct sk_buff *skb)
+{
+	struct sk_buff *clone;
+
+	clone = skb_clone(skb, GFP_ATOMIC);
+	if (!clone)
+		return NULL;
+	if (skb_cow(clone, 0)) {
+		kfree_skb(clone);
+		return NULL;
+	}
+
+	return clone;
+}
+
+/* If the original frame was an HSR tagged frame, return a private clone
+ * of it with the path id updated for 'port'. Otherwise, return a private
+ * clone for hardware tag insertion, or create a private frame especially
+ * tagged for 'port'.
  */
 struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
 					struct hsr_port *port)
@@ -336,14 +357,18 @@ struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame,
 	int movelen;
 
 	if (frame->skb_hsr) {
-		struct hsr_ethhdr *hsr_ethhdr =
-			(struct hsr_ethhdr *)skb_mac_header(frame->skb_hsr);
+		struct hsr_ethhdr *hsr_ethhdr;
+
+		skb = hsr_clone_private(frame->skb_hsr);
+		if (!skb)
+			return NULL;
 
 		/* set the lane id properly */

net/hsr/hsr_forward.c struct sk_buff *hsr_create_tagged_frame(struct hsr_frame_info *frame, · line 374

Quoted 10 lines
net/hsr/hsr_forward.c +3 -2
+		hsr_ethhdr = (struct hsr_ethhdr *)skb_mac_header(skb);
 		hsr_set_path_id(frame, hsr_ethhdr, port);
-		return skb_clone(frame->skb_hsr, GFP_ATOMIC);
+		return skb;
 	} else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
-		return skb_clone(frame->skb_std, GFP_ATOMIC);
+		return hsr_clone_private(frame->skb_std);
 	}
 
 	/* Create the new skb with enough headroom to fit the HSR tag */

[Severity: High]
This isn't a bug introduced by this patch, but should the sibling get_untagged_frame() callbacks be privatized the same way?

hsr_get_untagged_frame() and prp_get_untagged_frame() still end with:

	return skb_clone(frame->skb_std, GFP_ATOMIC);

and their consumer writes into that still-shared linear data:

net/hsr/hsr_forward.c:hsr_deliver_master() {
	was_multicast_frame = (skb->pkt_type == PACKET_MULTICAST);
	hsr_addr_subst_source(node_src, skb);
	skb_pull(skb, ETH_HLEN);
	...
}
net/hsr/hsr_framereg.c:hsr_addr_subst_source() {
	...
	memcpy(&eth_hdr(skb)->h_source, node->macaddress_A, ETH_ALEN);
}

Since that clone shares data with frame->skb_std, can the substituted source address leak into the ring egress built later in the same hsr_forward_do() loop? For an untagged frame frame->skb_hsr is NULL, so the slave iterations take either

	skb = __pskb_copy(frame->skb_std,
			  skb_headroom(frame->skb_std) + HSR_HLEN, GFP_ATOMIC);

or, with NETIF_F_HW_HSR_TAG_INS, the new hsr_clone_private(frame->skb_std) above, both of which copy the already-mutated bytes.

Port order looks like it puts master first: hsr_dev_finalize() calls hsr_add_port() for MASTER, then SLAVE_A/SLAVE_B (and INTERLINK), and hsr_add_port() uses list_add_tail_rcu().

The substitution is only a no-op when node->macaddress_A already equals h_source. hsr_get_node() also matches on macaddress_B:

net/hsr/hsr_framereg.c:hsr_get_node() {
	...
		if (ether_addr_equal(node->macaddress_B, ethhdr->h_source)) {
	...
}

and hsr_handle_sup_frame() populates macaddress_B from a supervision frame's source, so macaddress_A and h_source can differ.

The comment this series added to hsr_xmit() states the rule:

	/* An interlink-bound skb from get_untagged_frame() can still alias
	 * another live consumer: ...
	 * Privatize before any address mutation.
	 */

but the skb_cow() there is applied only for port->type == HSR_PT_INTERLINK, which leaves the master delivery path out. Would it be simpler to make the get_untagged_frame() callbacks return private clones too, so the contract holds for every consumer?

One more consumer of the same bytes: an AF_PACKET listener on the slave device gets its clone in packet_rcv() before hsr_handle_frame() runs, so does it also observe the rewritten h_source?

author
#9 lore raw

Re: [PATCH net v3 2/3] net: hsr: return private clones from the tagged-frame helpers

Quoted 7 lines · Jakub Kicinski

[Severity: High]
This isn't a bug introduced by this patch, but should the sibling get_untagged_frame() callbacks be privatized the same way?
...
One more consumer of the same bytes: an AF_PACKET listener on the slave device gets its clone in packet_rcv() before hsr_handle_frame() runs, so does it also observe the rewritten h_source?

Yes. Master delivery can rewrite frame->skb_std through its clone before the later slave copies it. When the learned A and B addresses differ, that copy preserves the substituted address rather than the original source. An earlier packet-socket clone can also be affected.

I'll compare private untagged returns with COW at the writers before settling the v4 ownership changes.

Signature · 1 line
Xin
author
#10 lore raw

PATCH v3 3/3 selftests: net: hsr: add shared-mutation regression test

In reply to Xin Xie

Add regression coverage for both shared-data corruptions. Delay one PRP egress and verify that queued clones retain their LAN IDs. For HSR RedBox, deliver a tagged multicast to the master and interlink and verify each source address.

Drain captures while injecting and merge both subtest results so packet-socket pressure or a skip cannot hide a failure.

---
 tools/testing/selftests/net/hsr/Makefile      |   1 +
 .../selftests/net/hsr/hsr_shared_mutation.sh  | 242 ++++++++++++++++++
 2 files changed, 243 insertions(+)
 create mode 100755 tools/testing/selftests/net/hsr/hsr_shared_mutation.sh
tools/testing/selftests/net/hsr/Makefile +1 -0
index 31fb9326cf53..87fe34951b8b 100644
@@ -5,6 +5,7 @@ top_srcdir = ../../../../..
 TEST_PROGS := \
 	hsr_ping.sh \
 	hsr_redbox.sh \
+	hsr_shared_mutation.sh \
 	link_faults.sh \
 	prp_ping.sh \
 # end of TEST_PROGS
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +242 -0

242 lines not on this page · raw message

Signature · 1 line
2.43.0
author
#11 lore raw

Re: [PATCH net v3 3/3] selftests: net: hsr: add shared-mutation regression test

Dispositions for the AI-review findings on this patch (the review is published on the web only, not mailed to the list):

Quoted 9 lines

The header calls this subtest "F2 (path/LAN ID)" and the changelog says "Add regression coverage for both shared-data corruptions", but is any path ID actually checked anywhere in the script?

This link is created with proto 1, so only the PRP path is exercised, and the checks below only decode the PRP RCT LAN-ID nibble. That covers prp_create_tagged_frame()'s frame->skb_prp branch.

Quoted 5 lines

The sibling branches in hsr_create_tagged_frame() are not touched by either subtest: [...]

Would it be worth adding an HSR-tagged (proto 0, version 1) case with captures on the slave peers so those branches are covered too?

The analysis is correct: only the PRP RCT branch is exercised. Note the F1 link is HSR_V0, which assigns the same path ID to both slaves, so a path-ID check would indeed need a version-1 link as suggested; the NETIF_F_HW_HSR_TAG_INS branches additionally need offload hardware that a veth topology does not provide.

Quoted 7 lines

Every other capability this script needs is probed and turned into a skip: ip/tc/python3 via require(), sch_netem via the tc qdisc probe, and HSR/PRP plus HSR RedBox via the ip link add probes. AF_PACKET is the exception.

tools/testing/selftests/net/hsr/config lists only: [...]

Quoted 7 lines

and CONFIG_PACKET in net/packet/Kconfig is a plain tristate with no default y. On a kernel built from this fragment, socket(AF_PACKET, ...) raises OSError(EAFNOSUPPORT), python3 exits 1, run_f2() returns 1 and the merge reports a hard FAIL rather than a skip.

Should CONFIG_PACKET be added to the hsr config fragment?

Correct. In practice a kselftest-merge picks up CONFIG_PACKET=y from other net selftests' fragments, so this only bites on a kernel built from the hsr fragment alone.

Quoted 5 lines

The capture loop above also exits when the four second deadline expires, leaving i_src as None. Since None != RB is true, does that make a missed vIp capture report as "interlink did not carry the RedBox MAC"?

Quoted 7 lines

The m_src check that follows is the assertion this subtest exists for [...] and it is skipped because the i_src check already called sys.exit(1). [...]

Could F1 get an equivalent explicit check for m_src is None / i_src is None before the value comparisons, so a timeout is distinguishable from a wrong MAC?

Yes, the subtest still fails in that case, but the printed reason is misleading and the primary assertion never runs; an explicit None check would separate the two outcomes.

Quoted 11 lines

The changelog says the results are merged "so packet-socket pressure or a skip cannot hide a failure". Does the merge hold for statuses that are not one of the kselftest constants?

Both run_f2() and run_f1() end with nsx python3 /dev/stdin, so ret is the raw exit status of ip netns exec python3. A signal-killed interpreter gives 128+N (137 for a SIGKILL/OOM, 139 for SIGSEGV), and an ip netns exec failure gives 255.

ksft_status_merge() only ranks four values: [...]

Quoted 8 lines

With ret=137, ${weights[137]} expands to the empty string, which bash evaluates as 0 inside [[ ]], so 0 -ge 0 succeeds and the function echoes a, i.e. 0. rc stays 0, the branch above prints "[ OK ]" and exit "$rc" returns 0 for a subtest that was killed mid-run. [...]

Would normalising ret to $ksft_fail for anything outside 0/$ksft_xfail/$ksft_skip/$ksft_fail before merging address this?

Yes, normalising ret to the ksft constants before merging addresses it. This only affects abnormal exits; normal outcomes always return the ksft codes, which merge correctly.

All four are test-code remarks; none changes the verdict direction on the configurations the test runs (it fails on the unfixed kernel and passes with the series), so no respin is planned for them.

Signature · 1 line
Xin
maintainer
#12 lore raw

Re: [PATCH net v3 3/3] selftests: net: hsr: add shared-mutation regression test

In reply to Xin Xie

This is an AI-generated review of your patch. The human sending this email has considered the AI review valid, or at least plausible.
---
selftests: net: hsr: add shared-mutation regression test

This adds tools/testing/selftests/net/hsr/hsr_shared_mutation.sh, which runs two subtests: a PRP subtest that delays one slave with netem and checks the LAN-ID nibble of captured frames, and an HSR RedBox subtest that checks the source MAC seen on the master and on the interlink. The two subtest results are combined with ksft_status_merge().

A few questions on the new script below.

Quoted 26 lines
tools/testing/selftests/net/hsr/Makefile +1 -0
index 31fb9326cf53..87fe34951b8b 100644
@@ -5,6 +5,7 @@ top_srcdir = ../../../../..
 TEST_PROGS := \
 	hsr_ping.sh \
 	hsr_redbox.sh \
+	hsr_shared_mutation.sh \
 	link_faults.sh \
 	prp_ping.sh \
 # end of TEST_PROGS
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +8 -0
new file mode 100755
index 000000000000..0b8b8791190d
@@ -0,0 +1,242 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# Verify that per-egress mutations of shared skb data are private:
+#
+# F2 (path/LAN ID): on an affected kernel the second slave's LAN-ID write
+# lands in the first slave's still-queued clone; with a netem delay on
+# slave A, injected frames leave A carrying B's LAN ID.

[ ... ]

tools/testing/selftests/net/hsr/hsr_shared_mutation.sh line 61

Quoted 5 lines
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +5 -0
+	if ! nsx ip link add name prp0 type hsr slave1 vA slave2 vB \
+		supervision 45 proto 1 2>/dev/null; then
+		echo "SKIP: HSR/PRP not supported by this kernel"
+		return $ksft_skip
+	fi

[Severity: Low]

The header calls this subtest "F2 (path/LAN ID)" and the changelog says "Add regression coverage for both shared-data corruptions", but is any path ID actually checked anywhere in the script?

This link is created with proto 1, so only the PRP path is exercised, and the checks below only decode the PRP RCT LAN-ID nibble. That covers prp_create_tagged_frame()'s frame->skb_prp branch.

The sibling branches in hsr_create_tagged_frame() are not touched by either subtest:

net/hsr/hsr_forward.c:hsr_create_tagged_frame() {
	if (frame->skb_hsr) {
		skb = hsr_clone_private(frame->skb_hsr);
		...
	} else if (port->dev->features & NETIF_F_HW_HSR_TAG_INS) {
		return hsr_clone_private(frame->skb_std);
	...
}

Would it be worth adding an HSR-tagged (proto 0, version 1) case with captures on the slave peers so those branches are covered too?

Quoted 2 lines
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +2 -0
+	nsx python3 /dev/stdin "$DUR" <<'PYF2'
+import socket, struct, select, sys, time

[ ... ]

tools/testing/selftests/net/hsr/hsr_shared_mutation.sh line 84

Quoted 4 lines
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +4 -0
+tx = socket.socket(socket.AF_PACKET, socket.SOCK_RAW); tx.bind(("prp0", 0))
+sA = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
+        socket.ntohs(0x0003))
+sA.bind(("vAp", 0))

[Severity: Low]

Every other capability this script needs is probed and turned into a
skip: ip/tc/python3 via require(), sch_netem via the tc qdisc probe, and HSR/PRP plus HSR RedBox via the ip link add probes. AF_PACKET is the exception.

tools/testing/selftests/net/hsr/config lists only:

CONFIG_BRIDGE=y
CONFIG_HSR=y
CONFIG_IPV6=y
CONFIG_NET_SCH_NETEM=m
CONFIG_VETH=y
CONFIG_VLAN_8021Q=m

and CONFIG_PACKET in net/packet/Kconfig is a plain tristate with no default y. On a kernel built from this fragment, socket(AF_PACKET, ...) raises OSError(EAFNOSUPPORT), python3 exits 1, run_f2() returns 1 and the merge reports a hard FAIL rather than a skip.

Should CONFIG_PACKET be added to the hsr config fragment?

[ ... ]

Quoted 15 lines
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +15 -0
+m_src = i_src = None
+end = time.time() + 4
+while time.time() < end and (m_src is None or i_src is None):
+    r, _, _ = select.select([sm, si], [], [], 0.3)
+    for s in r:
+        pkt = s.recv(65535)
+        # exact flow: dst, post-strip EtherType, exact payload, min length;
+        # h_source is the asserted value and must NOT be filtered on
+        if (len(pkt) < 60 or pkt[:6] != MCAST or pkt[12:14] != b"\x08\x00"
+                or pkt[14:14 + len(PAY)] != PAY):
+            continue
+        if s is sm and m_src is None:
+            m_src = pkt[6:12]
+        elif s is si and i_src is None:
+            i_src = pkt[6:12]

[ ... ]

tools/testing/selftests/net/hsr/hsr_shared_mutation.sh line 218

Quoted 8 lines
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +8 -0
+if i_src != RB:
+    print("FAIL: interlink did not carry the RedBox MAC")
+    sys.exit(1)
+if m_src != NODE:
+    print("FAIL: master received %s instead of the node MAC "
+          "(shared-mutation corruption)"
+          % (m_src.hex() if m_src else "nothing"))
+    sys.exit(1)

[Severity: Low]

The capture loop above also exits when the four second deadline expires, leaving i_src as None. Since None != RB is true, does that make a missed vIp capture report as "interlink did not carry the RedBox MAC"?

The m_src check that follows is the assertion this subtest exists for - it detects hsr_xmit()'s ether_addr_copy(eth_hdr(skb)->h_source, hsr->macaddress_redbox) landing in the master clone - and it is skipped because the i_src check already called sys.exit(1).

run_f2 has a "nothing arrived" guard:

if len(a) < 150 or len(b) < 150:
print("FAIL: too few injected frames captured (A=%d B=%d, sent 200)"
% (len(a), len(b)))

Could F1 get an equivalent explicit check for m_src is None / i_src is None before the value comparisons, so a timeout is distinguishable from a wrong MAC?

Quoted 7 lines
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +7 -0
+print("PASS: master kept node MAC, interlink kept RedBox MAC")
+sys.exit(0)
+PYF1
+}
+
+rc=0
+

tools/testing/selftests/net/hsr/hsr_shared_mutation.sh line 235

Quoted 10 lines
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +10 -0
+run_f2
+ret=$?
+rc=$(ksft_status_merge "$rc" "$ret")
+
+run_f1
+ret=$?
+rc=$(ksft_status_merge "$rc" "$ret")
+
+if [ "$rc" -eq 0 ]; then
+	echo "hsr_shared_mutation: per-egress mutation isolation (F1+F2) [ OK ]"

[Severity: Medium]

The changelog says the results are merged "so packet-socket pressure or a skip cannot hide a failure". Does the merge hold for statuses that are not one of the kselftest constants?

Both run_f2() and run_f1() end with nsx python3 /dev/stdin, so ret is the raw exit status of ip netns exec python3. A signal-killed interpreter gives 128+N (137 for a SIGKILL/OOM, 139 for SIGSEGV), and an ip netns exec failure gives 255.

ksft_status_merge() only ranks four values:

tools/testing/selftests/net/lib.sh:
ksft_status_merge()
{
local a=$1; shift
local b=$1; shift

__ksft_status_merge "$a" "$b" \
$ksft_pass $ksft_xfail $ksft_skip $ksft_fail
}

__ksft_status_merge()

{
	...
	for i in "$@"; do
		weights[$i]=$((weight++))
	done

	if [[ ${weights[$a]} -ge ${weights[$b]} ]]; then
		echo "$a"

With ret=137, ${weights[137]} expands to the empty string, which bash evaluates as 0 inside [[ ]], so 0 -ge 0 succeeds and the function echoes a, i.e. 0. rc stays 0, the branch above prints "[ OK ]" and exit "$rc" returns 0 for a subtest that was killed mid-run.

(If instead the empty operand aborts the conditional, the command substitution produces no output, rc becomes empty, and both [ "$rc" -eq 0 ] and [ "$rc" -eq "$ksft_skip" ] error out with exit "" not propagating a failure either.)

Would normalising ret to $ksft_fail for anything outside 0/$ksft_xfail/$ksft_skip/$ksft_fail before merging address this?

Quoted 7 lines
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +7 -0
+elif [ "$rc" -eq "$ksft_skip" ]; then
+	echo "hsr_shared_mutation: subtests skipped (capabilities missing)"
+else
+	echo "hsr_shared_mutation: per-egress mutation isolation [ FAIL ]" \
+		"rc=$rc" 1>&2
+fi
+exit "$rc"
author
#13 lore raw

Re: [PATCH net v3 3/3] selftests: net: hsr: add shared-mutation regression test

Quoted 2 lines · Jakub Kicinski

A few questions on the new script below.
...

I'll revise the selftest for v4. Unexpected subprocess exit statuses must be converted to FAIL before merging; my earlier no-respin conclusion was too broad. I'll also add CONFIG_PACKET to the test's config fragment and distinguish missing captures from incorrect MAC addresses.

To correct my earlier reply: the RedBox case can execute the HSR-tagged forwarding branch, but it does not check the path ID. I'll revisit that coverage for v4. A veth test still cannot validate hardware tag insertion.

Signature · 1 line
Xin
maintainer
#14 lore raw

Re: [PATCH net v3 3/3] selftests: net: hsr: add shared-mutation regression test

In reply to Xin Xie

tools/testing/selftests/net/hsr/hsr_shared_mutation.sh line 166

Quoted 2 lines · On Sat, 8 Aug 2026 02:45:24 +0200 Xin Xie wrote:
tools/testing/selftests/net/hsr/hsr_shared_mutation.sh new file +2 -0
+	nsx python3 /dev/stdin <<'PYF1'
+import socket, select, sys, time

It's a "no" on embedded Python in bash scripts.
Where do people get that from? Did AI generate it or are there projects in which this is common practice?

Please write the whole test in Python (see .../net/lib/py/ helpers), or move the python code out to its own scrip under TEST_FILES

author
#15 lore raw

Re: [PATCH net v3 3/3] selftests: net: hsr: add shared-mutation regression test

Quoted 6 lines · Jakub Kicinski

It's a "no" on embedded Python in bash scripts.
Where do people get that from? Did AI generate it or are there projects in which this is common practice?

Please write the whole test in Python (see .../net/lib/py/ helpers), or move the python code out to its own scrip under TEST_FILES

Yes, that snippet was AI-generated, I should have properly separated it. My bad!

I will extract the Python logic into its own helper script, put it under TEST_FILES, and clean this up for v4.

Signature · 1 line
Xin