summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/prog_tests/helper_restricted.c
diff options
context:
space:
mode:
authorDmitrii Banshchikov <me@ubique.spb.ru>2021-11-13 17:22:27 +0300
committerAlexei Starovoitov <ast@kernel.org>2021-11-16 07:37:11 +0300
commite60e6962c503f337531f80e2752423b5bd885443 (patch)
tree6d029ea816351ee368667c1244935862b898aeb1 /tools/testing/selftests/bpf/prog_tests/helper_restricted.c
parent5e0bc3082e2e403ac0753e099c2b01446bb35578 (diff)
downloadlinux-e60e6962c503f337531f80e2752423b5bd885443.tar.xz
selftests/bpf: Add tests for restricted helpers
This patch adds tests that bpf_ktime_get_coarse_ns(), bpf_timer_* and bpf_spin_lock()/bpf_spin_unlock() helpers are forbidden in tracing progs as their use there may result in various locking issues. Signed-off-by: Dmitrii Banshchikov <me@ubique.spb.ru> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20211113142227.566439-3-me@ubique.spb.ru
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/helper_restricted.c')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/helper_restricted.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/helper_restricted.c b/tools/testing/selftests/bpf/prog_tests/helper_restricted.c
new file mode 100644
index 000000000000..e1de5f80c3b2
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/helper_restricted.c
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <test_progs.h>
+#include "test_helper_restricted.skel.h"
+
+void test_helper_restricted(void)
+{
+ int prog_i = 0, prog_cnt;
+ int duration = 0;
+
+ do {
+ struct test_helper_restricted *test;
+ int maybeOK;
+
+ test = test_helper_restricted__open();
+ if (!ASSERT_OK_PTR(test, "open"))
+ return;
+
+ prog_cnt = test->skeleton->prog_cnt;
+
+ for (int j = 0; j < prog_cnt; ++j) {
+ struct bpf_program *prog = *test->skeleton->progs[j].prog;
+
+ maybeOK = bpf_program__set_autoload(prog, prog_i == j);
+ ASSERT_OK(maybeOK, "set autoload");
+ }
+
+ maybeOK = test_helper_restricted__load(test);
+ CHECK(!maybeOK, test->skeleton->progs[prog_i].name, "helper isn't restricted");
+
+ test_helper_restricted__destroy(test);
+ } while (++prog_i < prog_cnt);
+}