]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
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)
committerRoxana Nicolescu <roxana.nicolescu@canonical.com>
Mon, 2 Oct 2023 15:19:34 +0000 (17:19 +0200)
commitce5590102128ce7b4a68b400fca7fba2e658dab6
tree11d69799ba149f200b7c4e9694941eb06e5eaa2f
parentfa2d92873fda5b58f7167edd1036259ceb0ba485
bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen

BugLink: https://bugs.launchpad.net/bugs/2034469
[ Upstream commit 29ebbba7d46136cba324264e513a1e964ca16c0a ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
kernel/bpf/cgroup.c