On 09/17/2018 10:59 AM, John Fastabend 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. >
Sorry for the noise will need a v3 actually. > Reported-by: Eric Dumazet <eduma...@google.com> > Fixes: 1aa12bdf1bfb ("bpf: sockmap, add sock close() hook to remove socks") > Signed-off-by: John Fastabend <john.fastab...@gmail.com> > --- > kernel/bpf/sockmap.c | 71 > +++++++++++++++++++++++++++++++++++++------------- > 1 file changed, 52 insertions(+), 19 deletions(-) [...] > +} > + > +static void bpf_tcp_unhash(struct sock *sk) > +{ > + 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); ^^^^^^^^^^^^^^^^^ > + return sk->sk_prot->unhash(sk); if (sk->sk_prot->unhash) ... else return; Thanks, John