The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jiayuan Chen <jiayuan.chen@linux.dev>
To: bpf@vger.kernel.org
Cc: Jiayuan Chen <jiayuan.chen@linux.dev>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jiri Olsa <jolsa@kernel.org>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Shuah Khan <shuah@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Hangbin Liu <liuhangbin@gmail.com>,
	Krishna Kumar <krikku@gmail.com>,
	Samiullah Khawaja <skhawaja@google.com>,
	Martin Karsten <mkarsten@uwaterloo.ca>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: [PATCH bpf-next v4 0/3] bpf: prevent offloaded programs from running on host via tcx/netkit
Date: Mon, 10 Aug 2026 13:05:58 +0800	[thread overview]
Message-ID: <20260810050621.82035-1-jiayuan.chen@linux.dev> (raw)

Patch 1 fixes the reported bug [1]. Patch 2 fixes an old bug that was
already there. Patch 3 is a test that reproduces the bug in patch 2.

Patch 1 has no test here: the original report already has a reproducer,
and it needs netdevsim, which is not easy to do in a selftest.

An offloaded program runs on the NIC, so its bpf_func is set to
bpf_prog_warn_on_exec(). tcx, netkit and XDP run programs on the host, so
attaching an offloaded program to them hits the WARN on the first packet.
Patch 1 adds the check in bpf_mprog_attach(), the one place both tcx and
netkit go through. Patch 2 moves the XDP check into dev_xdp_install() so
the bpf_xdp_link_update() path is covered too.


[1]: https://lore.kernel.org/bpf/64d8e2b5-a214-4f3c-b9e8-bcedbcb2c602@hust.edu.cn/
 ------------[ cut here ]------------
 attempt to execute device eBPF program on the host!
 WARNING: kernel/bpf/offload.c:420 at 0x0, CPU#0: poc/337
 PKRU: 55555554
 Call Trace:
  <TASK>
  __dev_queue_xmit+0x22cb/0x3530
  ip_finish_output2+0x621/0x1a60
  ip_output+0x170/0x2e0
  ip_send_skb+0x129/0x180
  udp_send_skb+0x65d/0x1300
  udp_sendmsg+0x13bf/0x2000
  __sys_sendto+0x396/0x470
  __x64_sys_sendto+0xdc/0x1b0
  do_syscall_64+0x76/0x10a0
  entry_SYSCALL_64_after_hwframe+0x76/0x7e
 ---[ end trace 0000000000000000 ]---

v3 -> v4:
  - patch 2: also move the two device-bound checks, not just the offload
    one, so the link update path can't skip them (from the AI review on v3).
  - add patch 3, a selftest for the link update path.
v3: https://lore.kernel.org/bpf/20260425105942.223757-1-jiayuan.chen@linux.dev/

v2 -> v3:
  - Alexei said to do the check in one place instead of spreading it
    across attach paths. Put it in bpf_mprog_attach() for tcx/netkit and
    move the XDP check into dev_xdp_install(). Three patches became two.
v2: https://lore.kernel.org/bpf/20260424104201.217604-1-jiayuan.chen@linux.dev/

v1 -> v2:
  - tcx/netkit: also reject offloaded progs in the link update callback,
    not just attach (from the AI review on v1).
  - add a patch for the same hole in bpf_xdp_link_update().
v1: https://lore.kernel.org/bpf/20260423033609.252464-1-jiayuan.chen@linux.dev/

Jiayuan Chen (3):
  bpf, tcx, netkit: reject offloaded programs
  bpf, xdp: move offload check into dev_xdp_install()
  selftests/bpf: xdp: test dev_xdp_install() rejects device-bound
    program

 kernel/bpf/mprog.c                            | 11 +++++
 net/core/dev.c                                | 27 +++++-----
 .../bpf/prog_tests/xdp_dev_bound_only.c       | 49 +++++++++++++++++++
 3 files changed, 75 insertions(+), 12 deletions(-)

-- 
2.43.0


             reply	other threads:[~2026-08-10  5:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10  5:05 Jiayuan Chen [this message]
2026-08-10  5:05 ` [PATCH bpf-next v4 1/3] bpf, tcx, netkit: reject offloaded programs Jiayuan Chen
2026-08-10  5:06 ` [PATCH bpf-next v4 2/3] bpf, xdp: move offload check into dev_xdp_install() Jiayuan Chen
2026-08-10  5:06 ` [PATCH bpf-next v4 3/3] selftests/bpf: xdp: test dev_xdp_install() rejects device-bound program Jiayuan Chen
2026-08-10  6:30   ` bot+bpf-ci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260810050621.82035-1-jiayuan.chen@linux.dev \
    --to=jiayuan.chen@linux.dev \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eddyz87@gmail.com \
    --cc=edumazet@google.com \
    --cc=emil@etsalapatis.com \
    --cc=hawk@kernel.org \
    --cc=horms@kernel.org \
    --cc=ihor.solodrai@linux.dev \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=krikku@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=liuhangbin@gmail.com \
    --cc=martin.lau@linux.dev \
    --cc=memxor@gmail.com \
    --cc=mkarsten@uwaterloo.ca \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sdf@fomichev.me \
    --cc=shuah@kernel.org \
    --cc=skhawaja@google.com \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox