Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Breno Leitao and committed by
Jens Axboe
3f31e0d1 a615f67e

+5 -4
+1 -1
include/linux/bpf-cgroup.h
··· 137 137 enum cgroup_bpf_attach_type atype); 138 138 139 139 int __cgroup_bpf_run_filter_setsockopt(struct sock *sock, int *level, 140 - int *optname, char __user *optval, 140 + int *optname, sockptr_t optval, 141 141 int *optlen, char **kernel_optval); 142 142 143 143 int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level,
+3 -2
kernel/bpf/cgroup.c
··· 1785 1785 } 1786 1786 1787 1787 int __cgroup_bpf_run_filter_setsockopt(struct sock *sk, int *level, 1788 - int *optname, char __user *optval, 1788 + int *optname, sockptr_t optval, 1789 1789 int *optlen, char **kernel_optval) 1790 1790 { 1791 1791 struct cgroup *cgrp = sock_cgroup_ptr(&sk->sk_cgrp_data); ··· 1808 1808 1809 1809 ctx.optlen = *optlen; 1810 1810 1811 - if (copy_from_user(ctx.optval, optval, min(*optlen, max_optlen)) != 0) { 1811 + if (copy_from_sockptr(ctx.optval, optval, 1812 + min(*optlen, max_optlen))) { 1812 1813 ret = -EFAULT; 1813 1814 goto out; 1814 1815 }
+1 -1
net/socket.c
··· 2288 2288 2289 2289 if (!in_compat_syscall()) 2290 2290 err = BPF_CGROUP_RUN_PROG_SETSOCKOPT(sock->sk, &level, &optname, 2291 - user_optval, &optlen, 2291 + optval, &optlen, 2292 2292 &kernel_optval); 2293 2293 if (err < 0) 2294 2294 goto out_put;