Commit 1d59f3bc authored by Jakub Sitnicki's avatar Jakub Sitnicki Committed by Daniel Borkmann

bpf, sockmap: Let all kernel-land lookup values in SOCKMAP/SOCKHASH

Don't require the kernel code, like BPF helpers, that needs access to
SOCK{MAP,HASH} map contents to live in net/core/sock_map.c. Expose the
lookup operation to all kernel-land.

Lookup from BPF context is not whitelisted yet. While syscalls have a
dedicated lookup handler.
Signed-off-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200218171023.844439-8-jakub@cloudflare.com
parent c1cdf65d
...@@ -301,7 +301,7 @@ static struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key) ...@@ -301,7 +301,7 @@ static struct sock *__sock_map_lookup_elem(struct bpf_map *map, u32 key)
static void *sock_map_lookup(struct bpf_map *map, void *key) static void *sock_map_lookup(struct bpf_map *map, void *key)
{ {
return ERR_PTR(-EOPNOTSUPP); return __sock_map_lookup_elem(map, *(u32 *)key);
} }
static void *sock_map_lookup_sys(struct bpf_map *map, void *key) static void *sock_map_lookup_sys(struct bpf_map *map, void *key)
...@@ -991,6 +991,11 @@ static void *sock_hash_lookup_sys(struct bpf_map *map, void *key) ...@@ -991,6 +991,11 @@ static void *sock_hash_lookup_sys(struct bpf_map *map, void *key)
return &sk->sk_cookie; return &sk->sk_cookie;
} }
static void *sock_hash_lookup(struct bpf_map *map, void *key)
{
return __sock_hash_lookup_elem(map, key);
}
static void sock_hash_release_progs(struct bpf_map *map) static void sock_hash_release_progs(struct bpf_map *map)
{ {
psock_progs_drop(&container_of(map, struct bpf_htab, map)->progs); psock_progs_drop(&container_of(map, struct bpf_htab, map)->progs);
...@@ -1079,7 +1084,7 @@ const struct bpf_map_ops sock_hash_ops = { ...@@ -1079,7 +1084,7 @@ const struct bpf_map_ops sock_hash_ops = {
.map_get_next_key = sock_hash_get_next_key, .map_get_next_key = sock_hash_get_next_key,
.map_update_elem = sock_hash_update_elem, .map_update_elem = sock_hash_update_elem,
.map_delete_elem = sock_hash_delete_elem, .map_delete_elem = sock_hash_delete_elem,
.map_lookup_elem = sock_map_lookup, .map_lookup_elem = sock_hash_lookup,
.map_lookup_elem_sys_only = sock_hash_lookup_sys, .map_lookup_elem_sys_only = sock_hash_lookup_sys,
.map_release_uref = sock_hash_release_progs, .map_release_uref = sock_hash_release_progs,
.map_check_btf = map_check_no_btf, .map_check_btf = map_check_no_btf,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment