Skip to content

Commit

Permalink
selftests/bpf: Add more tests for check_max_stack_depth bug
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
kkdwivedi authored and Alexei Starovoitov committed Jul 18, 2023
1 parent b5e9ad5 commit 824adae
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tools/testing/selftests/bpf/progs/async_stack_depth.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ static int timer_cb(void *map, int *key, struct bpf_timer *timer)
return buf[69];
}

__attribute__((noinline))
static int bad_timer_cb(void *map, int *key, struct bpf_timer *timer)
{
volatile char buf[300] = {};
return buf[255] + timer_cb(NULL, NULL, NULL);
}

SEC("tc")
__failure __msg("combined stack size of 2 calls")
int prog(struct __sk_buff *ctx)
__failure __msg("combined stack size of 2 calls is 576. Too large")
int pseudo_call_check(struct __sk_buff *ctx)
{
struct hmap_elem *elem;
volatile char buf[256] = {};
Expand All @@ -37,4 +44,18 @@ int prog(struct __sk_buff *ctx)
return bpf_timer_set_callback(&elem->timer, timer_cb) + buf[0];
}

SEC("tc")
__failure __msg("combined stack size of 2 calls is 608. Too large")
int async_call_root_check(struct __sk_buff *ctx)
{
struct hmap_elem *elem;
volatile char buf[256] = {};

elem = bpf_map_lookup_elem(&hmap, &(int){0});
if (!elem)
return 0;

return bpf_timer_set_callback(&elem->timer, bad_timer_cb) + buf[0];
}

char _license[] SEC("license") = "GPL";

0 comments on commit 824adae

Please sign in to comment.