Skip to contentSkip to conversation

net: bridge: mrp: fix uninitialised bytes on the wire

PATCH Superseded Baul Lee 4 participants 6 messages Jul 26 – Jul 31

Subsystems (4)
lore
Share & tools
lore

Baul Lee

author
#0 lore raw

PATCH 1/1 net: bridge: mrp: fix uninitialised bytes on the wire

br_mrp_alloc_test_skb() builds MRP test frames on an skb from dev_alloc_skb(), which does not zero the linear data area. On the MRA ring-role branch the sub-option TLV header is appended with

	sub_tlv = skb_put(skb, sizeof(*sub_tlv));
	sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;

leaving sub_tlv->length unwritten, and the two trailing alignment bytes are appended with a bare skb_put() that neither writes nor clears them. The surrounding oui and sub_opt regions are explicitly memset(0), which bounds the exposure to exactly these three bytes.

Every MRA MRP_Test frame therefore carries three bytes of stale page-allocator memory, at frame offsets 65 to 67, to any observer of the MRP control traffic. A capture on a kernel without CONFIG_INIT_ON_ALLOC_DEFAULT_ON shows those bytes varying frame to frame and, after a page-allocator spray, carrying the sprayed pattern; the same reproducer on an otherwise identical CONFIG_INIT_ON_ALLOC_DEFAULT_ON kernel leaks nothing, confirming the source is uninitialised allocation memory. Reaching it needs CAP_NET_ADMIN, which is self-satisfiable on a stock kernel through unprivileged user and network namespaces.

Assign the sub-option TLV length explicitly, which is 0 as the AUTO_MGR sub-TLV carries no payload, and append the alignment padding with skb_put_zero().

Discovered by XBOW, triaged by Baul Lee <[email protected]>

Fixes f7458934b079 ("net: bridge: mrp: Update the Test frames for MRA")
---
 net/bridge/br_mrp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/bridge/br_mrp.c +2 -1
index 3f7126a7d720..a5548f475604 100644
@@ -226,9 +226,10 @@ static struct sk_buff *br_mrp_alloc_test_skb(struct br_mrp *mrp,
 
 		sub_tlv = skb_put(skb, sizeof(*sub_tlv));
 		sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;
+		sub_tlv->length = 0x0;
 
 		/* 32 bit alligment shall be ensured therefore add 2 bytes */
-		skb_put(skb, MRP_OPT_PADDING);
+		skb_put_zero(skb, MRP_OPT_PADDING);
 	}
 
 	br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_END, 0x0);
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw
Quoted 12 lines · Baul Lee

br_mrp_alloc_test_skb() builds MRP test frames on an skb from dev_alloc_skb(), which does not zero the linear data area. On the MRA ring-role branch the sub-option TLV header is appended with

	sub_tlv = skb_put(skb, sizeof(*sub_tlv));
	sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;

leaving sub_tlv->length unwritten, and the two trailing alignment bytes are appended with a bare skb_put() that neither writes nor clears them. The surrounding oui and sub_opt regions are explicitly memset(0), which bounds the exposure to exactly these three bytes.

Quoted 9 lines

Every MRA MRP_Test frame therefore carries three bytes of stale page-allocator memory, at frame offsets 65 to 67, to any observer of the MRP control traffic. A capture on a kernel without CONFIG_INIT_ON_ALLOC_DEFAULT_ON shows those bytes varying frame to frame and, after a page-allocator spray, carrying the sprayed pattern; the same reproducer on an otherwise identical CONFIG_INIT_ON_ALLOC_DEFAULT_ON kernel leaks nothing, confirming the source is uninitialised allocation memory. Reaching it needs CAP_NET_ADMIN, which is self-satisfiable on a stock kernel through unprivileged user and network namespaces.

Drop this entire unnecessary paragraph (slop).

Quoted 10 lines

Assign the sub-option TLV length explicitly, which is 0 as the AUTO_MGR sub-TLV carries no payload, and append the alignment padding with skb_put_zero().

Discovered by XBOW, triaged by Baul Lee <[email protected]>

Fixes f7458934b079 ("net: bridge: mrp: Update the Test frames for MRA")

You don't need a reported-by tag since you've already signed off the patch.

