🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23498

Re: [PATCH net 10/10] tcp: do not pass a BPF reqsk to an MPTCP listener

#23498
From: Jiayuan Chen
Date: Fri, 27 Nov 2026 11:10
99 lines
12481 bytes

On 11/23/26 9:24 PM, Matthieu Baerts (NGI0) wrote:
> From: Chris Mason <mason@kernel.org>
> 
> A slab-out-of-bounds write and a panic can occur if a tc BPF program
> that validates SYN cookies assigns an ACK to a TCP listener, and the ACK
> then goes to an MPTCP listener of the same SO_REUSEPORT group.
> 
> bpf_sk_assign_tcp_reqsk() attaches a plain TCP request sock to the skb,
> and returns -EINVAL if the program passes in an MPTCP listener. But
> inet_steal_sock() and inet6_steal_sock() select a listener again from
> the SO_REUSEPORT group of the listener that was passed in, and the
> result can be an MPTCP listener. cookie_bpf_check() then passes the
> request sock to mptcp_subflow_init_cookie_req(), which writes to members
> of the larger struct mptcp_subflow_request_sock, so the writes can land
> in the next object of the slab.
> 
> The fix used here is to drop the segment in cookie_bpf_check() if the
> listener is an MPTCP listener. The connection then fails, instead of
> corrupting the memory.
> 
> This issue has been found with the help of an LLM, and reproduced in a
> VM, with the reproducer shared with the original version of this patch:
> a tc BPF program validating SYN cookies -- the one from the BPF
> selftests -- and an SO_REUSEPORT group with a TCP listener and an MPTCP
> one, the latter being selected. With KASAN, the original version of this
> patch reported:
> 
>   BUG: KASAN: slab-out-of-bounds in mptcp_subflow_init_cookie_req
>   Write of size 1 at addr ... by task python3
>    mptcp_subflow_init_cookie_req
>    cookie_bpf_check
>    cookie_v4_check
>    tcp_v4_do_rcv
>    tcp_v4_rcv
> 
> Without debug options, and with request sockets of half-open connections
> next to the corrupted one, the kernel panicked a second later, when the
> timer of a request socket fired:
> 
>   BUG: kernel NULL pointer dereference, address: 000000000000058f
>   #PF: supervisor read access in kernel mode
>   #PF: error_code(0x0000) - not-present page
>   Oops: Oops: 0000 [#1] SMP NOPTI
>   CPU: 3 UID: 0 PID: 0 Comm: swapper/3 Not tainted 7.4.0-rc1+ #1 PREEMPT(lazy)
>   RIP: 0010:tcp_syn_ack_timeout+0xd/0x30
>   Call Trace:
>    <IRQ>
>    reqsk_timer_handler+0x22e/0x500
>    call_timer_fn+0x2a/0x140
>    __run_timers+0x1f7/0x280
>    run_timer_softirq+0x49/0xf0
>    handle_softirqs+0xfa/0x300
>    __irq_exit_rcu+0xb5/0xf0
>    sysvec_apic_timer_interrupt+0x73/0x80
>    </IRQ>
>   Kernel panic - not syncing: Fatal exception in interrupt
> 
> Fixes: e472f88891ab ("bpf: tcp: Support arbitrary SYN Cookie.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Chris Mason <mason@kernel.org>
> [ Shorter comment. Commit message: how the issue was found, its
>   symptoms, and that the connection then fails. ]
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>


Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>


Actually, we still have a few issues with bpf_sk_assign semantics...

> ---
> Cc: Neal Cardwell <ncardwell@google.com>
> Cc: Kuniyuki Iwashima <kuniyu@google.com>
> Cc: Martin KaFai Lau <kafai@fb.com>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Martin KaFai Lau <martin.lau@kernel.org>
> Cc: bpf@vger.kernel.org
> ---
>  net/ipv4/syncookies.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
> index 89169c82431c..f39600ee3f17 100644
> --- a/net/ipv4/syncookies.c
> +++ b/net/ipv4/syncookies.c
> @@ -312,7 +312,8 @@ struct request_sock *cookie_bpf_check(struct sock *sk, struct sk_buff *skb)
>  	skb->sk = NULL;
>  	skb->destructor = NULL;
>  
> -	if (cookie_tcp_reqsk_init(sk, skb, req)) {
> +	/* reuseport can pick an MPTCP listener: req is too small for it */
> +	if (sk_is_mptcp(sk) || cookie_tcp_reqsk_init(sk, skb, req)) {
>  		reqsk_free(req);
>  		req = NULL;
>  	}
Technical Details
Message-ID: <da0323dd-441a-46a6-ad9a-39def5fc08dc@linux.dev>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372679-linux-kernel-netdev=dewy.ru
References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org> <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-10-278042217e8d@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372679-linux-kernel-netdev=dewy.ru
From: jiayuan.chen@linux.dev (Jiayuan Chen)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 10/10] tcp: do not pass a BPF reqsk to an MPTCP
 listener
Date: Fri, 27 Nov 2026 19:10:01 +0800
Organization: Usenet Network
Message-ID: <da0323dd-441a-46a6-ad9a-39def5fc08dc@linux.dev>
References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org>
 <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-10-278042217e8d@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="717735"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:uj6qy2Zpy6isEHUE8c0B/jRoNuI= sha256:pmfB0u34HXjh/mN1JyEmzZBiEDiY/lrm0AQE1NQx00o=
	sha1:M/f6IjWhU/mwVBpSnLg1PIr1u4U= sha256:NReiOXqpit9xMND2eyuALWIKFX27JTNlVmA0b+9G0bc=
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 DF63E125F50; Fri, 27 Nov 2026 14:10:34 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.151
X-Spam-Status: No, score=-2.151 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, HK_RANDOM_FROM=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 (1024-bit key)
	header.d=linux.dev
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 IjTs578K9aqc;
	Fri, 27 Nov 2026 14:10:30 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-372679-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 7D553125F48; Fri, 27 Nov 2026 14:10:19 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 1C66D29A96; Fri, 27 Nov 2026 11:10:18 +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=1795777817;
	b=r7oVt625zPgBAIKeLkL4wq/Kh2NbTAJjyo/vyFhWR+vL6Zq6IGXCP2SZl74KHkvkjWDY
	 oKUJqvZhzOiOuMqtDPpztxc/HWR36euKIS2Bqx8WiUTciA1q6mA2H2glUaeHk49N8S+RT
	 TYuGsFesUq8maEAzsZLswTuld3o86H++Srxfy2LUdoFqxXiD5qF9RZVRD1iB9K0bXRJiL
	 o7r7BIZLziFBCmVdpmu4af+ua3y4W3xwVhsaVqLvkakD/qVU1+l24E1M2Hw0j3nxhKHFr
	 uWIfS62pC3u7uWkOD/oSX7lYkxF5GwJS+a7+I3q+U5QR272kNozJKBEogFqqDNAKjRw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795777817;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=yAseJCXCkp3H58r0OVANX+f+65Cd2MGF7drdzRohz2Q=;
	b=EVEZnvCUCCdJPNCft2otq3Pa6GUwtdZIktoQlnuT7je8IPcMGJbAFtGvo06b+xwNJpLu
	 Dafc3Dy5vyFviJa5UHVQq65JvkJXYdHJ42pjb70RgZMBxhHc7zWBKOutBAl1ZWyUKEiJT
	 6R9cEc28gVIlI93RRxcuUO/hZvFO2LIj75eH/915o9I3rRejMYfSXuQSY+H+khs/vWmNr
	 ASTuWAyKePzAHrT5VoMEe4qfdPXbSFLBxxYx1fEtKwqA/zqctcSMzpqLV2jiNur6tK5bg
	 abU7M5AiqN99N6Pr2us2/M/g27Ibun2qU4wCMk0nDglaZY8vCR3m0bGjC9p3yLnxakg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="fol/RnZ8";
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	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 62C8A606A324;
	Fri, 27 Nov 2026 11:10:17 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=fol/RnZ8
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.197
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795777816;
	b=EIv0cKUn0DfsB5jW97PJL/nrqhAeRb1IyNs866C2oSzv1sNSKc+uMUiHvtaoHZBdQsvv
	 m/J+ZQEbCjtRbw1ow+xKR3cnZCTJ25SGBhXPZM8tVK+azeqWXA4kfcW1u8DHc3iYtMZI6
	 uP6ngsp66llO6XnEnuIejtTVEt7RE84gksLeszIrS7nfVqjCeYBSwZij/fTrDuEUDV0vT
	 pFqEexaq8rB2uSiggoafW+5FZuAz4O/xp7eRUgCAxe7qhpf/+u+Ll/WhUc3iAnNNm9+Pa
	 ELqNombI5YRRimRSv5wee5uZDypiVynGJKva90unzzjyTNX3/1CkjW/r66uMJbQ7zKw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795777816;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent:
	 Subject:To:Cc:References:From:In-Reply-To:Content-Type:
	 Content-Transfer-Encoding;
	bh=yAseJCXCkp3H58r0OVANX+f+65Cd2MGF7drdzRohz2Q=;
	b=uyDqR56rOsxYDLxKJaj6gcv5gUXfsvD7xadWSjUlgw1hQF4sDkRxrzKjajUrsazzyrBa
	 x7NS6LenqhkfDB1S890wx1tQnn2SWPCaT8VuWFvyKwIuPxnHsgyfGpDnMMAwDAYKxbmaD
	 QvCxxiF/4KKcoBSwSAknGe2ae/GmNo+i9nWtRq+42ts2T9mJqt2SarcMGJOf80hr/1u5X
	 Ul0Msp3zxQ4mB7Wiql6w39lb1gQNgNZpbwZTs/fWa+laZmmvct6Q+sv/Qcp+UupxYOBMC
	 F3ZLjp2Zl5eVtygdO26jXlVupQxQ97fun6qgKXhlOSH/22H92stwiR5wJtVdNsptCRw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b="fol/RnZ8";
	arc=none smtp.remote-ip=91.218.175.197
X-Received: from mta0.migadu.com (out-197.mta0.migadu.com [91.218.175.197])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68A95606A31E
	for <netdev@vger.kernel.org>; Fri, 27 Nov 2026 11:10:14 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 68A95606A31E
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=N8t62i7CUa3ZOxo+eFaX+w6ClZWF5P21IBj52O6aWrk=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1795777813; v=1; x=1796382613;
 b=fol/RnZ89WCvUSpAU6PfS78nQ0M3jY1AjQrzR/Yqis7ROkFafxSIGY5IVaUVSpNQkmuEeazH
 VaEBMCa4jPqnwwsm/VLAbhRDmCcSyX+5hWg/VDisrezhFYS3J1ARRtDQ2gsVpuYoyzEP3vxDwvU
 F3dmmwP+yB6OI4ubsKihcE3s=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id b147367c39aa5312;
	Fri, 27 Nov 2026 11:10:10 +0000
X-Mizu-Trace-ID: b147367c39aa5312
X-Migadu-Flow: FLOW_OUT
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-User-Agent: Mozilla Thunderbird
X-Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev,
 Davide Caratti <dcaratti@redhat.com>, Chris Mason <mason@kernel.org>,
 stable@vger.kernel.org, Neal Cardwell <ncardwell@google.com>,
 Kuniyuki Iwashima <kuniyu@google.com>, Martin KaFai Lau <kafai@fb.com>,
 Daniel Borkmann <daniel@iogearbox.net>, Alexei Starovoitov <ast@kernel.org>,
 Martin KaFai Lau <martin.lau@kernel.org>, bpf@vger.kernel.org
X-In-Reply-To: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-10-278042217e8d@kernel.org>