提交 eb29429d 编写于 作者: D Daniel Borkmann

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: 81110384 ("bpf: sockmap, add hash map support")
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
Acked-by: NJohn Fastabend <john.fastabend@gmail.com>
上级 b845c898
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册