Skip to content

Commit 824adae

Browse files
kkdwivediAlexei Starovoitov
authored andcommitted
selftests/bpf: Add more tests for check_max_stack_depth bug
Another test which now exercies the path of the verifier where it will explore call chains rooted at the async callback. Without the prior fixes, this program loads successfully, which is incorrect. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Link: https://lore.kernel.org/r/20230717161530.1238-4-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent b5e9ad5 commit 824adae

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tools/testing/selftests/bpf/progs/async_stack_depth.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ static int timer_cb(void *map, int *key, struct bpf_timer *timer)
2222
return buf[69];
2323
}
2424

25+
__attribute__((noinline))
26+
static int bad_timer_cb(void *map, int *key, struct bpf_timer *timer)
27+
{
28+
volatile char buf[300] = {};
29+
return buf[255] + timer_cb(NULL, NULL, NULL);
30+
}
31+
2532
SEC("tc")
26-
__failure __msg("combined stack size of 2 calls")
27-
int prog(struct __sk_buff *ctx)
33+
__failure __msg("combined stack size of 2 calls is 576. Too large")
34+
int pseudo_call_check(struct __sk_buff *ctx)
2835
{
2936
struct hmap_elem *elem;
3037
volatile char buf[256] = {};
@@ -37,4 +44,18 @@ int prog(struct __sk_buff *ctx)
3744
return bpf_timer_set_callback(&elem->timer, timer_cb) + buf[0];
3845
}
3946

47+
SEC("tc")
48+
__failure __msg("combined stack size of 2 calls is 608. Too large")
49+
int async_call_root_check(struct __sk_buff *ctx)
50+
{
51+
struct hmap_elem *elem;
52+
volatile char buf[256] = {};
53+
54+
elem = bpf_map_lookup_elem(&hmap, &(int){0});
55+
if (!elem)
56+
return 0;
57+
58+
return bpf_timer_set_callback(&elem->timer, bad_timer_cb) + buf[0];
59+
}
60+
4061
char _license[] SEC("license") = "GPL";

0 commit comments

Comments
 (0)