Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795036728; b=4Mf6P47NYjCQA/79UCcQiEB3eej+sG0K3KCAK8OS07PlhUlYVZUY/NdBNywXtd+mshln 0sDT0Y1f0rVBj8gAC4GzCL075AaXf1P+JVDAfAwT12GN4r6lla8qVzbgs1nAlHapmnVyE TanxgjBENh13PenPJCzd77iKznhVRmm8VHkhQPZOzsbKd7mnKV0kR2RLrKoNzlBHohDqD UgscuY8ShTI3uenh9r+YJ7Rz3tSdLbPjT1C2aWvqlB5MK9XupVRuwWOkcVQrFL8gmxY9s uRV49a/Md1abILGV+e4k8Bj2JACK+QK2TdRRfH+YvzA+sOsAoRgu974iFOu9g8OS1MA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795036728; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=hLW/UpXo761epnwGcUPXEs9uq4kjnFziYBuBTZy+vPY=; b=RsSsNmYNnF5kWJxDtKAIr3Q1k42mBVbdKBfzUW9S/fq2x21AOqSPQlf7dmSFJGqpFcwD sfG3ipACoEIdeQa2aUj8ZTxJoV9d3rL8TppIOXGDpuMnjra/klwHAAfMsxqKoo2FNFGZ3 kNPprenpCbLd5d9dA2aB/mZpdIzxEBdV2lTYg3TuDfDVJqn4UY4DrBaJ5GbV+5BTMtvSW QHlgjInx4RJdmVVhylSTYs0+raGb3z1CyudTZz8aGtf6+ol4TcKQgytJvGp5ct+wYMx3j UhBZ6v2lUgTLO37JhaTQOjcy4FmEmyd15lm2rtwm+6FwFXzzEESEz6TZxGD4lKH2kjQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hLINFTo5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80BDD606A339; Wed, 18 Nov 2026 21:18:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hLINFTo5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D13551F000C4; Wed, 18 Nov 2026 21:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795036728; bh=hLW/UpXo761epnwGcUPXEs9uq4kjnFziYBuBTZy+vPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hLINFTo5WU1bWISkkw+OPlIiGGc4GFdLUcCvvGJBQh6na4tvm3IGhc69Lza6OhJwQ XYet4uCuhin2MXWkRfdGOp+lsWDFL//SWvUpgUG2xuCuafTPtv0MVnlI6P0cnivguW fm94mD/uPOkejN9b1rDsWxrA9eomEaefr+kNQCbo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Sashiko (nipa)" , Victor Nogueira , Jamal Hadi Salim , Simon Horman , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 1164/3318] netdevsim: reject cls_bpf programs bound to another device Date: Wed, 18 Nov 2026 15:29:46 +0100 Message-ID: <20261118150355.036016608@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jamal Hadi Salim [ Upstream commit 5820ca58b409402505b9e904d1ded4908e0b6b81 ] 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) 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 Signed-off-by: Jamal Hadi Salim Reviewed-by: Simon Horman Link: https://patch.msgid.link/QDISC-PYC7.v2.20261010165947-2@mojatatu.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/netdevsim/bpf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c index ca64136372fca..ba4a0ce5864fd 100644 --- a/drivers/net/netdevsim/bpf.c +++ b/drivers/net/netdevsim/bpf.c @@ -150,6 +150,17 @@ int nsim_bpf_setup_tc_block_cb(enum tc_setup_type type, return -EOPNOTSUPP; } + /* A dev-bound program can be replayed here when a netdev joins + * a shared block, after the core attach-time check has run; + * enforce the device match as nfp does. + */ + if (prog && bpf_prog_is_dev_bound(prog->aux) && + !bpf_offload_dev_match(prog, ns->netdev)) { + NSIM_EA(cls_bpf->common.extack, + "program bound to a different device"); + return -EINVAL; + } + if (cls_bpf->command != TC_CLSBPF_OFFLOAD) return -EOPNOTSUPP; -- 2.53.0