netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: ipv4: Make "ip route get" match iif lo rules again.
@ 2018-01-11  9:36 Lorenzo Colitti
  2018-01-11 13:55 ` David Ahern
  2018-01-15 18:54 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Lorenzo Colitti @ 2018-01-11  9:36 UTC (permalink / raw)
  To: netdev; +Cc: davem, dsahern, rami.rosen, nikolay, roopa, Lorenzo Colitti

Commit 3765d35ed8b9 ("net: ipv4: Convert inet_rtm_getroute to rcu
versions of route lookup") broke "ip route get" in the presence
of rules that specify iif lo.

Host-originated traffic always has iif lo, because
ip_route_output_key_hash and ip6_route_output_flags set the flow
iif to LOOPBACK_IFINDEX. Thus, putting "iif lo" in an ip rule is a
convenient way to select only originated traffic and not forwarded
traffic.

inet_rtm_getroute used to match these rules correctly because
even though it sets the flow iif to 0, it called
ip_route_output_key which overwrites iif with LOOPBACK_IFINDEX.
But now that it calls ip_route_output_key_hash_rcu, the ifindex
will remain 0 and not match the iif lo in the rule. As a result,
"ip route get" will return ENETUNREACH.

Fixes: 3765d35ed8b9 ("net: ipv4: Convert inet_rtm_getroute to rcu versions of route lookup")
Tested: https://android.googlesource.com/kernel/tests/+/master/net/test/multinetwork_test.py passes again
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
---
 net/ipv4/route.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 43b69af242..4e153b23bc 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2762,6 +2762,7 @@ static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,
 		if (err == 0 && rt->dst.error)
 			err = -rt->dst.error;
 	} else {
+		fl4.flowi4_iif = LOOPBACK_IFINDEX;
 		rt = ip_route_output_key_hash_rcu(net, &fl4, &res, skb);
 		err = 0;
 		if (IS_ERR(rt))
-- 
2.16.0.rc1.238.g530d649a79-goog

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ipv4: Make "ip route get" match iif lo rules again.
  2018-01-11  9:36 [PATCH net] net: ipv4: Make "ip route get" match iif lo rules again Lorenzo Colitti
@ 2018-01-11 13:55 ` David Ahern
  2018-01-15 18:54 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Ahern @ 2018-01-11 13:55 UTC (permalink / raw)
  To: Lorenzo Colitti, netdev; +Cc: davem, rami.rosen, nikolay, roopa

On 1/11/18 2:36 AM, Lorenzo Colitti wrote:
> Commit 3765d35ed8b9 ("net: ipv4: Convert inet_rtm_getroute to rcu
> versions of route lookup") broke "ip route get" in the presence
> of rules that specify iif lo.
> 
> Host-originated traffic always has iif lo, because
> ip_route_output_key_hash and ip6_route_output_flags set the flow
> iif to LOOPBACK_IFINDEX. Thus, putting "iif lo" in an ip rule is a
> convenient way to select only originated traffic and not forwarded
> traffic.
> 
> inet_rtm_getroute used to match these rules correctly because
> even though it sets the flow iif to 0, it called
> ip_route_output_key which overwrites iif with LOOPBACK_IFINDEX.
> But now that it calls ip_route_output_key_hash_rcu, the ifindex
> will remain 0 and not match the iif lo in the rule. As a result,
> "ip route get" will return ENETUNREACH.
> 
> Fixes: 3765d35ed8b9 ("net: ipv4: Convert inet_rtm_getroute to rcu versions of route lookup")
> Tested: https://android.googlesource.com/kernel/tests/+/master/net/test/multinetwork_test.py passes again
> Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
> ---
>  net/ipv4/route.c | 1 +
>  1 file changed, 1 insertion(+)
> 

Missed that. Thanks for fixing.

Acked-by: David Ahern <dsahern@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ipv4: Make "ip route get" match iif lo rules again.
  2018-01-11  9:36 [PATCH net] net: ipv4: Make "ip route get" match iif lo rules again Lorenzo Colitti
  2018-01-11 13:55 ` David Ahern
@ 2018-01-15 18:54 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2018-01-15 18:54 UTC (permalink / raw)
  To: lorenzo; +Cc: netdev, dsahern, rami.rosen, nikolay, roopa

From: Lorenzo Colitti <lorenzo@google.com>
Date: Thu, 11 Jan 2018 18:36:26 +0900

> Commit 3765d35ed8b9 ("net: ipv4: Convert inet_rtm_getroute to rcu
> versions of route lookup") broke "ip route get" in the presence
> of rules that specify iif lo.
> 
> Host-originated traffic always has iif lo, because
> ip_route_output_key_hash and ip6_route_output_flags set the flow
> iif to LOOPBACK_IFINDEX. Thus, putting "iif lo" in an ip rule is a
> convenient way to select only originated traffic and not forwarded
> traffic.
> 
> inet_rtm_getroute used to match these rules correctly because
> even though it sets the flow iif to 0, it called
> ip_route_output_key which overwrites iif with LOOPBACK_IFINDEX.
> But now that it calls ip_route_output_key_hash_rcu, the ifindex
> will remain 0 and not match the iif lo in the rule. As a result,
> "ip route get" will return ENETUNREACH.
> 
> Fixes: 3765d35ed8b9 ("net: ipv4: Convert inet_rtm_getroute to rcu versions of route lookup")
> Tested: https://android.googlesource.com/kernel/tests/+/master/net/test/multinetwork_test.py passes again
> Signed-off-by: Lorenzo Colitti <lorenzo@google.com>

Applied and queued up for -stable, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-01-15 18:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-11  9:36 [PATCH net] net: ipv4: Make "ip route get" match iif lo rules again Lorenzo Colitti
2018-01-11 13:55 ` David Ahern
2018-01-15 18:54 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).