mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf 0/3] Add validation for bpf_set_retval helper
@ 2026-05-30 10:12 Xu Kuohai
  2026-05-30 10:12 ` [PATCH bpf v3 1/3] bpf: Add validation for bpf_set_retval argument Xu Kuohai
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Xu Kuohai @ 2026-05-30 10:12 UTC (permalink / raw)
  To: bpf, linux-kernel
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Eduard Zingerman, Kumar Kartikeya Dwivedi,
	Yonghong Song, Stanislav Fomichev, YiFei Zhu, Matt Bobrowski,
	Quan Sun

The bpf_set_retval() helper is used by cgroup BPF programs to set the
return value of the kernel hook. The argument type for this helper is
ARG_ANYTHING. This allows setting a positive value, which no cgroup
hook expects and can cause issues, such as the kernel panic reported
in [1].

This series adds validation for the argument of the bpf_set_retval()
helper.

For BPF_LSM_CGROUP, the same validation as BPF_LSM_MAC is enforced,
i.e. validate the argument against the LSM hook specific range, which
is returned by bpf_lsm_get_retval_range().

For all other cgroup program types, restrict the argument to
[-MAX_ERRNO, 0], which matches the kernel convention of 0 for success
and negative errno for error.

[1] https://lore.kernel.org/all/567d3206-74a5-44e5-99c6-779c425f399e@std.uestc.edu.cn

v3:
- Mark R1 as precise to prevent validation bypass via branch pruning (sashiko)

v2: https://lore.kernel.org/bpf/20260530055557.549474-1-xukuohai@huaweicloud.com/
- Extend validation from LSM cgroup BPF type to all cgroup BPF types (sashiko)

v1: https://lore.kernel.org/bpf/20260523085806.417723-1-xukuohai@huaweicloud.com/

Xu Kuohai (3):
  bpf: Add validation for bpf_set_retval argument
  selftests/bpf: Fix cgroup bpf tests broken by bpf_set_retval
    validation
  selftests/bpf: Add tests for bpf_set_retval validation

 kernel/bpf/verifier.c                         |  25 ++++
 .../selftests/bpf/prog_tests/verifier.c       |   2 +
 .../bpf/progs/cgroup_getset_retval_hooks.c    |   6 +-
 .../selftests/bpf/progs/sk_bypass_prot_mem.c  |   2 +
 .../selftests/bpf/progs/verifier_cgroup.c     | 114 ++++++++++++++++++
 5 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/bpf/progs/verifier_cgroup.c

-- 
2.43.0


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

end of thread, other threads:[~2026-06-01 13:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-30 10:12 [PATCH bpf 0/3] Add validation for bpf_set_retval helper Xu Kuohai
2026-05-30 10:12 ` [PATCH bpf v3 1/3] bpf: Add validation for bpf_set_retval argument Xu Kuohai
2026-05-30 10:12 ` [PATCH bpf v3 2/3] selftests/bpf: Fix cgroup bpf tests broken by bpf_set_retval validation Xu Kuohai
2026-05-30 11:11   ` bot+bpf-ci
2026-06-01  5:45   ` Emil Tsalapatis
2026-06-01 13:05     ` Xu Kuohai
2026-05-30 10:12 ` [PATCH bpf v3 3/3] selftests/bpf: Add tests for " Xu Kuohai

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®