]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/bpf: Restrict bpf_set_retval argument in sk_bypass_prot_mem
authorXu Kuohai <xukuohai@huawei.com>
Fri, 5 Jun 2026 14:02:41 +0000 (14:02 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 5 Jun 2026 22:55:43 +0000 (15:55 -0700)
Test sk_bypass_prot_mem passes an unchecked value as argument to helper
bpf_set_retval(). The argument can be outside the valid range enforced
by the strict retval validation added in the next patch.

Restrict the argument to -EFAULT when it is outside the valid range, so
the test will not be rejected by the verifier when retval validation
is enforced.

Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Link: https://lore.kernel.org/r/20260605140243.664590-2-xukuohai@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/progs/sk_bypass_prot_mem.c

index 09a00d11ffcc43d391ddc8d66e389cd454459f5c..bae5283fca6b06615753f9d4763a101b222b0a2a 100644 (file)
@@ -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;
 }