diff options
author | Eric Dumazet <edumazet@google.com> | 2017-10-02 22:20:51 +0300 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-10-03 01:23:42 +0300 |
commit | eefca20eb20c66b06cf5ed09b49b1a7caaa27b7b (patch) | |
tree | 49ff0df975ed5fc89db450ca9b17ed040c1f7939 /net/core/filter.c | |
parent | 4ee4553e861a2a7c4f5b045d9453729d837d4a7d (diff) | |
download | linux-eefca20eb20c66b06cf5ed09b49b1a7caaa27b7b.tar.xz |
socket, bpf: fix possible use after free
Starting from linux-4.4, 3WHS no longer takes the listener lock.
Since this time, we might hit a use-after-free in sk_filter_charge(),
if the filter we got in the memcpy() of the listener content
just happened to be replaced by a thread changing listener BPF filter.
To fix this, we need to make sure the filter refcount is not already
zero before incrementing it again.
Fixes: e994b2f0fb92 ("tcp: do not lock listener to process SYN packets")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/filter.c')
-rw-r--r-- | net/core/filter.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index 82edad58d066..74b8c91fb5f4 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -989,10 +989,14 @@ static bool __sk_filter_charge(struct sock *sk, struct sk_filter *fp) bool sk_filter_charge(struct sock *sk, struct sk_filter *fp) { - bool ret = __sk_filter_charge(sk, fp); - if (ret) - refcount_inc(&fp->refcnt); - return ret; + if (!refcount_inc_not_zero(&fp->refcnt)) + return false; + + if (!__sk_filter_charge(sk, fp)) { + sk_filter_release(fp); + return false; + } + return true; } static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp) |