* [PATCH net-next] ipv6: check mc_forwarding before calling ip6mr_get_route()
@ 2026-11-11 9:45 Wenbo Sun
2026-11-12 2:14 ` Hangbin Liu
0 siblings, 1 reply; 3+ messages in thread
From: Wenbo Sun @ 2026-11-11 9:45 UTC (permalink / raw)
To: David Ahern, Ido Schimmel, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: Simon Horman, netdev, linux-kernel, sunwenbo, 1342116488
When CONFIG_IPV6_MROUTE is enabled, rt6_fill_node() unconditionally calls
ip6mr_get_route() whenever an input interface is specified and the
destination address is multicast.
However, if multicast routing is not active (i.e. no multicast routing
daemon is running and mc_forwarding is 0), there is no matching (S,G)
multicast routing cache entry, and skb->dev is NULL in the synthetic route
query skb allocated by inet6_rtm_getroute(). As a result, ip6mr_get_route()
returns -ENODEV, which causes rt6_fill_node() to jump to nla_put_failure
and return -EMSGSIZE to userspace ("RTNETLINK answers: Message too long").
In contrast, IPv4 counterpart rt_fill_info() checks
IPV4_DEVCONF_ALL_RO(net, MC_FORWARDING) before attempting to query
ipmr_get_route(), and falls back to emitting RTA_IIF and normal local
delivery route attributes when multicast routing is not enabled.
This discrepancy was identified during code audit of multicast route get
handling. The failure was confirmed on a UML kernel: querying an IPv6
multicast route with an input interface ("ip -6 route get <mcast_addr>
from <src_addr> ...") failed with -EMSGSIZE on an unpatched kernel.
Align IPv6 behavior with IPv4 by checking whether mc_forwarding is active
(atomic_read(&net->ipv6.devconf_all->mc_forwarding)) before calling
ip6mr_get_route(). When mc_forwarding is 0, rt6_fill_node() proceeds to
output RTA_IIF and normal route attributes.
Tested:
- On a UML kernel with CONFIG_IPV6_MROUTE=y, verified that
"ip -6 route get ff0e::1 from 2001:db8::3 ..." with an input interface
now succeeds and outputs the route instead of failing with -EMSGSIZE.
- Verified that IPv6 unicast route get and multicast route get without
an input interface continue to work as expected.
- 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@cmss.chinamobile.com>
---
net/ipv6/route.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 2eb884558c24..6dd4a70f6490 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -5862,7 +5862,8 @@ 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)) {
+ if (ipv6_addr_is_multicast(&rt6_dst->addr) &&
+ atomic_read(&net->ipv6.devconf_all->mc_forwarding)) {
int err = ip6mr_get_route(net, skb, rtm, portid);
if (err == 0)
--
2.33.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ipv6: check mc_forwarding before calling ip6mr_get_route()
2026-11-11 9:45 [PATCH net-next] ipv6: check mc_forwarding before calling ip6mr_get_route() Wenbo Sun
@ 2026-11-12 2:14 ` Hangbin Liu
2026-11-12 7:15 ` Wenbo Sun
0 siblings, 1 reply; 3+ messages in thread
From: Hangbin Liu @ 2026-11-12 2:14 UTC (permalink / raw)
To: Wenbo Sun
Cc: David Ahern, Ido Schimmel, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, linux-kernel,
1342116488
Hi Wenbo,
On Wed, Nov 11, 2026 at 05:45:28PM +0800, Wenbo Sun wrote:
> When CONFIG_IPV6_MROUTE is enabled, rt6_fill_node() unconditionally calls
> ip6mr_get_route() whenever an input interface is specified and the
> destination address is multicast.
>
> However, if multicast routing is not active (i.e. no multicast routing
> daemon is running and mc_forwarding is 0), there is no matching (S,G)
> multicast routing cache entry, and skb->dev is NULL in the synthetic route
> query skb allocated by inet6_rtm_getroute(). As a result, ip6mr_get_route()
> returns -ENODEV, which causes rt6_fill_node() to jump to nla_put_failure
> and return -EMSGSIZE to userspace ("RTNETLINK answers: Message too long").
>
> In contrast, IPv4 counterpart rt_fill_info() checks
> IPV4_DEVCONF_ALL_RO(net, MC_FORWARDING) before attempting to query
> ipmr_get_route(), and falls back to emitting RTA_IIF and normal local
> delivery route attributes when multicast routing is not enabled.
>
> This discrepancy was identified during code audit of multicast route get
> handling. The failure was confirmed on a UML kernel: querying an IPv6
> multicast route with an input interface ("ip -6 route get <mcast_addr>
> from <src_addr> ...") failed with -EMSGSIZE on an unpatched kernel.
>
> Align IPv6 behavior with IPv4 by checking whether mc_forwarding is active
> (atomic_read(&net->ipv6.devconf_all->mc_forwarding)) before calling
> ip6mr_get_route(). When mc_forwarding is 0, rt6_fill_node() proceeds to
> output RTA_IIF and normal route attributes.
>
> Tested:
> - On a UML kernel with CONFIG_IPV6_MROUTE=y, verified that
> "ip -6 route get ff0e::1 from 2001:db8::3 ..." with an input interface
> now succeeds and outputs the route instead of failing with -EMSGSIZE.
> - Verified that IPv6 unicast route get and multicast route get without
> an input interface continue to work as expected.
> - 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@cmss.chinamobile.com>
> ---
> net/ipv6/route.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 2eb884558c24..6dd4a70f6490 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -5862,7 +5862,8 @@ 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)) {
> + if (ipv6_addr_is_multicast(&rt6_dst->addr) &&
> + atomic_read(&net->ipv6.devconf_all->mc_forwarding)) {
> int err = ip6mr_get_route(net, skb, rtm, portid);
>
> if (err == 0)
In commit fd61c6ba313d ("net: ipv6: remove nowait arg to rt6_fill_node"),
David Ahern removed the nowait arg. Should we still return immediately
after err == 0? Also later if (err < 0), it still goto nla_put_failure
and return -EMSGSIZE. Maybe we can carry the err to the end and return
a more meaningful reason?
Anyway the added checking makes sense to me.
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ipv6: check mc_forwarding before calling ip6mr_get_route()
2026-11-12 2:14 ` Hangbin Liu
@ 2026-11-12 7:15 ` Wenbo Sun
0 siblings, 0 replies; 3+ messages in thread
From: Wenbo Sun @ 2026-11-12 7:15 UTC (permalink / raw)
To: Hangbin Liu
Cc: David Ahern, Ido Schimmel, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, netdev, linux-kernel,
sunwenbo, 1342116488
Hi Hangbin,
Thanks for the review and the Reviewed-by tag!
On Thu, Nov 12, 2026 at 02:14:50AM +0000, Hangbin Liu wrote:
> In commit fd61c6ba313d ("net: ipv6: remove nowait arg to rt6_fill_node"),
> David Ahern removed the nowait arg. Should we still return immediately
> after err == 0? Also later if (err < 0), it still goto nla_put_failure
> and return -EMSGSIZE. Maybe we can carry the err to the end and return
> a more meaningful reason?
>
> Anyway the added checking makes sense to me.
>
> Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
Both are very good observations on the existing ip6mr_get_route() error
handling in rt6_fill_node():
1) Regarding `if (err == 0) return 0;`:
Commit fd61c6ba313d only removed the unused `nowait` parameter (whose
value was always 0) and kept the pre-existing `!nowait && err == 0`
early return, mirroring IPv4 rt_fill_info(). Returning 0 from
ip6mr_get_route() means a cache miss was queued via
ip6mr_cache_unresolved() on nl_queries for asynchronous resolution;
falling through in rt6_fill_node() would append normal FIB attributes
without RTA_IIF.
That said, looking closely at inet6_rtm_getroute(), `skb->dev` is
currently never assigned there (unlike inet_rtm_getroute() in IPv4),
so on a cache miss ip6mr_get_route() takes `if (!dev || ...)` and
returns -ENODEV before ever reaching ip6mr_cache_unresolved(). Even
if `err == 0` were reached, returning 0 early skips nlmsg_end() while
inet6_rtm_getroute() still calls rtnl_unicast() when `err >= 0`.
Reworking that path would require changes in ip6mr.c and
inet6_rtm_getroute(), which goes beyond this patch's scope.
2) Regarding returning the real negative `err` instead of -EMSGSIZE:
Agreed -- ip6mr_get_route() can return -ENOENT, -ENODEV, -ENOMEM, or
-ENOBUFS, and jumping to nla_put_failure masks all of them as
-EMSGSIZE ("Message too long") even when mc_forwarding is enabled.
Among all callers of rt6_fill_node(), only inet6_rtm_getroute() passes
a non-zero iif and propagates negative errors back to userspace, so
initializing `int err = -EMSGSIZE;` and returning `err` at the failure
label looks safe and much cleaner.
To make it easy to review both together while keeping each change clear,
I plan to split this into a 2-patch [PATCH net-next v2 1/2] + [2/2]
series after the 24-hour resend window:
- Patch 1/2: check mc_forwarding before calling ip6mr_get_route()
(carrying your Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>).
- Patch 2/2: preserve and return the negative error from
ip6mr_get_route() in rt6_fill_node() instead of -EMSGSIZE.
Thanks,
Wenbo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-12 7:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11 9:45 [PATCH net-next] ipv6: check mc_forwarding before calling ip6mr_get_route() Wenbo Sun
2026-11-12 2:14 ` Hangbin Liu
2026-11-12 7:15 ` Wenbo Sun
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox