Repository navigation
Commit 64d8529
bpf: Allow bpf_map_lookup_elem for SOCKMAP and SOCKHASH
White-list map lookup for SOCKMAP/SOCKHASH from BPF. Lookup returns a
pointer to a full socket and acquires a reference if necessary.
To support it we need to extend the verifier to know that:
(1) register storing the lookup result holds a pointer to socket, if
lookup was done on SOCKMAP/SOCKHASH, and that
(2) map lookup on SOCKMAP/SOCKHASH is a reference acquiring operation,
which needs a corresponding reference release with bpf_sk_release.
On sock_map side, lookup handlers exposed via bpf_map_ops now bump
sk_refcnt if socket is reference counted. In turn, bpf_sk_select_reuseport,
the only in-kernel user of SOCKMAP/SOCKHASH ops->map_lookup_elem, was
updated to release the reference.
Sockets fetched from a map can be used in the same way as ones returned by
BPF socket lookup helpers, such as bpf_sk_lookup_tcp. In particular, they
can be used with bpf_sk_assign to direct packets toward a socket on TC
ingress path.
Suggested-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20200429181154.479310-2-jakub@cloudflare.com1 parent 0b3b9ca commit 64d8529
3 files changed
Lines changed: 55 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
432 | | - | |
| 432 | + | |
433 | 433 | | |
434 | 434 | | |
435 | 435 | | |
436 | | - | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
437 | 456 | | |
438 | 457 | | |
439 | 458 | | |
| |||
3934 | 3953 | | |
3935 | 3954 | | |
3936 | 3955 | | |
3937 | | - | |
| 3956 | + | |
| 3957 | + | |
3938 | 3958 | | |
3939 | 3959 | | |
3940 | 3960 | | |
3941 | 3961 | | |
3942 | 3962 | | |
3943 | 3963 | | |
3944 | 3964 | | |
3945 | | - | |
| 3965 | + | |
| 3966 | + | |
3946 | 3967 | | |
3947 | 3968 | | |
3948 | 3969 | | |
| |||
4112 | 4133 | | |
4113 | 4134 | | |
4114 | 4135 | | |
4115 | | - | |
| 4136 | + | |
4116 | 4137 | | |
4117 | 4138 | | |
4118 | 4139 | | |
| |||
4623 | 4644 | | |
4624 | 4645 | | |
4625 | 4646 | | |
4626 | | - | |
| 4647 | + | |
4627 | 4648 | | |
4628 | 4649 | | |
4629 | 4650 | | |
| |||
6532 | 6553 | | |
6533 | 6554 | | |
6534 | 6555 | | |
6535 | | - | |
| 6556 | + | |
| 6557 | + | |
| 6558 | + | |
6536 | 6559 | | |
6537 | | - | |
6538 | | - | |
6539 | | - | |
| 6560 | + | |
| 6561 | + | |
6540 | 6562 | | |
| 6563 | + | |
| 6564 | + | |
| 6565 | + | |
6541 | 6566 | | |
6542 | 6567 | | |
6543 | 6568 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8712 | 8712 | | |
8713 | 8713 | | |
8714 | 8714 | | |
| 8715 | + | |
| 8716 | + | |
| 8717 | + | |
| 8718 | + | |
8715 | 8719 | | |
8716 | 8720 | | |
8717 | 8721 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
343 | 343 | | |
344 | 344 | | |
345 | 345 | | |
346 | | - | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
347 | 354 | | |
348 | 355 | | |
349 | 356 | | |
| |||
1051 | 1058 | | |
1052 | 1059 | | |
1053 | 1060 | | |
1054 | | - | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
1055 | 1069 | | |
1056 | 1070 | | |
1057 | 1071 | | |
| |||
0 commit comments