[PATCH 4/4] selftests/bpf: add exception handling test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Many tests cover exception table creation, but none, at least on s390,
actually trigger the exception handler. This might be due to s390
allowing NULL dereferences in kernel mode (duh!).

This patch implements a test that follows garbage pointers and triggers
the exception handler on s390.

Signed-off-by: Ilya Leoshkevich <iii@xxxxxxxxxxxxx>
---
 .../selftests/bpf/prog_tests/bpf_iter.c       | 17 ++++++++++++++++
 .../selftests/bpf/progs/bpf_iter_exception.c  | 20 +++++++++++++++++++
 2 files changed, 37 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_iter_exception.c

diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
index fed42755416d..733e00dabd84 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_iter.c
@@ -15,6 +15,7 @@
 #include "bpf_iter_test_kern2.skel.h"
 #include "bpf_iter_test_kern3.skel.h"
 #include "bpf_iter_test_kern4.skel.h"
+#include "bpf_iter_exception.skel.h"
 
 static int duration;
 
@@ -455,6 +456,20 @@ static void test_overflow(bool test_e2big_overflow, bool ret1)
 	bpf_iter_test_kern4__destroy(skel);
 }
 
+static void test_exception(void)
+{
+	struct bpf_iter_exception *skel;
+
+	skel = bpf_iter_exception__open_and_load();
+	if (CHECK(!skel, "bpf_iter_exception__open_and_load",
+		  "skeleton open_and_load failed\n"))
+		return;
+
+	do_dummy_read(skel->progs.dump_ipv6_route);
+
+	bpf_iter_exception__destroy(skel);
+}
+
 void test_bpf_iter(void)
 {
 	if (test__start_subtest("btf_id_or_null"))
@@ -491,4 +506,6 @@ void test_bpf_iter(void)
 		test_overflow(true, false);
 	if (test__start_subtest("prog-ret-1"))
 		test_overflow(false, true);
+	if (test__start_subtest("exception"))
+		test_exception();
 }
diff --git a/tools/testing/selftests/bpf/progs/bpf_iter_exception.c b/tools/testing/selftests/bpf/progs/bpf_iter_exception.c
new file mode 100644
index 000000000000..ee2a08a40d5d
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/bpf_iter_exception.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0
+#include "bpf_iter.h"
+#include "bpf_tracing_net.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+SEC("iter/ipv6_route")
+int dump_ipv6_route(struct bpf_iter__ipv6_route *ctx)
+{
+	struct seq_file *seq = ctx->meta->seq;
+	struct fib6_info *rt = ctx->rt;
+
+	if (rt)
+		/* Follow pointers as recklessly as possible. */
+		BPF_SEQ_PRINTF(seq, "%s\n",
+			       &rt->nh->nh_info->fib6_nh.fib_nh_dev->name);
+	return 0;
+}
-- 
2.25.4




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux