selftests/bpf: Fix erroneous bitmask operation
[platform/kernel/linux-rpi.git] / tools / testing / selftests / bpf / progs / test_global_func10.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <stddef.h>
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5 #include "bpf_misc.h"
6
7 struct Small {
8         long x;
9 };
10
11 struct Big {
12         long x;
13         long y;
14 };
15
16 __noinline int foo(const struct Big *big)
17 {
18         if (!big)
19                 return 0;
20
21         return bpf_get_prandom_u32() < big->y;
22 }
23
24 SEC("cgroup_skb/ingress")
25 __failure __msg("invalid indirect access to stack")
26 int global_func10(struct __sk_buff *skb)
27 {
28         const struct Small small = {.x = skb->len };
29
30         return foo((struct Big *)&small) ? 1 : 0;
31 }