diff options
author | Breno Leitao <leitao@debian.org> | 2023-10-16 06:47:40 -0700 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2023-10-19 14:05:37 -0600 |
commit | 3f31e0d14d44ad491a81b7c1f83f32fbc300a867 (patch) | |
tree | e69d7c1110eef9f75be5837577e5ba0df99cfd8a /kernel | |
parent | a615f67e1a426f35366b8398c11f31c148e7df48 (diff) | |
download | linux-stable-3f31e0d14d44ad491a81b7c1f83f32fbc300a867.tar.gz linux-stable-3f31e0d14d44ad491a81b7c1f83f32fbc300a867.tar.bz2 linux-stable-3f31e0d14d44ad491a81b7c1f83f32fbc300a867.zip |
bpf: Add sockptr support for setsockopt
The whole network stack uses sockptr, and while it doesn't move to
something more modern, let's use sockptr in setsockptr BPF hooks, so, it
could be used by other callers.
The main motivation for this change is to use it in the io_uring
{g,s}etsockopt(), which will use a userspace pointer for *optval, but, a
kernel value for optlen.
Link: https://lore.kernel.org/all/ZSArfLaaGcfd8LH8@gmail.com/
Signed-off-by: Breno Leitao <leitao@debian.org>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20231016134750.1381153-3-leitao@debian.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/bpf/cgroup.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index ebc8c58f7e46..f0dedd4f7f2e 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1785,7 +1785,7 @@ static bool sockopt_buf_allocated(struct bpf_sockopt_kern *ctx, } int __cgroup_bpf_run_filter_setsockopt(struct sock *sk, int *level, - int *optname, char __user *optval, + int *optname, sockptr_t optval, int *optlen, char **kernel_optval) { struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); @@ -1808,7 +1808,8 @@ int __cgroup_bpf_run_filter_setsockopt(struct sock *sk, int *level, ctx.optlen = *optlen; - if (copy_from_user(ctx.optval, optval, min(*optlen, max_optlen)) != 0) { + if (copy_from_sockptr(ctx.optval, optval, + min(*optlen, max_optlen))) { ret = -EFAULT; goto out; } |