mirror of https://lore.kernel.org/lkml/
 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
  2026-08-11 14:19 ` [PATCH bpf v2 2/2] selftests/bpf: Exercise " Junseo Lim
  0 siblings, 2 replies; 4+ 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] 4+ messages in thread

end of thread, other threads:[~2026-08-11 15:10 UTC | newest]

Thread overview: 4+ 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®