Skip to contentSkip to conversation

ip6mr: prevent info-leak in ip6mr_cache_report()

PATCH Applied Henry Martin 4 participants 4 messages Nov 12 – Nov 16

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip6mr: prevent info-leak in ip6mr_cache_report()

The non-WHOLEPKT branch copies the IPv6 header at offset 0 and then appends 40 bytes with skb_put(), but the mrt6msg is written at offset 0 after skb_reset_transport_header(), so the appended 40 bytes are never initialized. They hold stale heap contents.

The report is queued to the mroute6 socket and copied into the IP6MRA_CREPORT_PKT netlink attribute, disclosing the stale bytes to user space. The stale bytes can contain kernel heap and image pointers, and the report is reachable from an unprivileged user namespace (MRT6_INIT in a new netns, plus the non-root RTNLGRP_IPV6_MROUTE_R group).

Use skb_put_zero() instead, as the IPv4 code does since commit 4f34002e2e376 ("ipmr: prevent info-leak in pmr_cache_report()").

This issue was discovered by Tencent CodeBuddy Security.

Fixes 7bc570c8b4f75 ("[IPV6] MROUTE: Support multicast forwarding.")
---
 net/ipv6/ip6mr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6mr.c +1 -1
index dd0638d3c3f95..b7ae220d6b21d 100644
@@ -1154,7 +1154,7 @@ static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt,
 	/*
 	 *	Add our header
 	 */
-	skb_put(skb, sizeof(*msg));
+	skb_put_zero(skb, sizeof(*msg));
 	skb_reset_transport_header(skb);
 	msg = (struct mrt6msg *)skb_transport_header(skb);
 
Signature · 1 line
2.43.7
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Henry Martin
Quoted 12 lines · Henry Martin

The non-WHOLEPKT branch copies the IPv6 header at offset 0 and then appends 40 bytes with skb_put(), but the mrt6msg is written at offset 0 after skb_reset_transport_header(), so the appended 40 bytes are never initialized. They hold stale heap contents.

The report is queued to the mroute6 socket and copied into the IP6MRA_CREPORT_PKT netlink attribute, disclosing the stale bytes to user space. The stale bytes can contain kernel heap and image pointers, and the report is reachable from an unprivileged user namespace (MRT6_INIT in a new netns, plus the non-root RTNLGRP_IPV6_MROUTE_R group).

Quoted 8 lines

Use skb_put_zero() instead, as the IPv4 code does since commit 4f34002e2e376 ("ipmr: prevent info-leak in pmr_cache_report()").

This issue was discovered by Tencent CodeBuddy Security.

Fixes 7bc570c8b4f75 ("[IPV6] MROUTE: Support multicast forwarding.")

Note that:

1. You're expected to answer to the bot with the requested information.

2. Better, avoid getting your patch flagged by the bot in the first place by putting the relevant information (a KMSAN trace in this case) in the commit message. See commit aa1799e93f5e ("ipmr, ip6mr: validate packets injected into the register vif on xmit"), for example.

Anyway, this code is quite bizarre. Unclear why it allocates room for 80 bytes, writes the IPv6 header to the first 40, then overwrites it with 'mrt6msg' and leaves the remaining 40 bytes as garbage.

I will follow up with the following diff after your patch is in net-next:

net/ipv6/ip6mr.c +2 -13
index b7ae220d6b21..31f0e1ef5601 100644
@@ -1107,7 +1107,7 @@ static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt,
 						+sizeof(*msg));
 	else
 #endif
-		skb = alloc_skb(sizeof(struct ipv6hdr) + sizeof(*msg), GFP_ATOMIC);
+		skb = alloc_skb(sizeof(*msg), GFP_ATOMIC);
 
 	if (!skb)
 		return -ENOBUFS;
@@ -1143,20 +1143,9 @@ static int ip6mr_cache_report(const struct mr_table *mrt, struct sk_buff *pkt,
 	} else
 #endif
 	{
-	/*
-	 *	Copy the IP header
-	 */
-
-	skb_put(skb, sizeof(struct ipv6hdr));
+	msg = skb_put(skb, sizeof(*msg));
 	skb_reset_network_header(skb);
-	skb_copy_to_linear_data(skb, ipv6_hdr(pkt), sizeof(struct ipv6hdr));
-
-	/*
-	 *	Add our header
-	 */
-	skb_put_zero(skb, sizeof(*msg));
 	skb_reset_transport_header(skb);
-	msg = (struct mrt6msg *)skb_transport_header(skb);
 
 	msg->im6_mbz = 0;
 	msg->im6_msgtype = assert;
#3 lore raw
In reply to Henry Martin
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 5 lines · On Thu, 12 Nov 2026 12:24:15 +0800 you wrote:

The non-WHOLEPKT branch copies the IPv6 header at offset 0 and then appends 40 bytes with skb_put(), but the mrt6msg is written at offset 0 after skb_reset_transport_header(), so the appended 40 bytes are never initialized. They hold stale heap contents.

Quoted 8 lines

The report is queued to the mroute6 socket and copied into the IP6MRA_CREPORT_PKT netlink attribute, disclosing the stale bytes to user space. The stale bytes can contain kernel heap and image pointers, and the report is reachable from an unprivileged user namespace (MRT6_INIT in a new netns, plus the non-root RTNLGRP_IPV6_MROUTE_R group).

[...]

Here is the summary with links:
- [net] ip6mr: prevent info-leak in ip6mr_cache_report()

    https://git.kernel.org/netdev/net/c/ea538b5790ee

You are awesome, thank you!

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