History

bpf: sockmap: Enable map_update_elem from bpf_iter

Allow passing a pointer to a BTF struct sock_common* when updating a sockmap or sockhash. Since BTF pointers can fault and therefore be NULL at runtime we need to add an additional !sk check to sock_map_update_elem. Since we may be passed a request or timewait socket we also need to check sk_fullsock. Doing this allows calling map_update_elem on sockmap from bpf_iter context, which uses BTF pointers.

Lorenz Bauer committed 6 years ago

Commit 6550f2d1 parent efa90b52 files · +4 −1Browse files

Unified · Split

2 files
  1. kernel/bpf/verifier.c +1 −1
  2. net/core/sock_map.c +3 −0
kernel/bpf/verifier.c+1−1
@@ -3943,7 +3943,7 @@ static int resolve_map_arg_type(struct bpf_verifier_env *env, · 3942 unmodified lines
3943 case BPF_MAP_TYPE_SOCKMAP:3943 case BPF_MAP_TYPE_SOCKMAP:
3944 case BPF_MAP_TYPE_SOCKHASH:3944 case BPF_MAP_TYPE_SOCKHASH:
3945 if (*arg_type == ARG_PTR_TO_MAP_VALUE) {3945 if (*arg_type == ARG_PTR_TO_MAP_VALUE) {
3946 *arg_type = ARG_PTR_TO_SOCKET;3946 *arg_type = ARG_PTR_TO_BTF_ID_SOCK_COMMON;
3947 } else {3947 } else {
3948 verbose(env, "invalid arg_type for sockmap/sockhash\n");3948 verbose(env, "invalid arg_type for sockmap/sockhash\n");
3949 return -EINVAL;3949 return -EINVAL;
net/core/sock_map.c+3−0
@@ -610,6 +610,9 @@ static int sock_map_update_elem(struct bpf_map *map, void *key, · 609 unmodified lines
610 struct sock *sk = (struct sock *)value;610 struct sock *sk = (struct sock *)value;
611 int ret;611 int ret;
612 612
613 if (unlikely(!sk || !sk_fullsock(sk)))
614 return -EINVAL;
615
613 if (!sock_map_sk_is_suitable(sk))616 if (!sock_map_sk_is_suitable(sk))
614 return -EOPNOTSUPP;617 return -EOPNOTSUPP;
615 618

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t