Stanislav Fomichev
0d01da6afc
bpf: implement getsockopt and setsockopt hooks
...
Implement new BPF_PROG_TYPE_CGROUP_SOCKOPT program type and
BPF_CGROUP_{G,S}ETSOCKOPT cgroup hooks.
BPF_CGROUP_SETSOCKOPT can modify user setsockopt arguments before
passing them down to the kernel or bypass kernel completely.
BPF_CGROUP_GETSOCKOPT can can inspect/modify getsockopt arguments that
kernel returns.
Both hooks reuse existing PTR_TO_PACKET{,_END} infrastructure.
The buffer memory is pre-allocated (because I don't think there is
a precedent for working with __user memory from bpf). This might be
slow to do for each {s,g}etsockopt call, that's why I've added
__cgroup_bpf_prog_array_is_empty that exits early if there is nothing
attached to a cgroup. Note, however, that there is a race between
__cgroup_bpf_prog_array_is_empty and BPF_PROG_RUN_ARRAY where cgroup
program layout might have changed; this should not be a problem
because in general there is a race between multiple calls to
{s,g}etsocktop and user adding/removing bpf progs from a cgroup.
The return code of the BPF program is handled as follows:
* 0: EPERM
* 1: success, continue with next BPF program in the cgroup chain
v9:
* allow overwriting setsockopt arguments (Alexei Starovoitov):
* use set_fs (same as kernel_setsockopt)
* buffer is always kzalloc'd (no small on-stack buffer)
v8:
* use s32 for optlen (Andrii Nakryiko)
v7:
* return only 0 or 1 (Alexei Starovoitov)
* always run all progs (Alexei Starovoitov)
* use optval=0 as kernel bypass in setsockopt (Alexei Starovoitov)
(decided to use optval=-1 instead, optval=0 might be a valid input)
* call getsockopt hook after kernel handlers (Alexei Starovoitov)
v6:
* rework cgroup chaining; stop as soon as bpf program returns
0 or 2; see patch with the documentation for the details
* drop Andrii's and Martin's Acked-by (not sure they are comfortable
with the new state of things)
v5:
* skip copy_to_user() and put_user() when ret == 0 (Martin Lau)
v4:
* don't export bpf_sk_fullsock helper (Martin Lau)
* size != sizeof(__u64) for uapi pointers (Martin Lau)
* offsetof instead of bpf_ctx_range when checking ctx access (Martin Lau)
v3:
* typos in BPF_PROG_CGROUP_SOCKOPT_RUN_ARRAY comments (Andrii Nakryiko)
* reverse christmas tree in BPF_PROG_CGROUP_SOCKOPT_RUN_ARRAY (Andrii
Nakryiko)
* use __bpf_md_ptr instead of __u32 for optval{,_end} (Martin Lau)
* use BPF_FIELD_SIZEOF() for consistency (Martin Lau)
* new CG_SOCKOPT_ACCESS macro to wrap repeated parts
v2:
* moved bpf_sockopt_kern fields around to remove a hole (Martin Lau)
* aligned bpf_sockopt_kern->buf to 8 bytes (Martin Lau)
* bpf_prog_array_is_empty instead of bpf_prog_array_length (Martin Lau)
* added [0,2] return code check to verifier (Martin Lau)
* dropped unused buf[64] from the stack (Martin Lau)
* use PTR_TO_SOCKET for bpf_sockopt->sk (Martin Lau)
* dropped bpf_target_off from ctx rewrites (Martin Lau)
* use return code for kernel bypass (Martin Lau & Andrii Nakryiko)
Cc: Andrii Nakryiko <andriin@fb.com >
Cc: Martin Lau <kafai@fb.com >
Signed-off-by: Stanislav Fomichev <sdf@google.com >
Signed-off-by: Alexei Starovoitov <ast@kernel.org >
2019-06-27 15:25:16 -07:00
..
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:04 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-08 15:20:40 -07:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:18 +02:00
2019-06-19 17:09:55 +02:00
2019-05-11 10:54:43 -04:00
2019-06-05 17:37:07 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-05-31 11:13:10 +02:00
2019-05-15 18:21:43 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-13 13:23:19 -07:00
2019-06-21 09:58:42 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:36:37 +02:00
2019-05-30 11:29:22 -07:00
2019-06-22 08:59:24 -04:00
2019-06-19 17:09:55 +02:00
2019-06-17 20:20:36 -07:00
2019-05-24 17:27:13 +02:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:26:32 -07:00
2019-06-19 17:09:55 +02:00
2019-06-13 17:34:56 -10:00
2019-05-30 11:29:53 -07:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:09 +02:00
2019-06-05 17:37:09 +02:00
2019-05-30 11:26:37 -07:00
2019-06-19 17:09:07 +02:00
2019-06-05 17:30:29 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:05 +02:00
2019-05-30 11:26:37 -07:00
2019-05-24 17:27:12 +02:00
2019-06-05 17:37:06 +02:00
2019-05-24 17:39:02 +02:00
2019-05-30 11:29:55 -07:00
2019-06-19 17:09:07 +02:00
2019-05-30 11:26:35 -07:00
2019-06-05 17:36:37 +02:00
2019-05-24 17:27:11 +02:00
2019-05-24 17:27:11 +02:00
2019-05-24 17:27:11 +02:00
2019-05-24 17:27:11 +02:00
2019-05-24 17:27:11 +02:00
2019-06-05 17:37:06 +02:00
2019-06-05 17:37:17 +02:00
2019-05-21 11:28:46 +02:00
2019-05-30 11:26:32 -07:00
2019-06-05 17:37:17 +02:00
2019-05-30 11:26:35 -07:00
2019-05-24 17:37:52 +02:00
2019-05-24 17:37:52 +02:00
2019-05-14 09:47:48 -07:00
2019-06-05 17:37:07 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-14 19:52:50 -07:00
2019-06-17 09:33:02 -06:00
2019-05-30 11:26:41 -07:00
2019-05-14 19:52:49 -07:00
2019-05-23 10:25:26 -06:00
2019-05-23 10:25:26 -06:00
2019-05-24 17:36:45 +02:00
2019-06-27 15:25:16 -07:00
2019-06-20 00:06:27 -04:00
2019-06-27 15:25:16 -07:00
2019-06-27 15:25:16 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:08 +02:00
2019-06-14 17:46:14 -10:00
2019-06-17 20:20:36 -07:00
2019-05-15 13:21:37 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:36:37 +02:00
2019-06-19 17:09:55 +02:00
2019-05-14 19:52:48 -07:00
2019-05-09 15:25:13 -04:00
2019-05-30 11:25:18 -07:00
2019-05-30 11:26:35 -07:00
2019-05-18 15:52:26 -07:00
2019-06-19 17:09:55 +02:00
2019-05-24 17:27:11 +02:00
2019-06-05 17:37:06 +02:00
2019-05-30 11:26:39 -07:00
2019-06-05 17:36:37 +02:00
2019-06-19 17:09:55 +02:00
2019-06-03 12:02:03 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-15 10:00:29 +02:00
2019-05-14 19:52:50 -07:00
2019-06-19 17:09:06 +02:00
2019-06-19 17:09:06 +02:00
2019-05-24 17:27:11 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:29:53 -07:00
2019-05-20 15:02:08 -07:00
2019-05-24 17:27:11 +02:00
2019-05-30 11:26:37 -07:00
2019-06-05 17:37:05 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-13 17:34:56 -10:00
2019-05-24 17:37:52 +02:00
2019-06-05 17:37:17 +02:00
2019-05-30 11:29:21 -07:00
2019-05-30 11:29:21 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:07 +02:00
2019-05-24 17:37:54 +02:00
2019-06-05 17:37:06 +02:00
2019-05-30 11:26:41 -07:00
2019-05-30 11:26:41 -07:00
2019-05-30 11:26:41 -07:00
2019-06-19 17:09:07 +02:00
2019-05-21 11:28:40 +02:00
2019-06-05 17:37:05 +02:00
2019-05-15 17:35:54 +01:00
2019-05-24 17:37:53 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:36:37 +02:00
2019-05-30 11:26:35 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:29:19 -07:00
2019-05-30 11:26:32 -07:00
2019-05-25 16:33:36 -07:00
2019-05-30 11:26:32 -07:00
2019-06-05 17:36:37 +02:00
2019-06-05 17:36:37 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-06-19 17:09:55 +02:00
2019-06-27 15:25:16 -07:00
2019-06-05 17:36:37 +02:00
2019-05-30 11:26:35 -07:00
2019-05-24 17:36:45 +02:00
2019-05-24 17:27:11 +02:00
2019-05-24 17:27:11 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-12 18:16:31 -04:00
2019-06-19 17:09:11 +02:00
2019-05-30 11:26:41 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:35 -07:00
2019-05-30 11:26:32 -07:00
2019-05-24 17:27:12 +02:00
2019-06-19 15:53:58 +02:00
2019-05-13 15:08:16 -07:00
2019-05-15 16:05:47 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:06 +02:00
2019-06-01 15:51:32 -07:00
2019-05-14 09:47:47 -07:00
2019-05-30 11:29:53 -07:00
2019-05-30 11:26:35 -07:00
2019-05-30 11:26:32 -07:00
2019-06-05 17:37:06 +02:00
2019-06-05 17:37:06 +02:00
2019-05-30 11:26:35 -07:00
2019-05-30 11:26:35 -07:00
2019-06-05 17:36:38 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:37 -07:00
2019-05-21 11:28:39 +02:00
2019-05-14 09:47:44 -07:00
2019-05-14 09:47:48 -07:00
2019-05-24 17:36:45 +02:00
2019-05-24 17:36:45 +02:00
2019-06-05 17:37:17 +02:00
2019-06-05 17:37:05 +02:00
2019-05-21 11:28:39 +02:00
2019-05-21 11:28:39 +02:00
2019-05-21 11:28:39 +02:00
2019-05-21 11:28:39 +02:00
2019-05-30 11:27:46 -07:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:29:55 -07:00
2019-06-22 08:59:24 -04:00
2019-05-30 11:26:41 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-23 09:48:07 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:37 -07:00
2019-05-30 11:26:32 -07:00
2019-06-07 11:00:14 -07:00
2019-06-05 17:37:17 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-06-02 18:08:36 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:17 +02:00
2019-06-05 17:37:05 +02:00
2019-05-30 11:26:41 -07:00
2019-06-05 17:36:37 +02:00
2019-05-30 11:26:35 -07:00
2019-06-19 17:09:56 +02:00
2019-06-19 17:09:56 +02:00
2019-06-05 17:37:06 +02:00
2019-06-05 17:36:37 +02:00
2019-06-05 17:37:16 +02:00
2019-05-30 11:26:32 -07:00
2019-06-05 17:37:17 +02:00
2019-05-14 19:52:52 -07:00
2019-05-30 11:26:32 -07:00
2019-06-19 17:09:55 +02:00
2019-05-24 17:36:45 +02:00
2019-06-05 17:36:37 +02:00
2019-06-05 17:36:37 +02:00
2019-05-24 17:37:52 +02:00
2019-05-30 11:26:35 -07:00
2019-06-14 19:31:47 -07:00
2019-05-30 11:26:32 -07:00
2019-05-14 19:52:49 -07:00
2019-06-05 17:37:16 +02:00
2019-05-24 17:27:11 +02:00
2019-05-30 11:26:32 -07:00
2019-05-24 17:27:11 +02:00
2019-05-24 17:36:45 +02:00
2019-06-19 17:09:08 +02:00
2019-06-05 17:37:06 +02:00
2019-05-24 17:36:45 +02:00
2019-05-30 11:26:35 -07:00
2019-06-05 17:37:16 +02:00
2019-05-30 11:29:19 -07:00
2019-05-30 11:29:19 -07:00
2019-05-14 19:52:48 -07:00
2019-06-19 17:09:53 +02:00
2019-06-19 17:09:07 +02:00
2019-06-19 17:09:56 +02:00
2019-05-14 19:52:49 -07:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:29:22 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:17 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:07 +02:00
2019-06-19 17:09:55 +02:00
2019-05-21 11:28:46 +02:00
2019-05-24 17:39:02 +02:00
2019-06-05 17:36:38 +02:00
2019-06-19 17:09:55 +02:00
2019-06-01 15:51:31 -07:00
2019-05-14 19:52:49 -07:00
2019-05-16 15:55:48 -07:00
2019-05-21 11:28:45 +02:00
2019-06-05 17:37:06 +02:00
2019-05-30 11:26:32 -07:00
2019-05-24 17:37:53 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:17 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:26:32 -07:00
2019-06-13 17:34:56 -10:00
2019-05-14 09:47:50 -07:00
2019-05-14 09:47:49 -07:00
2019-06-13 17:34:56 -10:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:36:38 +02:00
2019-05-30 11:26:32 -07:00
2019-05-21 11:28:45 +02:00
2019-05-30 11:26:41 -07:00
2019-05-14 09:47:46 -07:00
2019-05-14 19:52:48 -07:00
2019-06-19 17:09:55 +02:00
2019-06-07 13:09:06 -07:00
2019-05-14 09:47:49 -07:00
2019-05-14 19:52:48 -07:00
2019-05-14 10:55:54 -07:00
2019-05-24 17:27:10 +02:00
2019-05-19 10:58:45 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:35 -07:00
2019-06-05 17:36:38 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-31 09:45:26 -07:00
2019-05-31 18:02:48 +02:00
2019-05-30 11:26:41 -07:00
2019-05-14 17:19:47 +02:00
2019-06-05 17:37:16 +02:00
2019-06-05 17:37:16 +02:00
2019-05-24 17:27:11 +02:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:26:32 -07:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:26:35 -07:00
2019-06-05 17:30:29 +02:00
2019-05-16 10:29:00 -07:00
2019-06-05 17:37:06 +02:00
2019-05-30 11:26:39 -07:00
2019-05-14 09:47:51 -07:00
2019-05-30 11:29:19 -07:00
2019-06-21 22:05:42 -04:00
2019-05-27 10:55:08 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:07 +02:00
2019-05-21 10:50:45 +02:00
2019-05-17 10:33:30 -07:00
2019-06-05 17:37:07 +02:00
2019-05-30 11:26:37 -07:00
2019-06-07 11:00:14 -07:00
2019-06-17 20:20:36 -07:00
2019-05-30 11:29:52 -07:00
2019-06-05 17:37:16 +02:00
2019-05-21 11:28:45 +02:00
2019-06-05 17:37:07 +02:00
2019-06-05 17:37:16 +02:00
2019-06-05 17:37:16 +02:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:16 +02:00
2019-05-30 11:26:35 -07:00
2019-05-30 11:26:35 -07:00
2019-05-24 17:36:45 +02:00
2019-05-14 19:52:48 -07:00
2019-05-24 17:36:45 +02:00
2019-05-30 11:29:54 -07:00
2019-06-05 17:37:04 +02:00
2019-05-30 11:26:32 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-05-24 17:36:45 +02:00
2019-05-24 17:36:45 +02:00
2019-05-14 19:52:51 -07:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:26:41 -07:00
2019-05-14 19:52:48 -07:00
2019-05-14 19:52:48 -07:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:36:37 +02:00
2019-06-05 17:37:06 +02:00
2019-05-24 17:36:45 +02:00
2019-06-13 22:34:55 -07:00
2019-05-30 11:26:32 -07:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:36:37 +02:00
2019-05-14 19:52:48 -07:00
2019-05-30 11:26:32 -07:00
2019-06-05 17:37:17 +02:00
2019-05-17 10:08:59 -07:00
2019-05-30 11:26:35 -07:00
2019-05-30 11:26:35 -07:00
2019-06-03 13:26:20 -07:00
2019-05-14 19:52:51 -07:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:29:21 -07:00
2019-06-05 17:36:37 +02:00
2019-05-29 13:27:08 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:32 -07:00
2019-06-19 17:09:55 +02:00
2019-06-05 17:37:17 +02:00
2019-05-21 11:28:46 +02:00
2019-05-21 11:28:46 +02:00
2019-06-19 17:09:07 +02:00
2019-06-05 17:37:06 +02:00
2019-06-19 17:09:55 +02:00
2019-05-14 19:52:48 -07:00
2019-05-30 11:29:52 -07:00
2019-05-24 17:39:00 +02:00
2019-05-30 11:26:32 -07:00
2019-06-05 17:37:17 +02:00
2019-05-30 11:26:41 -07:00
2019-06-05 17:36:37 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:35 -07:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:35 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-05-31 12:37:46 -07:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:06 +02:00
2019-06-19 17:09:55 +02:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:26:32 -07:00
2019-06-19 10:09:21 -04:00
2019-05-23 16:13:29 +02:00
2019-05-16 15:51:55 -07:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:29:19 -07:00
2019-05-30 11:26:35 -07:00
2019-05-24 17:36:45 +02:00
2019-06-05 17:36:37 +02:00
2019-06-05 17:36:37 +02:00
2019-05-30 11:26:37 -07:00
2019-06-17 20:20:36 -07:00
2019-06-05 17:37:16 +02:00
2019-05-30 11:26:32 -07:00
2019-06-05 17:37:04 +02:00
2019-06-03 10:44:21 +02:00
2019-06-05 17:36:37 +02:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:29:22 -07:00
2019-06-05 17:37:09 +02:00
2019-06-05 17:37:16 +02:00
2019-06-14 20:18:27 -07:00
2019-05-21 11:28:46 +02:00
2019-06-05 17:37:06 +02:00
2019-06-19 17:09:55 +02:00
2019-06-22 16:30:37 -07:00
2019-06-05 17:36:37 +02:00
2019-05-30 11:26:32 -07:00
2019-05-16 16:16:18 -07:00
2019-06-05 17:37:06 +02:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:29:19 -07:00
2019-05-30 11:29:19 -07:00
2019-05-30 11:26:37 -07:00
2019-06-19 17:09:55 +02:00
2019-05-24 17:39:02 +02:00
2019-06-05 17:37:17 +02:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:29:21 -07:00
2019-06-05 17:37:09 +02:00
2019-06-05 17:37:17 +02:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:26:32 -07:00
2019-06-05 17:37:04 +02:00
2019-05-30 11:26:32 -07:00
2019-05-30 11:26:35 -07:00
2019-05-14 09:47:45 -07:00
2019-05-30 11:26:41 -07:00
2019-06-05 17:30:29 +02:00
2019-05-24 17:27:11 +02:00
2019-05-30 11:26:41 -07:00
2019-06-19 17:09:55 +02:00
2019-05-24 17:27:13 +02:00
2019-05-24 17:27:13 +02:00
2019-06-05 17:30:27 +02:00
2019-05-12 13:11:36 -04:00
2019-05-24 17:39:00 +02:00
2019-06-05 17:37:05 +02:00
2019-05-18 15:52:26 -07:00
2019-05-14 09:47:45 -07:00
2019-06-05 17:37:05 +02:00
2019-06-05 17:37:05 +02:00
2019-05-30 11:26:35 -07:00
2019-06-19 17:09:55 +02:00
2019-05-30 11:26:37 -07:00
2019-05-15 17:35:54 +01:00
2019-06-05 17:37:07 +02:00
2019-05-30 11:26:41 -07:00
2019-05-24 17:36:47 +02:00