netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Ahern <dsa@cumulusnetworks.com>,
	Eric Dumazet <edumazet@google.com>,
	"David S . Miller" <davem@davemloft.net>
Cc: netdev <netdev@vger.kernel.org>
Subject: Re: [PATCH net] net: ipv6: prevent use after free in ip6_route_mpath_notify()
Date: Sun, 3 Jun 2018 07:31:24 -0700	[thread overview]
Message-ID: <4dfbdd4b-947b-bbf7-27f3-abbd48a817b4@gmail.com> (raw)
In-Reply-To: <4b46d531-904b-6e5f-67ce-a275f0826d47@cumulusnetworks.com>



On 06/03/2018 07:01 AM, David Ahern wrote:
> On 6/3/18 7:35 AM, Eric Dumazet wrote:
>> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
>> index f4d61736c41abe8cd7f439c4a37100e90c1eacca..830eefdbdb6734eb81ea0322fb6077ee20be1889 100644
>> --- a/net/ipv6/route.c
>> +++ b/net/ipv6/route.c
>> @@ -4263,7 +4263,9 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
>>  
>>  	err_nh = NULL;
>>  	list_for_each_entry(nh, &rt6_nh_list, next) {
>> +		dst_release(&rt_last->dst);
>>  		rt_last = nh->rt6_info;
>> +		dst_hold(&rt_last->dst);
>>  		err = __ip6_ins_rt(nh->rt6_info, info, &nh->mxc, extack);
>>  		/* save reference to first route for notification */
>>  		if (!rt_notif && !err)
>> @@ -4317,7 +4319,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
>>  		list_del(&nh->next);
>>  		kfree(nh);
>>  	}
>> -
>> +	dst_release(&rt_last->dst);
>>  	return err;
>>  }
> 
> Since the rtnl lock is held, a successfully inserted route can not be
> removed until ip6_route_multipath_add finishes. This is a simpler change
> that works with net-next as well:

Your patch changes the intent of your original commit.

It seems you wanted rt_last to point to the last attempted insertion,
not the last successful one ?

Or have I misunderstood, and not only we had a use-after-free, but also
a semantic error ?


> 
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index f4d61736c41a..1684197c189f 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -4263,11 +4263,12 @@ static int ip6_route_multipath_add(struct
> fib6_config *cfg,
> 
>         err_nh = NULL;
>         list_for_each_entry(nh, &rt6_nh_list, next) {
> -               rt_last = nh->rt6_info;
>                 err = __ip6_ins_rt(nh->rt6_info, info, &nh->mxc, extack);
>                 /* save reference to first route for notification */
>                 if (!rt_notif && !err)
>                         rt_notif = nh->rt6_info;
> +               if (!err)
> +                       rt_last = nh->rt6_info;
> 
>                 /* nh->rt6_info is used or freed at this point, reset to
> NULL*/
>                 nh->rt6_info = NULL;
> 
> 
> Is there a reproducer for the syzbot case?

Not yet.

  reply	other threads:[~2018-06-03 14:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-03 13:35 [PATCH net] net: ipv6: prevent use after free in ip6_route_mpath_notify() Eric Dumazet
2018-06-03 14:01 ` David Ahern
2018-06-03 14:31   ` Eric Dumazet [this message]
2018-06-03 14:46     ` David Ahern
2018-06-04  2:39       ` Eric Dumazet
2018-06-03 14:40   ` David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4dfbdd4b-947b-bbf7-27f3-abbd48a817b4@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dsa@cumulusnetworks.com \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).