netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] ipv6: Unlink sibling route in case of failure
@ 2019-07-17 20:39 Ido Schimmel
  2019-07-18 14:21 ` David Ahern
  0 siblings, 1 reply; 3+ messages in thread
From: Ido Schimmel @ 2019-07-17 20:39 UTC (permalink / raw)
  To: netdev; +Cc: davem, dsahern, alexpe, mlxsw, Ido Schimmel

From: Ido Schimmel <idosch@mellanox.com>

When a route needs to be appended to an existing multipath route,
fib6_add_rt2node() first appends it to the siblings list and increments
the number of sibling routes on each sibling.

Later, the function notifies the route via call_fib6_entry_notifiers().
In case the notification is vetoed, the route is not unlinked from the
siblings list, which can result in a use-after-free.

Fix this by unlinking the route from the siblings list before returning
an error.

Audited the rest of the call sites from which the FIB notification chain
is called and could not find more problems.

Fixes: 2233000cba40 ("net/ipv6: Move call_fib6_entry_notifiers up for route adds")
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Reported-by: Alexander Petrovskiy <alexpe@mellanox.com>
---
Dave, this will not apply cleanly to stable trees due to recent changes
in net-next. I can prepare another patch for stable if needed.
---
 net/ipv6/ip6_fib.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
index 49884f96232b..87f47bc55c5e 100644
--- a/net/ipv6/ip6_fib.c
+++ b/net/ipv6/ip6_fib.c
@@ -1151,8 +1151,24 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
 			err = call_fib6_entry_notifiers(info->nl_net,
 							FIB_EVENT_ENTRY_ADD,
 							rt, extack);
-			if (err)
+			if (err) {
+				struct fib6_info *sibling, *next_sibling;
+
+				/* If the route has siblings, then it first
+				 * needs to be unlinked from them.
+				 */
+				if (!rt->fib6_nsiblings)
+					return err;
+
+				list_for_each_entry_safe(sibling, next_sibling,
+							 &rt->fib6_siblings,
+							 fib6_siblings)
+					sibling->fib6_nsiblings--;
+				rt->fib6_nsiblings = 0;
+				list_del_init(&rt->fib6_siblings);
+				rt6_multipath_rebalance(next_sibling);
 				return err;
+			}
 		}
 
 		rcu_assign_pointer(rt->fib6_next, iter);
-- 
2.21.0


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

* Re: [PATCH net] ipv6: Unlink sibling route in case of failure
  2019-07-17 20:39 [PATCH net] ipv6: Unlink sibling route in case of failure Ido Schimmel
@ 2019-07-18 14:21 ` David Ahern
  2019-07-18 19:03   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: David Ahern @ 2019-07-18 14:21 UTC (permalink / raw)
  To: Ido Schimmel, netdev; +Cc: davem, alexpe, mlxsw, Ido Schimmel

On 7/17/19 2:39 PM, Ido Schimmel wrote:
> From: Ido Schimmel <idosch@mellanox.com>
> 
> When a route needs to be appended to an existing multipath route,
> fib6_add_rt2node() first appends it to the siblings list and increments
> the number of sibling routes on each sibling.
> 
> Later, the function notifies the route via call_fib6_entry_notifiers().
> In case the notification is vetoed, the route is not unlinked from the
> siblings list, which can result in a use-after-free.
> 
> Fix this by unlinking the route from the siblings list before returning
> an error.
> 
> Audited the rest of the call sites from which the FIB notification chain
> is called and could not find more problems.
> 
> Fixes: 2233000cba40 ("net/ipv6: Move call_fib6_entry_notifiers up for route adds")
> Signed-off-by: Ido Schimmel <idosch@mellanox.com>
> Reported-by: Alexander Petrovskiy <alexpe@mellanox.com>
> ---
> Dave, this will not apply cleanly to stable trees due to recent changes
> in net-next. I can prepare another patch for stable if needed.
> ---
>  net/ipv6/ip6_fib.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 

Thanks for the fix, Ido. I can help with the ports as well.

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


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

* Re: [PATCH net] ipv6: Unlink sibling route in case of failure
  2019-07-18 14:21 ` David Ahern
@ 2019-07-18 19:03   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2019-07-18 19:03 UTC (permalink / raw)
  To: dsahern; +Cc: idosch, netdev, alexpe, mlxsw, idosch

From: David Ahern <dsahern@gmail.com>
Date: Thu, 18 Jul 2019 08:21:01 -0600

> On 7/17/19 2:39 PM, Ido Schimmel wrote:
>> From: Ido Schimmel <idosch@mellanox.com>
>> 
>> When a route needs to be appended to an existing multipath route,
>> fib6_add_rt2node() first appends it to the siblings list and increments
>> the number of sibling routes on each sibling.
>> 
>> Later, the function notifies the route via call_fib6_entry_notifiers().
>> In case the notification is vetoed, the route is not unlinked from the
>> siblings list, which can result in a use-after-free.
>> 
>> Fix this by unlinking the route from the siblings list before returning
>> an error.
>> 
>> Audited the rest of the call sites from which the FIB notification chain
>> is called and could not find more problems.
>> 
>> Fixes: 2233000cba40 ("net/ipv6: Move call_fib6_entry_notifiers up for route adds")
>> Signed-off-by: Ido Schimmel <idosch@mellanox.com>
>> Reported-by: Alexander Petrovskiy <alexpe@mellanox.com>
>> ---
>> Dave, this will not apply cleanly to stable trees due to recent changes
>> in net-next. I can prepare another patch for stable if needed.
>> ---
>>  net/ipv6/ip6_fib.c | 18 +++++++++++++++++-
>>  1 file changed, 17 insertions(+), 1 deletion(-)
>> 
> 
> Thanks for the fix, Ido. I can help with the ports as well.
> 
> Reviewed-by: David Ahern <dsahern@gmail.com>

Applied and queued up for -stable.

Since I've done a bunch of ipv6 routing fix backports through David's
refactoring and cleanups, I'll give this one a try too :-) If I run
into problems I'll ask for help.

Thanks.

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17 20:39 [PATCH net] ipv6: Unlink sibling route in case of failure Ido Schimmel
2019-07-18 14:21 ` David Ahern
2019-07-18 19:03   ` 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).