bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen
authorStanislav Fomichev <sdf@google.com>
Thu, 11 May 2023 17:04:53 +0000 (10:04 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Sat, 13 May 2023 23:20:15 +0000 (16:20 -0700)
commit29ebbba7d46136cba324264e513a1e964ca16c0a
treefa10cc308a2863f94dbc55e8076003e7705bbe64
parentbdeeed3498c7871c17465bb4f11d1bc67f9098af
bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen

With the way the hooks implemented right now, we have a special
condition: optval larger than PAGE_SIZE will expose only first 4k into
BPF; any modifications to the optval are ignored. If the BPF program
doesn't handle this condition by resetting optlen to 0,
the userspace will get EFAULT.

The intention of the EFAULT was to make it apparent to the
developers that the program is doing something wrong.
However, this inadvertently might affect production workloads
with the BPF programs that are not too careful (i.e., returning EFAULT
for perfectly valid setsockopt/getsockopt calls).

Let's try to minimize the chance of BPF program screwing up userspace
by ignoring the output of those BPF programs (instead of returning
EFAULT to the userspace). pr_info_once those cases to
the dmesg to help with figuring out what's going wrong.

Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
Suggested-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20230511170456.1759459-2-sdf@google.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
kernel/bpf/cgroup.c