net/bridge/br_mrp.c static struct sk_buff *br_mrp_alloc_test_skb(struct br_mrp *mrp, · line 227

Quoted 13 lines
---
 net/bridge/br_mrp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/bridge/br_mrp.c +0 -0
index 3f7126a7d720..a5548f475604 100644
@@ -226,9 +226,10 @@ static struct sk_buff *br_mrp_alloc_test_skb(struct br_mrp *mrp,
 
 		sub_tlv = skb_put(skb, sizeof(*sub_tlv));

if you use skb_put_zero here, you can drop the explicit zeroing below, in fact you can add the MRP_OPT_PADDING as well and move the comment above it then drop the second skb_put_zero entirely

Quoted 12 lines
net/bridge/br_mrp.c +2 -1
 		sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;
+		sub_tlv->length = 0x0;
 
 		/* 32 bit alligment shall be ensured therefore add 2 bytes */
-		skb_put(skb, MRP_OPT_PADDING);
+		skb_put_zero(skb, MRP_OPT_PADDING);
 	}
 
 	br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_END, 0x0);
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw
Quoted 23 lines · Nikolay Aleksandrov
Quoted 12 lines · Baul Lee

br_mrp_alloc_test_skb() builds MRP test frames on an skb from dev_alloc_skb(), which does not zero the linear data area. On the MRA ring-role branch the sub-option TLV header is appended with

	sub_tlv = skb_put(skb, sizeof(*sub_tlv));
	sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;

leaving sub_tlv->length unwritten, and the two trailing alignment bytes are appended with a bare skb_put() that neither writes nor clears them. The surrounding oui and sub_opt regions are explicitly memset(0), which bounds the exposure to exactly these three bytes.

Quoted 9 lines

Every MRA MRP_Test frame therefore carries three bytes of stale page-allocator memory, at frame offsets 65 to 67, to any observer of the MRP control traffic. A capture on a kernel without CONFIG_INIT_ON_ALLOC_DEFAULT_ON shows those bytes varying frame to frame and, after a page-allocator spray, carrying the sprayed pattern; the same reproducer on an otherwise identical CONFIG_INIT_ON_ALLOC_DEFAULT_ON kernel leaks nothing, confirming the source is uninitialised allocation memory. Reaching it needs CAP_NET_ADMIN, which is self-satisfiable on a stock kernel through unprivileged user and network namespaces.

Quoted 1 line

Drop this entire unnecessary paragraph (slop).

Hi Baul

Please be careful with this. AI slop will quickly damage your reputation with Reviewers and Maintainers. If you have a poor reputation, your patches are likely to be slower to get reviewed, get more examination and more minor problems pointed out. AI is a useful tool, but it is just a tool. You personally are responsible for everything in the patch, so it is up to you to decided if what the AI has generated is correct/useful.

Quoted 6 lines
Quoted 3 lines
Fixes f7458934b079 ("net: bridge: mrp: Update the Test frames for MRA")

You don't need a reported-by tag since you've already signed off the patch.

Please handle this for all the other patches you have posted to netdev.

It is a good idea to only post one patch, get review comments for all the errors you make, and learn from them. Only once you are confident you are likely to get everything correct can you start posting multiple patches in parallel. Posting lots of patches with the same error will also quickly damage your reputation.

Andrew

author
#3 lore raw

PATCH v2 1/1 net: bridge: mrp: fix uninitialised bytes on the wire

In reply to Baul Lee

br_mrp_alloc_test_skb() builds MRP test frames on an skb from dev_alloc_skb(), which does not clear the linear data area. On the MRA ring-role branch the sub-option TLV header is appended with

	sub_tlv = skb_put(skb, sizeof(*sub_tlv));
	sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;

so sub_tlv->length is never written, and the two trailing alignment bytes are appended with a bare skb_put() that does not clear them either. The neighbouring oui and sub_opt regions are explicitly zeroed, so three uninitialised bytes are left in every MRA MRP_Test frame that goes out.

Put the sub-option TLV header and the alignment padding in a single skb_put_zero(), which clears both. The AUTO_MGR sub-TLV carries no payload, so the zeroed length field is already the value it should have.

