diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2018-08-22 18:09:17 +0200 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-08-22 20:35:18 +0200 |
commit | eb29429d81e31b191f3b2bd19cf820279cec6463 (patch) | |
tree | 8226d9ef2befb79ae7f8857ba6b8e2d1504f6cdf /kernel/bpf | |
parent | bpf, sockmap: fix sock_hash_alloc and reject zero-sized keys (diff) | |
download | linux-eb29429d81e31b191f3b2bd19cf820279cec6463.tar.xz linux-eb29429d81e31b191f3b2bd19cf820279cec6463.zip |
bpf, sockmap: fix sock hash count in alloc_sock_hash_elem
When we try to allocate a new sock hash entry and the allocation
fails, then sock hash map fails to reduce the map element counter,
meaning we keep accounting this element although it was never used.
Fix it by dropping the element counter on error.
Fixes: 81110384441a ("bpf: sockmap, add hash map support")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Diffstat (limited to 'kernel/bpf')
-rw-r--r-- | kernel/bpf/sockmap.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/kernel/bpf/sockmap.c b/kernel/bpf/sockmap.c index 60ceb0e1fa56..40c6ef9fc828 100644 --- a/kernel/bpf/sockmap.c +++ b/kernel/bpf/sockmap.c @@ -2269,8 +2269,10 @@ static struct htab_elem *alloc_sock_hash_elem(struct bpf_htab *htab, } l_new = kmalloc_node(htab->elem_size, GFP_ATOMIC | __GFP_NOWARN, htab->map.numa_node); - if (!l_new) + if (!l_new) { + atomic_dec(&htab->count); return ERR_PTR(-ENOMEM); + } memcpy(l_new->key, key, key_size); l_new->sk = sk; |