Re: [PATCH bpf v3 2/3] selftests/bpf: Fix cgroup bpf tests broken by bpf_set_retval validation

From: Emil Tsalapatis

Date: Mon Jun 01 2026 - 01:46:03 EST


On Sat May 30, 2026 at 6:12 AM EDT, Xu Kuohai wrote:
> From: Xu Kuohai <xukuohai@xxxxxxxxxx>
>
> Add explicit return value checks for cgroup bpf progs rejected by the
> bpf_set_retval validation.
>
> Signed-off-by: Xu Kuohai <xukuohai@xxxxxxxxxx>

Since these tests are breaking with patch 1 you should put this patch
before them to avoid the breakage in the first place.

> ---
> .../selftests/bpf/progs/cgroup_getset_retval_hooks.c | 6 +++++-
> tools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c | 2 ++
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/cgroup_getset_retval_hooks.c b/tools/testing/selftests/bpf/progs/cgroup_getset_retval_hooks.c
> index 13dfb4bbfd28..c0bfa2d12dc7 100644
> --- a/tools/testing/selftests/bpf/progs/cgroup_getset_retval_hooks.c
> +++ b/tools/testing/selftests/bpf/progs/cgroup_getset_retval_hooks.c
> @@ -2,12 +2,16 @@
>
> #include <linux/bpf.h>
> #include <bpf/bpf_helpers.h>
> +#include <errno.h>
> +#include "err.h"
>
> #define BPF_RETVAL_HOOK(name, section, ctx, expected_err) \
> __attribute__((__section__("?" section))) \
> int name(struct ctx *_ctx) \
> { \
> - bpf_set_retval(bpf_get_retval()); \
> + int val = bpf_get_retval(); \
> + set_if_not_errno_or_zero(val, -EFAULT); \
> + bpf_set_retval(val); \
> return 1; \
> }
>
> diff --git a/tools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c b/tools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c
> index 09a00d11ffcc..bae5283fca6b 100644
> --- a/tools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c
> +++ b/tools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c
> @@ -5,6 +5,7 @@
> #include <bpf/bpf_helpers.h>
> #include <bpf/bpf_tracing.h>
> #include <errno.h>
> +#include "err.h"
>
> extern int tcp_memory_per_cpu_fw_alloc __ksym;
> extern int udp_memory_per_cpu_fw_alloc __ksym;
> @@ -97,6 +98,7 @@ int sock_create(struct bpf_sock *ctx)
> return 1;
>
> err:
> + set_if_not_errno_or_zero(err, -EFAULT);
> bpf_set_retval(err);
> return 0;
> }