Fixes f7458934b079 ("net: bridge: mrp: Update the Test frames for MRA")

---
v2:
- fold the alignment padding into a single skb_put_zero() for the sub-option TLV header, dropping the explicit length assignment and the second skb_put() (Nikolay Aleksandrov)
- drop the paragraph about observing the leak, and the Reported-by tags

Link to v1: https://lore.kernel.org/netdev/[email protected]/

 net/bridge/br_mrp.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/bridge/br_mrp.c +2 -4
index 179d2470b..ef16d0703 100644
@@ -224,11 +224,9 @@ static struct sk_buff *br_mrp_alloc_test_skb(struct br_mrp *mrp,
 		sub_opt = skb_put(skb, sizeof(*sub_opt));
 		memset(sub_opt, 0x0, sizeof(*sub_opt));
 
-		sub_tlv = skb_put(skb, sizeof(*sub_tlv));
-		sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;
-
 		/* 32 bit alligment shall be ensured therefore add 2 bytes */
-		skb_put(skb, MRP_OPT_PADDING);
+		sub_tlv = skb_put_zero(skb, sizeof(*sub_tlv) + MRP_OPT_PADDING);
+		sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;
 	}
 
 	br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_END, 0x0);
Signature · 1 line
2.53.0
maintainer Acked-by on v2 1/1
#4 lore raw
Quoted 53 lines · Baul Lee

br_mrp_alloc_test_skb() builds MRP test frames on an skb from dev_alloc_skb(), which does not clear the linear data area. On the MRA ring-role branch the sub-option TLV header is appended with

	sub_tlv = skb_put(skb, sizeof(*sub_tlv));
	sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;

so sub_tlv->length is never written, and the two trailing alignment bytes are appended with a bare skb_put() that does not clear them either. The neighbouring oui and sub_opt regions are explicitly zeroed, so three uninitialised bytes are left in every MRA MRP_Test frame that goes out.

Put the sub-option TLV header and the alignment padding in a single skb_put_zero(), which clears both. The AUTO_MGR sub-TLV carries no payload, so the zeroed length field is already the value it should have.

Fixes f7458934b079 ("net: bridge: mrp: Update the Test frames for MRA")

---
v2:
- fold the alignment padding into a single skb_put_zero() for the sub-option TLV header, dropping the explicit length assignment and the second skb_put() (Nikolay Aleksandrov)
- drop the paragraph about observing the leak, and the Reported-by tags

Link to v1: https://lore.kernel.org/netdev/[email protected]/

 net/bridge/br_mrp.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/bridge/br_mrp.c +2 -4
index 179d2470b..ef16d0703 100644
@@ -224,11 +224,9 @@ static struct sk_buff *br_mrp_alloc_test_skb(struct br_mrp *mrp,
 		sub_opt = skb_put(skb, sizeof(*sub_opt));
 		memset(sub_opt, 0x0, sizeof(*sub_opt));
 
-		sub_tlv = skb_put(skb, sizeof(*sub_tlv));
-		sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;
-
 		/* 32 bit alligment shall be ensured therefore add 2 bytes */
-		skb_put(skb, MRP_OPT_PADDING);
+		sub_tlv = skb_put_zero(skb, sizeof(*sub_tlv) + MRP_OPT_PADDING);
+		sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;
 	}
 
 	br_mrp_skb_tlv(skb, BR_MRP_TLV_HEADER_END, 0x0);
Signature · 1 line
2.53.0

You should not send patches as replies, they should be sent on their own. Aside from that the patch looks good to me:

#5 lore raw
In reply to Baul Lee
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Wed, 29 Jul 2026 22:19:41 +0900 you wrote:

br_mrp_alloc_test_skb() builds MRP test frames on an skb from dev_alloc_skb(), which does not clear the linear data area. On the MRA ring-role branch the sub-option TLV header is appended with

	sub_tlv = skb_put(skb, sizeof(*sub_tlv));
	sub_tlv->type = BR_MRP_SUB_TLV_HEADER_TEST_AUTO_MGR;

[...]

Here is the summary with links:
- [net,v2] net: bridge: mrp: fix uninitialised bytes on the wire

    https://git.kernel.org/netdev/net/c/63488dba65ef

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html