All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf v2 0/2] bpf: Reject negative optlen in cgroup getsockopt hook
@ 2026-08-11 14:19 Junseo Lim
  2026-08-11 14:19 ` [PATCH bpf v2 1/2] " Junseo Lim
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Junseo Lim @ 2026-08-11 14:19 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau
  Cc: Stanislav Fomichev, Song Liu, Yonghong Song, Jiri Olsa,
	Emil Tsalapatis, bpf, linux-kernel, Sechang Lim

A cgroup getsockopt BPF program can set a negative optlen after the
kernel getsockopt handler has run. For TCP_ZEROCOPY_RECEIVE, the
kernel-buffer hook did not validate the lower bound and the negative
value could reach copy_to_sockptr() as a size_t.

Patch 1 rejects negative optlen values in the kernel-buffer hook.
Patch 2 adds a test_progs selftest that reproduces the issue through
TCP_ZEROCOPY_RECEIVE.

For patch 2, the userspace-visible errno is EFAULT on both fixed and
unfixed kernels, so the broken behavior cannot be detected from the
getsockopt() return value alone. The selftest exercises the problematic
path and can be used to reproduce the hardened usercopy warning on
unpatched kernels.

Changelog:
v1 -> v2:
- Add the selftest for negative optlen.
- Add Emil's Reviewed-by tag.
- Add Reported-by tag.

v1: https://lore.kernel.org/bpf/20260726070122.2407344-1-zirajs7@gmail.com/T/

Junseo Lim (2):
  bpf: Reject negative optlen in cgroup getsockopt hook
  selftests/bpf: Exercise negative optlen in cgroup getsockopt hook


 kernel/bpf/cgroup.c                           |  2 +-
 .../selftests/bpf/prog_tests/sockopt.c        | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

-- 
2.55.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-08-17  9:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-11 14:19 [PATCH bpf v2 0/2] bpf: Reject negative optlen in cgroup getsockopt hook Junseo Lim
2026-08-11 14:19 ` [PATCH bpf v2 1/2] " Junseo Lim
2026-08-11 14:19 ` [PATCH bpf v2 2/2] selftests/bpf: Exercise " Junseo Lim
2026-08-11 15:10   ` bot+bpf-ci
2026-08-17  4:57     ` Junseo Lim
2026-08-17  9:50 ` [PATCH bpf v2 0/2] bpf: Reject " patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.