* [PATCH bpf v2 RESEND 1/2] bpf: reject dev-bound-only programs on other devices
@ 2026-09-20 13:23 Weiming Shi
2026-09-20 13:23 ` [PATCH bpf v2 RESEND 2/2] selftests: net: test cross-device XDP dev-bound attachment Weiming Shi
0 siblings, 1 reply; 2+ messages in thread
From: Weiming Shi @ 2026-09-20 13:23 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, David S. Miller, Jakub Kicinski,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Eric Dumazet, Paolo Abeni, Simon Horman, Shuah Khan
Cc: bpf, netdev, linux-kselftest, linux-kernel, co+ac0a8c41de69121d,
Xiang Mei, Weiming Shi, stable
__bpf_offload_dev_match() falls back to comparing offdev pointers after an
exact netdev mismatch. Bound-only programs normally have NULL offdevs, so
unrelated netdevs compare equal. A bound-only program on an
offload-registered netdev can instead inherit a real offdev and match a
sibling port. With CAP_BPF and CAP_NET_ADMIN, a caller can use
bpf(BPF_LINK_CREATE) with a different target ifindex to run metadata kfuncs
specialized for the bound driver on the target driver's xdp_buff. Running a
veth-bound program on tun reads beyond tun's bare stack xdp_buff as a
veth_xdp_buff.
Oops: general protection fault, probably for non-canonical address
KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017]
RIP: 0010:veth_xdp_rx_timestamp (drivers/net/veth.c:1673)
Call Trace:
...
tun_build_skb (drivers/net/tun.c:1739)
tun_get_user (drivers/net/tun.c:1856)
tun_chr_write_iter (drivers/net/tun.c:2091)
vfs_write (fs/read_write.c:595 fs/read_write.c:687)
ksys_write (fs/read_write.c:739)
do_syscall_64 (arch/x86/entry/syscall_64.c:84)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
Kernel panic - not syncing: Fatal exception in interrupt
Restrict non-offloaded programs to exact netdev matches and retain the
shared-offdev fallback only for genuinely offloaded multi-port programs.
Cc: stable@vger.kernel.org
Fixes: 2b3486bc2d23 ("bpf: Introduce device-bound XDP programs")
Reported-by: <co+ac0a8c41de69121d@bugs.sh>
Link: https://lore.kernel.org/bpf/20260917161335.1020405-2-bestswngs@gmail.com/
Assisted-by: LLM
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
---
Resend:
- Start a new thread after the previous v2 was threaded under v1; no patch
changes.
Changes in v2:
- Drop the redundant offdev NULL check.
- State the capability requirements instead of using attacker wording.
- Move the regression test to patch 2.
kernel/bpf/offload.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
index 0d6f55695..d85539981 100644
--- a/kernel/bpf/offload.c
+++ b/kernel/bpf/offload.c
@@ -698,6 +698,8 @@ static bool __bpf_offload_dev_match(struct bpf_prog *prog,
return false;
if (offload->netdev == netdev)
return true;
+ if (!bpf_prog_is_offloaded(prog->aux))
+ return false;
ondev1 = bpf_offload_find_netdev(offload->netdev);
ondev2 = bpf_offload_find_netdev(netdev);
--
2.55.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH bpf v2 RESEND 2/2] selftests: net: test cross-device XDP dev-bound attachment
2026-09-20 13:23 [PATCH bpf v2 RESEND 1/2] bpf: reject dev-bound-only programs on other devices Weiming Shi
@ 2026-09-20 13:23 ` Weiming Shi
0 siblings, 0 replies; 2+ messages in thread
From: Weiming Shi @ 2026-09-20 13:23 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
Ihor Solodrai, David S. Miller, Jakub Kicinski,
Jesper Dangaard Brouer, John Fastabend, Stanislav Fomichev,
Eric Dumazet, Paolo Abeni, Simon Horman, Shuah Khan
Cc: bpf, netdev, linux-kselftest, linux-kernel, co+ac0a8c41de69121d,
Xiang Mei, Weiming Shi
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@gmail.com/
Assisted-by: LLM
Signed-off-by: Weiming Shi <bestswngs@gmail.com>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-20 13:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-20 13:23 [PATCH bpf v2 RESEND 1/2] bpf: reject dev-bound-only programs on other devices Weiming Shi
2026-09-20 13:23 ` [PATCH bpf v2 RESEND 2/2] selftests: net: test cross-device XDP dev-bound attachment Weiming Shi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®