From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAE5530F7F2 for ; Sat, 25 Apr 2026 11:00:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777114826; cv=none; b=s+ccLKnQwiaLiyN1rK+RHc1LZakpRzzF/tEOaFhhXlHz+r7l8+R7yE+15nN46hOY3nKi6nB36hCxrjzon4FhLMGd+K4kBi00LFHndgIuh0gi0NhmPz4T6QgrWccA5rmVE0BgdzBFf+3PYbK65nmVE4eqWzIcu4ZPnMHDo5BAIJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777114826; c=relaxed/simple; bh=w2LCY/0Y9pS66aRGDAL5zzSoVn8UqImz/5AFiWfll/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bt0AZJYKdy0pQc8NNUYazDt182PXvN2DrT/niZ/pHPcZHrmAeo9HuBOJHW8Dl1o2+7BBe6aoK/SKIkCnf5q1E0v2m8NpUB/dMxhI6zo6UEIGlqMuYOH6vMEnGGqVv+mByK6BzbRna6UVSM0u8O6KRHoA9gAG9LSd/oSsBOOTr80= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jkt9yDDz; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jkt9yDDz" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777114822; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Dv1nqX9pl+QS83DIlKgQtMErP4cw097MHr3XQmGaLCM=; b=jkt9yDDzRuFvPEQE6rfgQLgRqrZQ8AZz15R5qjw22Z8i/r0oBE5QEwMHOKyHuMFezVt08q NiCYsBrUnk/MnhVDJ11US6bVMKbkAY0yO8DgNUdd7fbFFQTCfF97AyNnD4wSFENh4E1OYo kXCf3M5W5pstolvisK77m39R5D+7uWk= From: Jiayuan Chen To: bpf@vger.kernel.org Cc: Jiayuan Chen , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Song Liu , Yonghong Song , Jiri Olsa , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Stanislav Fomichev , Willem de Bruijn , Samiullah Khawaja , Hangbin Liu , Krishna Kumar , Kuniyuki Iwashima , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH bpf v3 2/2] bpf, xdp: move offload check into dev_xdp_install() Date: Sat, 25 Apr 2026 18:59:29 +0800 Message-ID: <20260425105942.223757-3-jiayuan.chen@linux.dev> In-Reply-To: <20260425105942.223757-1-jiayuan.chen@linux.dev> References: <20260425105942.223757-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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: 026a4c28e1db3 ("bpf, xdp: Implement LINK_UPDATE for BPF XDP link") Signed-off-by: Jiayuan Chen --- net/core/dev.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/core/dev.c b/net/core/dev.c index 831129f2a69b5..e3958281e8d63 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10330,6 +10330,11 @@ static int dev_xdp_install(struct net_device *dev, enum bpf_xdp_mode mode, netdev_ops_assert_locked(dev); + if (prog && mode != XDP_MODE_HW && bpf_prog_is_offloaded(prog->aux)) { + NL_SET_ERR_MSG(extack, "Using offloaded program without HW_MODE flag is not supported"); + return -EINVAL; + } + if (dev->cfg->hds_config == ETHTOOL_TCP_DATA_SPLIT_ENABLED && prog && !prog->aux->xdp_has_frags) { NL_SET_ERR_MSG(extack, "unable to install XDP to device using tcp-data-split"); @@ -10481,10 +10486,6 @@ static int dev_xdp_attach(struct net_device *dev, struct netlink_ext_ack *extack NL_SET_ERR_MSG(extack, "Native and generic XDP can't be active at the same time"); return -EEXIST; } - if (!offload && bpf_prog_is_offloaded(new_prog->aux)) { - NL_SET_ERR_MSG(extack, "Using offloaded program without HW_MODE flag is not supported"); - return -EINVAL; - } if (bpf_prog_is_dev_bound(new_prog->aux) && !bpf_offload_dev_match(new_prog, dev)) { NL_SET_ERR_MSG(extack, "Program bound to different device"); return -EINVAL; -- 2.43.0