Article View: linux.kernel.netdev
Article #20855Re: [PATCH bpf 1/2] bpf, net: validate assigned socket on receive
From: bot+bpf-ci
Date: Mon, 23 Nov 2026 09:38
Date: Mon, 23 Nov 2026 09:38
99 lines
11911 bytes
11911 bytes
--===============5546299398506454022==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
> bpf, net: validate assigned socket on receive
TL;DR:
- Raw sockets with matching sk_protocol may pass the new check, possibly
causing type confusion and out-of-bounds writes in UDP/TCP receive
- Changelog says normal path is unaffected, but early-demuxed UDP packets run
the new checks
> The normal packet path is not affected: the checks run only after the
> prefetched test and the protocol is a constant at every call site.
The commit message says the normal packet path is not affected because the
checks run only after the prefetched test. Is that accurate for UDP?
skb_sk_is_prefetched() is skb->destructor == sock_pfree, and sock_pfree is
also installed by udp_v4_early_demux() and udp_v6_early_demux(), which run
on ordinary traffic when net.ipv4.udp_early_demux is enabled (the
default).
So early-demuxed UDP packets do reach inet_prefetched_sk_mismatch() or
inet6_prefetched_sk_mismatch() in udp_rcv() and udpv6_rcv(). The early
demux lookups already enforce netns and family, so no valid socket looks
to be rejected, but could the changelog say that these packets run the new
checks and why that is acceptable?
> diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
> --- a/include/net/inet_hashtables.h
> +++ b/include/net/inet_hashtables.h
[ ... ]
> @@ -444,11 +444,24 @@ static inline struct sock *inet_lookup(struct net *net,
> return sk;
> }
>
> +static inline bool inet_prefetched_sk_mismatch(const struct sock *sk,
> + const struct net *net,
> + u8 protocol)
> +{
> + if (unlikely(!net_eq(sock_net(sk), net)))
> + return true;
> + if (!sk_fullsock(sk))
> + return unlikely(protocol != IPPROTO_TCP);
> + return unlikely(sk->sk_protocol != protocol ||
> + (sk->sk_family == AF_INET6 && ipv6_only_sock(sk)));
> +}
Does matching sk_protocol prove that this is really a TCP or UDP socket?
For SOCK_RAW, inet_create() stores the user-chosen protocol in
sk->sk_protocol, so socket(AF_INET, SOCK_RAW, IPPROTO_UDP) has
sk_protocol == IPPROTO_UDP and sk_family == AF_INET. raw_hash_sk() hashes
it and sets SOCK_RCU_FREE, so bpf_sk_assign() accepts it without a
reference.
A tc program can obtain such a socket without a lookup helper. On
veth_xmit() -> __dev_forward_skb() -> skb_scrub_packet() the skb is not
orphaned, so at the peer's tc ingress skb->sk is still the sender's raw
socket, and __sk_buff->sk can be passed to bpf_sk_assign().
Then in udp_rcv():
inet_steal_sock()
inet_prefetched_sk_mismatch() /* netns ok, full sock, sk_protocol ==
IPPROTO_UDP, not AF_INET6 */
passes, sk_state is TCP_CLOSE and sk_reuseport is clear, so the raw_sock is
returned. udp_unicast_rcv_skb() and udp_queue_rcv_one_skb() then use it as
a struct udp_sock, which is larger than raw_sock. That looks like the same
type confusion as the KASAN report in the commit message.
The same applies to SOCK_RAW with IPPROTO_TCP on the TCP receive path:
inet_steal_sock() returns it because sk_state != TCP_LISTEN, and
tcp_v4_rcv() then calls tcp_segs_in(tcp_sk(sk), skb), which writes beyond
the raw_sock. AF_INET6 raw sockets pass inet6_prefetched_sk_mismatch() in
the same way.
The old code had no check at all, but the stated goal is to drop a
prefetched socket that does not match the receiving protocol. Should the
full socket branch also require sk_type == SOCK_STREAM for TCP and
SOCK_DGRAM for UDP, and an inet family on IPv4? sk_is_tcp() and
sk_is_udp() already check family, type and protocol together, and
bpf_sk_assign_tcp_reqsk() checks sk->sk_type != SOCK_STREAM.
[ ... ]
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45143832636
--===============5546299398506454022==--
Technical Details
Message-ID:
<17a6c638570f5dbce09ea097938e5bcb33d226fd40323af3e27b3f083ad851d9@mail.kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369193-linux-kernel-netdev=dewy.ruReferences:
<20261123084138.723275-2-razor@blackwall.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369193-linux-kernel-netdev=dewy.ru From: bot+bpf-ci@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH bpf 1/2] bpf, net: validate assigned socket on receive Date: Mon, 23 Nov 2026 09:38:41 +0000 (UTC) Organization: Usenet Network Message-ID: <17a6c638570f5dbce09ea097938e5bcb33d226fd40323af3e27b3f083ad851d9@mail.kernel.org> References: <20261123084138.723275-2-razor@blackwall.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5546299398506454022==" Injection-Info: usenet.network; logging-data="3840606"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:P+eci3XblNVuzIpLvhI60PD3S28= sha256:/vIuQ7229oHACsS249AIlLi99uBIR/qaU+XcfuRAlPY= sha1:emyaIlRX0sQOcWcYd4EnbK881pE= sha256:5q3cAF04sb0L0R1o19SGnsyFK0fQ7lUVsBrfy/6n5mQ= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 613AD125D96; Mon, 23 Nov 2026 12:39:29 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Q_Q2RSXpO9Re; Mon, 23 Nov 2026 12:39:25 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369193-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 3D036125D95; Mon, 23 Nov 2026 12:39:14 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 5A63933019; Mon, 23 Nov 2026 09:38:45 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795426725; b=MtFVEKAshJ+QQ0cw35g3nHdX4rovIhpaJla0DsWxOmE6dqjtTXgnLTG5ep8Tateu5sAu fH5vFyRakV3TFyS+tHVYKLPnjhJOF/UoNnJbNtmuo/iN3dg7RHn8JGCPbQFCXkm25fiV9 2ik+EX2iAqDgZ+6GWJv4/T0YSX7/aIOm5fcOEs3Sgo9D+N5Zru2di+Mo1NVYzjDS/xXGE Cg3SX0vbt0rNdaTMJQsv3yy8gJSLy/so2clcQqnEYg0TgD0LHsjxlf2VXsHQg0n9O0EBb +Ndm5ET1G6m5+DJHJBWG8Mr6dJPxBlbl/4afOZTUrJs1KMWlXGm8HQ6C3MAEvBCqcsw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795426725; h=X-Original-To:Received:Received:DKIM-Signature:Content-Type: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=eQjysNNGlsoUj/cZnZbV4xgqvZHEKysJuGURf1mwqlE=; b=2lNGUBwpsofSfrKvOKekB2huX7ZM6hK1dhp87yVGQhnlWK7au/R/ZkPKkoYy8K1I3vLw V0p7cGESISW+dmBY4zt9HajXRsa75Y4vz9WzMabvak6RAzYm3cPu/8yLwrBOPEEXUNtK1 osHitAD7D/yd9NGenJUBAkBLYpA1jIAvI6J/ag2PZ4bcr/9H1DZ6n79Zm4gaX4lNYnkuJ 3a1csD5xFvNEy0Vwe0qVm7m4zs7o8tCBYLhfGrpFEjPpxQx+wb1zWujnEljlQ4SCp4BBF 0CiQ/jdfHcgxNgJ939xmO7c3oW4iXI3epNnP23QQM3yvbOcnb+oy4sgdpob7NpKVCTA== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Nug+G2Y1; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB349606A335; Mon, 23 Nov 2026 09:38:44 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Nug+G2Y1 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795426724; b=WdQNDTBoHmWpUT31eiLsXrB/dz9iPl7sDp/mRbRoztTfOjekNpLB2QMxa8uhrBviVxPC naL05+1Loy8c/N9QPcxeI3hTdDwMjfvjs/Ad+kBaA/xz88LLiI/3PwN7L2ZP9leb9Lkz8 X8wCFcxrnO11O8RqM217YkdCOU28bWfZEg3CjiWz7EV6cnPquDvzmXWo3YkVnJVbWNtRh xFJI3+3n2DCBgmldI90XRJdV5PxsJ5cMwopaeoxB2jhL89XdZyKTW5vBky1S1gvMzdloM AkzvYYVGEStDvEqL+K61ipZJUYU06N/JzJTz5J8L0RgxIycIHaQ5f0hBDEThW+yoV+Q== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795426724; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=eQjysNNGlsoUj/cZnZbV4xgqvZHEKysJuGURf1mwqlE=; b=erriKJFYPM6DzOgxHlyfCD5PLSqtvll/qwqv3TyQzHHVjWa6V9DJGqdkA1AfwtaZOBsE uZcjL5VZ654wTBD0OmTvMrLGNZNfRycaYK9KdjXdqGIwauTOsLL93C4RGWDqCbd3q08FF w0rQ4E+9/2sVe0Vw4gAdciFcPNyQQkk1NvBvAT50wIB54mqrgPAnE6/1l9mvCXRB85RLt PD4qEDVZjEN5RlUxW91hFG0ZKnPI2RHY+djnITcxvrSRLiFbREO37RRofg/eSP142LP2V GeLMQPlyLVu3BO73TJ5gF6JjLGQfgvFU5NaS8XMVn5adJf2LjJnXc2mvZ6yxI05kzdQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Nug+G2Y1; arc=none smtp.remote-ip=100.103.45.18 X-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 159C5606A31A; Mon, 23 Nov 2026 09:38:43 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 567621F000D4; Mon, 23 Nov 2026 09:38:41 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795426723; bh=eQjysNNGlsoUj/cZnZbV4xgqvZHEKysJuGURf1mwqlE=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=Nug+G2Y1TaD8ogWh5idPqiNwM1/pEjGecOCbWnb4nSG0tAdjrmhLFjmb8jnrfR3xV QSnFKerGH0HgU0PXwQbzbpt3L7dCrk09iLFBarhfqNmeskJwKISaqPE1AZsND7Ufqm zGkaqKQ/ZL5RaU6VYwgFz2A1KdU1pB145x1SIyYPKtHqgX0I2edrSMEHkApNQ9UIsc Emqz7MALPAI0get7b0ztrrZsxB/+SbfhrzyWND5v8IwSDdsAiYaZwQtY1fXsDbrJq8 DVhGvml3adCEhXaZu80eX9apgkkpC8HXpAW28pJ28KA6Rk9ISq49FaqtdJvxnfTubo 6Cuso/uqon14g== X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261123084138.723275-2-razor@blackwall.org> X-Cc: razor@blackwall.org,davem@davemloft.net,edumazet@kernel.org,kuba@kernel.org,pabeni@redhat.com,horms@kernel.org,kuniyu@google.com,willemdebruijn.kernel@gmail.com,kafai@fb.com,ast@kernel.org,daniel@iogearbox.net,john.fastabend@gmail.com,netdev@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev