Skip to content

Commit 60e5ca8

Browse files
rdnaAlexei Starovoitov
authored andcommitted
bpf: Fix memlock accounting for sock_hash
Add missed bpf_map_charge_init() in sock_hash_alloc() and correspondingly bpf_map_charge_finish() on ENOMEM. It was found accidentally while working on unrelated selftest that checks "map->memory.pages > 0" is true for all map types. Before: # bpftool m l ... 3692: sockhash name m_sockhash flags 0x0 key 4B value 4B max_entries 8 memlock 0B After: # bpftool m l ... 84: sockmap name m_sockmap flags 0x0 key 4B value 4B max_entries 8 memlock 4096B Fixes: 604326b ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Andrey Ignatov <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent f6fede8 commit 60e5ca8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/core/sock_map.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,11 +991,15 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
991991
err = -EINVAL;
992992
goto free_htab;
993993
}
994+
err = bpf_map_charge_init(&htab->map.memory, cost);
995+
if (err)
996+
goto free_htab;
994997

995998
htab->buckets = bpf_map_area_alloc(htab->buckets_num *
996999
sizeof(struct bpf_htab_bucket),
9971000
htab->map.numa_node);
9981001
if (!htab->buckets) {
1002+
bpf_map_charge_finish(&htab->map.memory);
9991003
err = -ENOMEM;
10001004
goto free_htab;
10011005
}

0 commit comments

Comments
 (0)