* [PATCH bpf] bpf: Fix memlock accounting for sock_hash
@ 2020-06-12 0:08 Andrey Ignatov
2020-06-12 22:26 ` Alexei Starovoitov
0 siblings, 1 reply; 2+ messages in thread
From: Andrey Ignatov @ 2020-06-12 0:08 UTC (permalink / raw)
To: bpf; +Cc: Andrey Ignatov, ast, daniel, kafai, kernel-team
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: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
Signed-off-by: Andrey Ignatov <rdna@fb.com>
---
net/core/sock_map.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/core/sock_map.c b/net/core/sock_map.c
index 17a40a947546..3a2dc6af1d78 100644
--- a/net/core/sock_map.c
+++ b/net/core/sock_map.c
@@ -989,11 +989,15 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
err = -EINVAL;
goto free_htab;
}
+ err = bpf_map_charge_init(&htab->map.memory, cost);
+ if (err)
+ goto free_htab;
htab->buckets = bpf_map_area_alloc(htab->buckets_num *
sizeof(struct bpf_htab_bucket),
htab->map.numa_node);
if (!htab->buckets) {
+ bpf_map_charge_finish(&htab->map.memory);
err = -ENOMEM;
goto free_htab;
}
--
2.24.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH bpf] bpf: Fix memlock accounting for sock_hash
2020-06-12 0:08 [PATCH bpf] bpf: Fix memlock accounting for sock_hash Andrey Ignatov
@ 2020-06-12 22:26 ` Alexei Starovoitov
0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2020-06-12 22:26 UTC (permalink / raw)
To: Andrey Ignatov
Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Kernel Team
On Thu, Jun 11, 2020 at 5:09 PM Andrey Ignatov <rdna@fb.com> wrote:
>
> 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: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface")
> Signed-off-by: Andrey Ignatov <rdna@fb.com>
That's a nasty one. Good catch.
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-12 22:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-12 0:08 [PATCH bpf] bpf: Fix memlock accounting for sock_hash Andrey Ignatov
2020-06-12 22:26 ` Alexei Starovoitov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.