From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 8496651C057; Wed, 30 Sep 2026 17:27:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789239; cv=none; b=SB3H47ya2161Yw4bWpBSxcqx1mDlWw8ZCap/svTHa6NLO0d3LctHNIemUjSduuDavWqaABqD17utwFRlzVJcSBjGbJo5nLiSQ1kzr16iHi5oQNzjxi7TIF8m+9vVX0c8EJteiPq/D0hB5LJCl/dVkuzy43PloSquFnP/6JVtdD4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790789239; c=relaxed/simple; bh=GTg93rSbmGFoKVCa8OZQNBZXXghy35qAqSNVyYzU/B4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VXKWeKuBg5yBfdYjLnlSLIGs/o5Hh8h8WhmDzCgcsNjtxcRujcE91S9gqIvxx0ocDvNlOSIXAHSU7274UqyY1ZH+9CelaJZFvfdukXGJu0sWb98n2oacaLoIfy972U2oe1aS+vpmuf+dc3SaN3ooFH03GvZ1+N0d+tLdBll0eIg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=M1HyTrC/; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="M1HyTrC/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEB441F000FF; Wed, 30 Sep 2026 17:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790789238; bh=AjX8JzBDL5LxOVOBLcGFfllYbSh8xnaGp0si4eiBFow=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M1HyTrC/H5kJgqz13X9NAAxLungfQ7jMNDeaBUecmjrlFmXgaPt75bewS2ELH0lQo V3J9D5DXdm1dgakW4KT5EvlF6Mqs7Uc2swIKf2F08MyMTFeWtIYsRJhQhB68ExAYOH veT4AfQZVPp8a/6Y6h+nBtchseaVRN8HpP03R8zk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, co+ac0a8c41de69121d@bugs.sh, Weiming Shi , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.12 400/877] bpf: Reject dev-bound-only programs on other devices Date: Wed, 30 Sep 2026 17:21:51 +0200 Message-ID: <20260930152423.316713397@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152414.738996857@linuxfoundation.org> References: <20260930152414.738996857@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Weiming Shi [ Upstream commit 6db1ce73e9853f533eb7f413f14ba00f8ec6f80d ] __bpf_offload_dev_match() falls back to comparing offdev pointers after an exact netdev mismatch. Bound-only programs normally have NULL offdevs, so unrelated netdevs compare equal. A bound-only program on an offload-registered netdev can instead inherit a real offdev and match a sibling port. With CAP_BPF and CAP_NET_ADMIN, a caller can use bpf(BPF_LINK_CREATE) with a different target ifindex to run metadata kfuncs specialized for the bound driver on the target driver's xdp_buff. Running a veth-bound program on tun reads beyond tun's bare stack xdp_buff as a veth_xdp_buff. Oops: general protection fault, probably for non-canonical address KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017] RIP: 0010:veth_xdp_rx_timestamp (drivers/net/veth.c:1673) Call Trace: ... tun_build_skb (drivers/net/tun.c:1739) tun_get_user (drivers/net/tun.c:1856) tun_chr_write_iter (drivers/net/tun.c:2091) vfs_write (fs/read_write.c:595 fs/read_write.c:687) ksys_write (fs/read_write.c:739) do_syscall_64 (arch/x86/entry/syscall_64.c:84) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Kernel panic - not syncing: Fatal exception in interrupt Restrict non-offloaded programs to exact netdev matches and retain the shared-offdev fallback only for genuinely offloaded multi-port programs. Fixes: 2b3486bc2d23 ("bpf: Introduce device-bound XDP programs") Reported-by: Signed-off-by: Weiming Shi Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/20260917161335.1020405-2-bestswngs@gmail.com/ Link: https://patch.msgid.link/20260920132303.4109240-3-bestswngs@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/offload.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c index 56115739fcfdd..1b6f9e7175666 100644 --- a/kernel/bpf/offload.c +++ b/kernel/bpf/offload.c @@ -703,6 +703,8 @@ static bool __bpf_offload_dev_match(struct bpf_prog *prog, return false; if (offload->netdev == netdev) return true; + if (!bpf_prog_is_offloaded(prog->aux)) + return false; ondev1 = bpf_offload_find_netdev(offload->netdev); ondev2 = bpf_offload_find_netdev(netdev); -- 2.53.0