netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: Y Song <ys114321@gmail.com>
Cc: edumazet@google.com, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	netdev <netdev@vger.kernel.org>
Subject: Re: [bpf PATCH 2/3] bpf: sockmap, fix transition through disconnect without close
Date: Mon, 17 Sep 2018 21:40:21 -0700	[thread overview]
Message-ID: <0b55da5e-893b-8cfe-87df-b536a1e3565b@gmail.com> (raw)
In-Reply-To: <CAH3MdRU-0p9wno4Vmo6xCaEF9r83+WP_UBLccqA0tmcP3yOCnA@mail.gmail.com>

On 09/17/2018 02:09 PM, Y Song wrote:
> On Mon, Sep 17, 2018 at 10:32 AM John Fastabend
> <john.fastabend@gmail.com> wrote:
>>
>> It is possible (via shutdown()) for TCP socks to go trough TCP_CLOSE
>> state via tcp_disconnect() without actually calling tcp_close which
>> would then call our bpf_tcp_close() callback. Because of this a user
>> could disconnect a socket then put it in a LISTEN state which would
>> break our assumptions about sockets always being ESTABLISHED state.
>>
>> To resolve this rely on the unhash hook, which is called in the
>> disconnect case, to remove the sock from the sockmap.
>>
>> Reported-by: Eric Dumazet <edumazet@google.com>
>> Fixes: 1aa12bdf1bfb ("bpf: sockmap, add sock close() hook to remove socks")
>> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
>> ---

[...]

>> +{
>> +       void (*unhash_fun)(struct sock *sk);
>> +       struct smap_psock *psock;
>> +
>> +       rcu_read_lock();
>> +       psock = smap_psock_sk(sk);
>> +       if (unlikely(!psock)) {
>> +               rcu_read_unlock();
>> +               release_sock(sk);
> 
> Can socket be released here?
>

Right, it was an error (it can not be released) fixed in v3.


>> +               return sk->sk_prot->unhash(sk);
>> +       }
>> +
>> +       /* The psock may be destroyed anytime after exiting the RCU critial
>> +        * section so by the time we use close_fun the psock may no longer
>> +        * be valid. However, bpf_tcp_close is called with the sock lock
>> +        * held so the close hook and sk are still valid.
>> +        */
> 
> the comments above are not correct. A copy-paste mistake?

I just removed the comments they are not overly helpful at this point
and the commit msg is more useful anyways.

Thanks,
John

  reply	other threads:[~2018-09-18 10:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-17 17:31 [bpf PATCH 0/3] bpf, sockmap ESTABLISHED state only John Fastabend
2018-09-17 17:31 ` [bpf PATCH 1/3] bpf: sockmap only allow ESTABLISHED sock state John Fastabend
2018-09-17 20:49   ` Y Song
2018-09-17 17:31 ` [bpf PATCH 2/3] bpf: sockmap, fix transition through disconnect without close John Fastabend
2018-09-17 21:09   ` Y Song
2018-09-18  4:40     ` John Fastabend [this message]
2018-09-17 17:32 ` [bpf PATCH 3/3] bpf: test_maps, only support ESTABLISHED socks John Fastabend
2018-09-17 21:21   ` Y Song
2018-09-18  4:38     ` John Fastabend

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=0b55da5e-893b-8cfe-87df-b536a1e3565b@gmail.com \
    --to=john.fastabend@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=edumazet@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=ys114321@gmail.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).