bpf: prevent offloaded programs from running on host via tcx/netkit#11950
bpf: prevent offloaded programs from running on host via tcx/netkit#11950kernel-patches-daemon-bpf[bot] wants to merge 3 commits intobpf_basefrom
Conversation
|
Upstream branch: b5c111f |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 4319515564 via email |
5a2f726 to
0f927f5
Compare
|
Upstream branch: b5c111f |
f286f4b to
ede04b3
Compare
0f927f5 to
16f0aff
Compare
|
Upstream branch: b5c111f |
ede04b3 to
8c50787
Compare
16f0aff to
ee9631b
Compare
|
Upstream branch: 0c7ae13 |
8c50787 to
71703ac
Compare
ee9631b to
010a7e6
Compare
|
Upstream branch: f3b8c28 |
71703ac to
e421a00
Compare
010a7e6 to
c40937c
Compare
|
Upstream branch: 18fc650 |
An offloaded prog has its bpf_func replaced by bpf_prog_warn_on_exec() during bpf_prog_offload_compile(), since it is supposed to run on the NIC. Both current mprog users, tcx and netkit, dispatch programs via bpf_prog_run() on the host. Attaching an offloaded prog through any of their entry points (BPF_PROG_ATTACH, BPF_LINK_CREATE, BPF_LINK_UPDATE on tcx_*/netkit_*) ends up tripping the WARN on the first packet. Ideally this validation would live in tcx and netkit, since "must not be offloaded" is a property of those subsystems' software dispatch, not of the generic multi-prog attachment layer. However, those two together have six attach call sites and putting the check in each of them duplicates the same logic. mprog happens to be the only chokepoint shared by all of them, so add the check there instead and scope it to BPF_PROG_TYPE_SCHED_CLS via a small helper, so a future mprog user that legitimately accepts offloaded programs is not affected. Use bpf_prog_is_offloaded() rather than bpf_prog_is_dev_bound() + bpf_offload_dev_match() (as XDP does): bpf_prog_dev_bound_init() already rejects BPF_F_XDP_DEV_BOUND_ONLY for BPF_PROG_TYPE_SCHED_CLS, so a dev-bound SCHED_CLS program is always offloaded. The simpler check is sufficient and also rejects attaching a program offloaded to device A onto device B. Fixes: 053c8e1 ("bpf: Add generic attach/detach/query API for multi-progs") Reported-by: Yinhao Hu <dddddd@hust.edu.cn> Reported-by: Kaiyan Mei <M202472210@hust.edu.cn> Reported-by: Dongliang Mu <dzm91@hust.edu.cn> Closes: https://lore.kernel.org/bpf/64d8e2b5-a214-4f3c-b9e8-bcedbcb2c602@hust.edu.cn/ Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
bpf_xdp_link_update() calls dev_xdp_install() directly and bypasses dev_xdp_attach(), so the offload check that lived in dev_xdp_attach() does not apply. A user can create an XDP link in SKB or native mode with a regular program and then replace it via BPF_LINK_UPDATE with an offloaded program, whose bpf_func is bpf_prog_warn_on_exec(), tripping the WARN on the first packet. Move the check from dev_xdp_attach() into dev_xdp_install() so both the attach path and the link update path are covered by a single check at the actual install site. Fixes: 026a4c2 ("bpf, xdp: Implement LINK_UPDATE for BPF XDP link") Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev>
e421a00 to
7a7d49a
Compare
c40937c to
bc609a5
Compare
Pull request for series with
subject: bpf: prevent offloaded programs from running on host via tcx/netkit
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1085473