Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Add testcase for async callback return value failure

A previous commit updated the verifier to print an accurate failure
message for when someone specifies a nonzero return value from an async
callback. This adds a testcase for validating that the verifier emits
the correct message in such a case.

Signed-off-by: David Vernet <void@manifault.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20231009161414.235829-2-void@manifault.com

authored by

David Vernet and committed by
Daniel Borkmann
57ddeb86 82995598

+51 -2
+4 -2
tools/testing/selftests/bpf/prog_tests/timer.c
··· 2 2 /* Copyright (c) 2021 Facebook */ 3 3 #include <test_progs.h> 4 4 #include "timer.skel.h" 5 + #include "timer_failure.skel.h" 5 6 6 7 static int timer(struct timer *timer_skel) 7 8 { ··· 50 49 51 50 timer_skel = timer__open_and_load(); 52 51 if (!ASSERT_OK_PTR(timer_skel, "timer_skel_load")) 53 - goto cleanup; 52 + return; 54 53 55 54 err = timer(timer_skel); 56 55 ASSERT_OK(err, "timer"); 57 - cleanup: 58 56 timer__destroy(timer_skel); 57 + 58 + RUN_TESTS(timer_failure); 59 59 }
+47
tools/testing/selftests/bpf/progs/timer_failure.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ 3 + 4 + #include <linux/bpf.h> 5 + #include <time.h> 6 + #include <errno.h> 7 + #include <bpf/bpf_helpers.h> 8 + #include "bpf_misc.h" 9 + #include "bpf_tcp_helpers.h" 10 + 11 + char _license[] SEC("license") = "GPL"; 12 + 13 + struct elem { 14 + struct bpf_timer t; 15 + }; 16 + 17 + struct { 18 + __uint(type, BPF_MAP_TYPE_ARRAY); 19 + __uint(max_entries, 1); 20 + __type(key, int); 21 + __type(value, struct elem); 22 + } timer_map SEC(".maps"); 23 + 24 + static int timer_cb_ret1(void *map, int *key, struct bpf_timer *timer) 25 + { 26 + if (bpf_get_smp_processor_id() % 2) 27 + return 1; 28 + else 29 + return 0; 30 + } 31 + 32 + SEC("fentry/bpf_fentry_test1") 33 + __failure __msg("should have been in (0x0; 0x0)") 34 + int BPF_PROG2(test_ret_1, int, a) 35 + { 36 + int key = 0; 37 + struct bpf_timer *timer; 38 + 39 + timer = bpf_map_lookup_elem(&timer_map, &key); 40 + if (timer) { 41 + bpf_timer_init(timer, &timer_map, CLOCK_BOOTTIME); 42 + bpf_timer_set_callback(timer, timer_cb_ret1); 43 + bpf_timer_start(timer, 1000, 0); 44 + } 45 + 46 + return 0; 47 + }