[PATCH net-next v3 1/2] ipv6: check mc_forwarding before calling ip6mr_get_route()
From: Wenbo Sun
Date: Sun Nov 15 2026 - 20:48:28 EST
When CONFIG_IPV6_MROUTE is enabled, rt6_fill_node() currently calls
ip6mr_get_route() whenever an input interface (RTA_IIF) is specified and
the route destination is multicast.
However, inet6_rtm_getroute() does not set skb->dev on the newly
allocated reply skb, and the looked-up rt6_info carries the matched FIB6
prefix (such as ff00::/8 from addrconf_add_mroute()) rather than the
queried (S,G) addresses. As a result, when multicast forwarding is
disabled (mc_forwarding is 0), ip6mr_get_route() falls into the
cache-miss check and returns -ENODEV, causing rt6_fill_node() to jump to
nla_put_failure and report -EMSGSIZE ("RTNETLINK answers: Message too
long") to userspace. Similarly, interface-local and link-local multicast
groups are never forwarded by ip6_mc_input(), so querying them with
mc_forwarding enabled also enters ip6mr_get_route() and fails instead of
reporting the local route.
In contrast, the IPv4 counterpart rt_fill_info() guards ipmr_get_route()
with !ipv4_is_local_multicast(dst) and IPV4_DEVCONF_ALL_RO(net,
MC_FORWARDING), falling back to emitting RTA_IIF and normal route
attributes.
To align IPv6 behavior with IPv4 and ip6_mc_input(), check that
mc_forwarding is non-zero and that the destination (dest when available,
otherwise rt6_dst->addr) is neither interface-local (IPV6_ADDR_LOOPBACK)
nor link-local (IPV6_ADDR_LINKLOCAL) multicast before calling
ip6mr_get_route().
This discrepancy was identified with the assistance of an LLM-based code
review comparing IPv4 and IPv6 multicast route get handling, confirmed
on a UML kernel where multicast route queries with an input interface
failed on an unpatched kernel, and verified in UML that routable
multicast queries with mc_forwarding disabled as well as link-local
(ff02::1) and interface-local (ff01::1) queries with mc_forwarding
enabled now succeed and report RTA_IIF.
Built with W=1 on UML, x86_64 allmodconfig, and x86_64 allyesconfig with
zero new warnings or errors.
Signed-off-by: Wenbo Sun <sunwenbo@xxxxxxxxxxxxxxxxxxxx>
---
net/ipv6/route.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 1b2dcc066e19..27597d149672 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -5868,7 +5868,12 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
#endif
if (iif) {
#ifdef CONFIG_IPV6_MROUTE
- if (ipv6_addr_is_multicast(&rt6_dst->addr)) {
+ const struct in6_addr *mc_dst = dest ? : &rt6_dst->addr;
+
+ if (ipv6_addr_is_multicast(mc_dst) &&
+ !(ipv6_addr_type(mc_dst) &
+ (IPV6_ADDR_LOOPBACK | IPV6_ADDR_LINKLOCAL)) &&
+ atomic_read(&net->ipv6.devconf_all->mc_forwarding)) {
int err = ip6mr_get_route(net, skb, rtm, portid);
if (err == 0)
--
2.33.0