All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Borkmann <dborkman@redhat.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
	Salam Noureddine <noureddine@aristanetworks.com>,
	Ben Greear <greearb@candelatech.com>
Subject: Re: [PATCH net v2] packet: fix use after free race in send path when dev is released
Date: Thu, 21 Nov 2013 16:28:43 +0100	[thread overview]
Message-ID: <528E26AB.8020501@redhat.com> (raw)
In-Reply-To: <1385047624.10637.48.camel@edumazet-glaptop2.roam.corp.google.com>

On 11/21/2013 04:27 PM, Eric Dumazet wrote:
> On Thu, 2013-11-21 at 16:02 +0100, Daniel Borkmann wrote:
>
>>
>> That was also my first thought, but Salam pointed out to me, that in case
>> we have a situation such as ...
>>
>> in packet_cached_dev_get():
>>       rcu_read_lock();
>>       dev = rcu_dereference(po->cached_dev);      in packet_notifier():
>>                                                   ---> CPU1: dev_put(po->prot_hook.dev);
>> ---> CPU0:
>>       if (dev)
>> 	dev_hold(dev);
>>       rcu_read_unlock();
>>
>> ... we could reach a refcount of 0, before we increase it back to 1. Not sure
>> if this can actually happen, maybe in preemptible RCU where read-side critical
>> sections to be preempted? So with this rather paranoid approach we make sure
>> to avoid such a situation as we wait a grace period when readers finished.
>
> There is no need, because we respect a rcu grace period at dismantle
> time already.
>
> Nothing bad can happen inside the rcu_read_lock()/rcu_read_unlock() pair
> in packed_cached_dev_get()
>
> Note that dev_put() does not take any immediate action, it only
> decrements the refcount.
>
> So if CPU1 does the dev_put(po->prot_hook.dev) after
> setting cached_dev to NULL, we should be safe.

Ok, then I'll update the patch and send out v3 with that removed.

Thanks for the input Eric!

      reply	other threads:[~2013-11-21 15:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-21  9:47 [PATCH net v2] packet: fix use after free race in send path when dev is released Daniel Borkmann
2013-11-21 14:40 ` Eric Dumazet
2013-11-21 15:02   ` Daniel Borkmann
2013-11-21 15:27     ` Eric Dumazet
2013-11-21 15:28       ` Daniel Borkmann [this message]

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=528E26AB.8020501@redhat.com \
    --to=dborkman@redhat.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=greearb@candelatech.com \
    --cc=netdev@vger.kernel.org \
    --cc=noureddine@aristanetworks.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.