OSDN Git Service

bpf, sockmap: fix sock hash count in alloc_sock_hash_elem
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 22 Aug 2018 16:09:17 +0000 (18:09 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 22 Aug 2018 18:35:18 +0000 (20:35 +0200)
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>
kernel/bpf/sockmap.c

index 60ceb0e..40c6ef9 100644 (file)
@@ -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;