[PATCH bpf 2/2] selftests/bpf: Add XDP dispatcher FineIBT regression test
From: David Windsor
Date: Tue Jul 07 2026 - 22:58:31 EST
Add a regression test for the x86 BPF dispatcher's indirect-jump fallback
under FineIBT.
This test can crash the kernel on an unfixed FineIBT build and so should
be run in a VM.
Signed-off-by: David Windsor <dwindsor@xxxxxxxxx>
---
.../bpf/prog_tests/xdp_dispatcher_fineibt.c | 47 +++++++++++++++++++
.../bpf/progs/xdp_dispatcher_fineibt.c | 18 +++++++
2 files changed, 65 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_dispatcher_fineibt.c
create mode 100644 tools/testing/selftests/bpf/progs/xdp_dispatcher_fineibt.c
diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_dispatcher_fineibt.c b/tools/testing/selftests/bpf/prog_tests/xdp_dispatcher_fineibt.c
new file mode 100644
index 000000000000..2d3fc4034eb9
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/xdp_dispatcher_fineibt.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 David Windsor */
+
+/*
+ * Regression test for the x86 BPF dispatcher's indirect-jump fallback
+ * under FineIBT.
+ *
+ * WARNING
+ * -------
+ * This test can crash the kernel, thus should be run in a VM.
+ */
+#include <uapi/linux/if_link.h>
+#include <test_progs.h>
+#include <network_helpers.h>
+#include "xdp_dispatcher_fineibt.skel.h"
+
+#define IFINDEX_LO 1
+
+void test_xdp_dispatcher_fineibt(void)
+{
+ struct xdp_dispatcher_fineibt *skel;
+ int err, attached_fd, unattached_fd;
+
+ LIBBPF_OPTS(bpf_test_run_opts, topts,
+ .data_in = &pkt_v4,
+ .data_size_in = sizeof(pkt_v4),
+ );
+
+ skel = xdp_dispatcher_fineibt__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
+ return;
+
+ attached_fd = bpf_program__fd(skel->progs.xdp_dispatcher_attached);
+ unattached_fd = bpf_program__fd(skel->progs.xdp_dispatcher_unattached);
+
+ err = bpf_xdp_attach(IFINDEX_LO, attached_fd, XDP_FLAGS_SKB_MODE, NULL);
+ if (!ASSERT_OK(err, "attach_prog"))
+ goto out;
+
+ err = bpf_prog_test_run_opts(unattached_fd, &topts);
+ ASSERT_OK(err, "unattached_test_run");
+ ASSERT_EQ(topts.retval, XDP_PASS, "unattached_retval");
+
+ bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
+out:
+ xdp_dispatcher_fineibt__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/xdp_dispatcher_fineibt.c b/tools/testing/selftests/bpf/progs/xdp_dispatcher_fineibt.c
new file mode 100644
index 000000000000..b49b84f01c8e
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/xdp_dispatcher_fineibt.c
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2026 David Windsor */
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+
+SEC("xdp")
+int xdp_dispatcher_attached(struct xdp_md *ctx)
+{
+ return XDP_PASS;
+}
+
+SEC("xdp")
+int xdp_dispatcher_unattached(struct xdp_md *ctx)
+{
+ return XDP_PASS;
+}
+
+char _license[] SEC("license") = "GPL";
--
2.53.0