bpf: allow cgroup progs to export custom errnos to userspace
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 15 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | bpf: Make BPF_PROG_RUN_ARRAY return -errno instead of allow booleaninclude/ kernel/ security/ | +25 | 1 reply | |
| 2/3 | bpf: Add cgroup helper bpf_export_errno to get/set exported errno valueinclude/ include/ kernel/ +1 more | +63 | 13 replies | |
| 3/3 | selftests/bpf: Test bpf_export_errno behavior with cgroup/sockopttools/ tools/ tools/ | +569 | 1 reply |
Reviews trailers per patch
All 3 patches have a Reviewed-by or Acked-by.
| Patch | Stanislav Fomichev | Song Liu |
|---|---|---|
| 1/3 | R-b | A-b |
| 2/3 | R-b | A-b |
| 3/3 | R-b | A-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH bpf-next 0/3] bpf: allow cgroup progs to export custom errnos to userspace
From: YiFei Zhu <[email protected]>
Right now, most cgroup hooks are best used for permission checks. They can only reject a syscall with -EPERM, so a cause of a rejection, if the rejected by eBPF cgroup hooks, is ambiguous to userspace. Additionally, if the syscalls are implemented in eBPF, all permission checks and the implementation has to happen within the same filter, as programs executed later in the series of progs are unaware of the return values return by the previous progs.
This patch series adds a helper, bpf_export_errno, that allows hooks to get/set the errno exported by eBPF to userspace. Invoking the helper with a positive errno will set the exported errno, and invoking the helper with zero will return the previously set errno. This means that an errno, once set, can be overridden but cannot be unset. This also allows later progs to retrieve errnos set by previous progs.
For legacy programs that rejects a syscall without setting the exported errno, for backwards compatibility, if a prog rejects without itself or a prior prog setting errno, the errno is set by the kernel to -EPERM.
Tests have been added in this series to test the behavior of the helper with cgroup setsockopt getsockopt hooks.
Patch 1 changes the API of macros to prepare for the next patch and
should be a no-op.
Patch 2 implements the helper and the tracking of errno. Patch 3 tests the behaviors of the helper.
YiFei Zhu (3):
bpf: Make BPF_PROG_RUN_ARRAY return -errno instead of allow boolean
bpf: Add cgroup helper bpf_export_errno to get/set exported errno
value
selftests/bpf: Test bpf_export_errno behavior with cgroup/sockopt
include/linux/bpf.h | 27 +- include/uapi/linux/bpf.h | 14 + kernel/bpf/cgroup.c | 65 ++- security/device_cgroup.c | 2 +- tools/include/uapi/linux/bpf.h | 14 + .../bpf/prog_tests/cgroup_export_errno.c | 472 ++++++++++++++++++ .../progs/cgroup_export_errno_getsockopt.c | 45 ++ .../progs/cgroup_export_errno_setsockopt.c | 52 ++ 8 files changed, 651 insertions(+), 40 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/cgroup_export_errno.c create mode 100644 tools/testing/selftests/bpf/progs/cgroup_export_errno_getsockopt.c create mode 100644 tools/testing/selftests/bpf/progs/cgroup_export_errno_setsockopt.c
--
2.33.0