From: Simon Horman <horms@kernel.org>
To: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: netdev@vger.kernel.org, kuba@kernel.org, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com,
sdf@fomichev.me, martin.lau@kernel.org, daniel@iogearbox.net,
qmo@kernel.org, bpf@vger.kernel.org, jiri@resnulli.us,
stable@vger.kernel.org, sashiko-bot@kernel.org,
victor@mojatatu.com
Subject: Re: [PATCH net v2 1/3] netdevsim: reject cls_bpf programs bound to another device
Date: Fri, 16 Oct 2026 19:22:12 +0100 [thread overview]
Message-ID: <20261016182212.GK363352@horms.kernel.org> (raw)
In-Reply-To: <QDISC-PYC7.v2.20261010165947-2@mojatatu.com>
On Sat, Oct 10, 2026 at 05:02:48PM -0400, Jamal Hadi Salim wrote:
> The issue:
> nsim_bpf_setup_tc_block_cb() installs any device-bound SCHED_CLS program
> without checking that its offload device matches the target netdev. The
> core cls_bpf attach path rejects a mismatching program, but a netdev that
> joins a shared block later is replayed the stored filter by
> cls_bpf_reoffload() before it is inserted into block->ports, so the
> attach-time check cannot see it. The driver callback is the
> authoritative per-device acceptance boundary and must enforce the match
> itself, as nfp already does in nfp_net_bpf_offload().
>
> Without the check, replaying a device-bound program onto a different
> bpf_offload_dev installs it into that device's netdevsim state, which
> trips the WARN in nsim_bpf_uninit() (ns->bpf_offloaded set on a foreign
> device) and can dereference a NULL prog->aux->offload in
> nsim_prog_set_loaded().
>
> The Fix:
> Reject a device-bound program whose offload device does not match the
> target netdev, with -EINVAL and an extack so the rejected replay is not
> silent. The check is intentionally narrower than nfp's: it fires only
> for a dev-bound program, so nsim's bpf_tc_non_bound_accept mode (which
> admits an unbound program onto the device) is unaffected. Teardown is
> never blocked: the guard is on the program being installed and an unbind
> passes cls_bpf.prog = NULL.
>
> Conditions to recreate the bug:
> - CONFIG_NETDEVSIM=y, CONFIG_NET_CLS_BPF=y
> - load and pin a dev-bound SCHED_CLS program for netdevsim device B
> - install the program on a shared block owned by B
> - add an independently backed netdevsim device C to that block; the
> bind replays the filter to C's callback, and C's
> ports/0/bpf_offloaded_id takes the B-bound program id.
>
> The reported Sashiko review is at
> https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260809094418.901607-1-jhs@mojatatu.com
>
> Fixes: 31d3ad832948 ("netdevsim: add bpf offload support")
> Reported-by: Sashiko (nipa) <sashiko-bot@kernel.org>
> Link: https://lore.kernel.org/netdev/20260809094418.901607-1-jhs@mojatatu.com/
> Link: https://lore.kernel.org/netdev/QDISC-PYC7.v1.20261003103747@mojatatu.com/
> Cc: stable@vger.kernel.org
> Reviewed-by: Victor Nogueira <victor@mojatatu.com>
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Reviewed-by: Simon Horman <horms@kernel.org>
next prev parent reply other threads:[~2026-10-16 18:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-10 21:02 [PATCH net v2 0/3] net/sched: cls_bpf: accept dev-bound programs on shared blocks Jamal Hadi Salim
2026-10-10 21:02 ` [PATCH net v2 1/3] netdevsim: reject cls_bpf programs bound to another device Jamal Hadi Salim
2026-10-11 21:03 ` netdev-bot+sashiko
2026-10-11 23:50 ` Jamal Hadi Salim
2026-10-16 18:22 ` Simon Horman [this message]
2026-10-10 21:02 ` [PATCH net v2 2/3] net/sched: cls_bpf: accept dev-bound programs on shared blocks Jamal Hadi Salim
2026-10-11 21:03 ` netdev-bot+sashiko
2026-10-11 23:51 ` Jamal Hadi Salim
2026-10-16 18:23 ` Simon Horman
2026-10-10 21:02 ` [PATCH net v2 3/3] selftests: net: exercise dev-bound cls_bpf " Jamal Hadi Salim
2026-10-11 21:03 ` netdev-bot+sashiko
2026-10-11 23:49 ` Jamal Hadi Salim
2026-10-11 23:50 ` Jamal Hadi Salim
2026-10-16 18:23 ` Simon Horman
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=20261016182212.GK363352@horms.kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=qmo@kernel.org \
--cc=sashiko-bot@kernel.org \
--cc=sdf@fomichev.me \
--cc=stable@vger.kernel.org \
--cc=victor@mojatatu.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.