netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] route: set the deleted fnhe fnhe_daddr to 0 in ip_del_fnhe to fix a race
@ 2019-03-08  6:50 Xin Long
  2019-03-08 15:33 ` David Ahern
  2019-03-08 18:51 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Xin Long @ 2019-03-08  6:50 UTC (permalink / raw)
  To: network dev; +Cc: davem, David Ahern, Jon Maxwell, jmaxwell

The race occurs in __mkroute_output() when 2 threads lookup a dst:

  CPU A                 CPU B
  find_exception()
                        find_exception() [fnhe expires]
                        ip_del_fnhe() [fnhe is deleted]
  rt_bind_exception()

In rt_bind_exception() it will bind a deleted fnhe with the new dst, and
this dst will get no chance to be freed. It causes a dev defcnt leak and
consecutive dmesg warnings:

  unregister_netdevice: waiting for ethX to become free. Usage count = 1

Especially thinks Jon to identify the issue.

This patch fixes it by setting fnhe_daddr to 0 in ip_del_fnhe() to stop
binding the deleted fnhe with a new dst when checking fnhe's fnhe_daddr
and daddr in rt_bind_exception().

It works as both ip_del_fnhe() and rt_bind_exception() are protected by
fnhe_lock and the fhne is freed by kfree_rcu().

Fixes: deed49df7390 ("route: check and remove route cache when we get route")
Signed-off-by: Jon Maxwell <jmaxwell37@gmail.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/ipv4/route.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 5163b64..b0eb4fa 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1303,6 +1303,10 @@ static void ip_del_fnhe(struct fib_nh *nh, __be32 daddr)
 		if (fnhe->fnhe_daddr == daddr) {
 			rcu_assign_pointer(*fnhe_p, rcu_dereference_protected(
 				fnhe->fnhe_next, lockdep_is_held(&fnhe_lock)));
+			/* set fnhe_daddr to 0 to ensure it won't bind with
+			 * new dsts in rt_bind_exception().
+			 */
+			fnhe->fnhe_daddr = 0;
 			fnhe_flush_routes(fnhe);
 			kfree_rcu(fnhe, rcu);
 			break;
-- 
2.1.0


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

* Re: [PATCH net] route: set the deleted fnhe fnhe_daddr to 0 in ip_del_fnhe to fix a race
  2019-03-08  6:50 [PATCH net] route: set the deleted fnhe fnhe_daddr to 0 in ip_del_fnhe to fix a race Xin Long
@ 2019-03-08 15:33 ` David Ahern
  2019-03-08 18:51 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Ahern @ 2019-03-08 15:33 UTC (permalink / raw)
  To: Xin Long, network dev; +Cc: davem, Jon Maxwell, jmaxwell

On 3/7/19 11:50 PM, Xin Long wrote:
> The race occurs in __mkroute_output() when 2 threads lookup a dst:
> 
>   CPU A                 CPU B
>   find_exception()
>                         find_exception() [fnhe expires]
>                         ip_del_fnhe() [fnhe is deleted]
>   rt_bind_exception()
> 
> In rt_bind_exception() it will bind a deleted fnhe with the new dst, and
> this dst will get no chance to be freed. It causes a dev defcnt leak and
> consecutive dmesg warnings:
> 
>   unregister_netdevice: waiting for ethX to become free. Usage count = 1
> 
> Especially thinks Jon to identify the issue.
> 
> This patch fixes it by setting fnhe_daddr to 0 in ip_del_fnhe() to stop
> binding the deleted fnhe with a new dst when checking fnhe's fnhe_daddr
> and daddr in rt_bind_exception().
> 
> It works as both ip_del_fnhe() and rt_bind_exception() are protected by
> fnhe_lock and the fhne is freed by kfree_rcu().
> 
> Fixes: deed49df7390 ("route: check and remove route cache when we get route")
> Signed-off-by: Jon Maxwell <jmaxwell37@gmail.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
>  net/ipv4/route.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 

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



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

* Re: [PATCH net] route: set the deleted fnhe fnhe_daddr to 0 in ip_del_fnhe to fix a race
  2019-03-08  6:50 [PATCH net] route: set the deleted fnhe fnhe_daddr to 0 in ip_del_fnhe to fix a race Xin Long
  2019-03-08 15:33 ` David Ahern
@ 2019-03-08 18:51 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-03-08 18:51 UTC (permalink / raw)
  To: lucien.xin; +Cc: netdev, dsahern, jmaxwell37, jmaxwell

From: Xin Long <lucien.xin@gmail.com>
Date: Fri,  8 Mar 2019 14:50:54 +0800

> The race occurs in __mkroute_output() when 2 threads lookup a dst:
> 
>   CPU A                 CPU B
>   find_exception()
>                         find_exception() [fnhe expires]
>                         ip_del_fnhe() [fnhe is deleted]
>   rt_bind_exception()
> 
> In rt_bind_exception() it will bind a deleted fnhe with the new dst, and
> this dst will get no chance to be freed. It causes a dev defcnt leak and
> consecutive dmesg warnings:
> 
>   unregister_netdevice: waiting for ethX to become free. Usage count = 1
> 
> Especially thinks Jon to identify the issue.

I did "s/thinks/thanks/" here.

> This patch fixes it by setting fnhe_daddr to 0 in ip_del_fnhe() to stop
> binding the deleted fnhe with a new dst when checking fnhe's fnhe_daddr
> and daddr in rt_bind_exception().
> 
> It works as both ip_del_fnhe() and rt_bind_exception() are protected by
> fnhe_lock and the fhne is freed by kfree_rcu().
> 
> Fixes: deed49df7390 ("route: check and remove route cache when we get route")
> Signed-off-by: Jon Maxwell <jmaxwell37@gmail.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Applied and queues up for -stable, thank you.

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

end of thread, other threads:[~2019-03-08 18:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-08  6:50 [PATCH net] route: set the deleted fnhe fnhe_daddr to 0 in ip_del_fnhe to fix a race Xin Long
2019-03-08 15:33 ` David Ahern
2019-03-08 18:51 ` 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).