netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: stranche@codeaurora.org
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev@vger.kernel.org, steffen.klassert@secunet.com
Subject: Re: [PATCH net] af_key: free SKBs under RCU protection
Date: Fri, 21 Sep 2018 11:09:05 -0600	[thread overview]
Message-ID: <a1b484c544c9f631246374ccf09e491f@codeaurora.org> (raw)
In-Reply-To: <6f2e6b62-42dc-f2b3-3758-29f5338f1185@gmail.com>

>> 
>> As long as one skb has sock_rfree has its destructor, the socket 
>> attached to
>> this skb can not be released. There is no race here.
>> 
>> Note that skb_clone() does not propagate the destructor.
>> 
>> The issue here is that in the rcu lookup, we can find a socket that 
>> has been
>> dismantled, with a 0 refcount.
>> 
>> We must not use sock_hold() in this case, since we are not sure the 
>> socket refcount is not already 0.
>> 
>> pfkey_broadcast() and pfkey_broadcast_one() violate basic RCU rules.
>> 
>> When in a RCU lookup, one want to increment an object refcount, it 
>> needs
>> to be extra-careful, as I did in my proposal.
>> 
>> Note that the race could be automatically detected with 
>> CONFIG_REFCOUNT_FULL=y
> 
> Bug was added in commit 7f6b9dbd5afb ("af_key: locking change")

Hi Eric,

I tried your refcount idea below, but it still results in the same 
crash.

>>>> --- a/net/key/af_key.c
>>>> +++ b/net/key/af_key.c
>>>> @@ -201,7 +201,9 @@ static int pfkey_broadcast_one(struct sk_buff
>>>> *skb, struct sk_buff **skb2,
>>>>  {
>>>>         int err = -ENOBUFS;
>>>> 
>>>> -       sock_hold(sk);
>>>> +       if (!refcount_inc_not_zero(&sk->sk_refcnt))
>>>> +               return -ENOENT;
>>>> +
>>>>         if (*skb2 == NULL) {
>>>>                 if (refcount_read(&skb->users) != 1) {
>>>>                         *skb2 = skb_clone(skb, allocation);

I also tried reverting 7f6b9dbd5afb ("af_key: locking change") and 
running the
test there and I still see the crash, so it doesn't seem to be an RCU 
specific
issue.

Is there anything else that could be causing this?

  reply	other threads:[~2018-09-21 22:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-20  0:18 [PATCH net] af_key: free SKBs under RCU protection Sean Tranchetti
2018-09-20 13:29 ` Eric Dumazet
2018-09-20 19:25   ` stranche
2018-09-20 22:10     ` Eric Dumazet
2018-09-20 22:29       ` Eric Dumazet
2018-09-21 17:09         ` stranche [this message]
2018-09-21 17:40           ` Eric Dumazet
2018-09-21 18:44             ` stranche
2018-09-23 17:15     ` Eric Dumazet
2018-09-24 18:46       ` stranche

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=a1b484c544c9f631246374ccf09e491f@codeaurora.org \
    --to=stranche@codeaurora.org \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=steffen.klassert@secunet.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 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).