[PATCH bpf v2 RESEND 2/2] selftests: net: test cross-device XDP dev-bound attachment

From: Weiming Shi

Date: Sun Sep 20 2026 - 09:24:31 EST


Add a regression test which loads dev-bound-only XDP programs on both ends
of a veth pair. Verify that attaching one program to the other device is
rejected with the expected extack.

The second program keeps a bound-only registration for the target device,
recreating the NULL-offdev collision fixed by the previous patch.

Link: https://lore.kernel.org/bpf/20260917161335.1020405-2-bestswngs@xxxxxxxxx/
Assisted-by: LLM
Signed-off-by: Weiming Shi <bestswngs@xxxxxxxxx>
---
Resend:
- Start a new thread after the previous v2 was threaded under v1; no patch
changes.

Changes in v2:
- New patch.

tools/testing/selftests/net/bpf_offload.py | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/tools/testing/selftests/net/bpf_offload.py b/tools/testing/selftests/net/bpf_offload.py
index c856d266c..017910b4d 100755
--- a/tools/testing/selftests/net/bpf_offload.py
+++ b/tools/testing/selftests/net/bpf_offload.py
@@ -995,6 +995,24 @@ try:
rm("/sys/fs/bpf/devbound")
sim.wait_for_flush()

+ start_test("Test dev-bound program on a different device...")
+ cmd("ip link add bpfveth0 type veth peer name bpfveth1")
+ try:
+ bpftool_prog_load("sample_ret0.bpf.o", "/sys/fs/bpf/devbound0",
+ dev_bind="bpfveth0")
+ bpftool_prog_load("sample_ret0.bpf.o", "/sys/fs/bpf/devbound1",
+ dev_bind="bpfveth1")
+ ret, _, err = ip("link set dev bpfveth1 xdpdrv " +
+ bpf_pinned("/sys/fs/bpf/devbound0"), fail=False,
+ include_stderr=True)
+ fail(ret == 0, "dev-bound program attached to a different device")
+ check_extack(err, "Program bound to different device.", args)
+ finally:
+ cmd("ip link del bpfveth0", fail=False)
+ rm("/sys/fs/bpf/devbound0")
+ rm("/sys/fs/bpf/devbound1")
+ bpftool_prog_list_wait(expected=0)
+
start_test("Test XDP load failure...")
sim.dfs["dev/bpf_bind_verifier_accept"] = 0
ret, _, err = bpftool_prog_load("sample_ret0.bpf.o", "/sys/fs/bpf/offload",
--
2.55.0