Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.200 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796084376; b=n95eJTaBoglbH72V06JvJL7zSoIPcERhKCYyowjL9o/FEEqJhVv5cwomCLOCj9eCHkn/ twrdQPYFJkTY6Hp4SGtEETUjEoo0LAkgQm1qWzvC37ChkH6mxAh5B5XBk0luL2EnRM2nq uLxF443u63tFlDz/GVn2ZiVU58c0O6+9CONYA+yqKxY1qUlS59L7XKCWiMWhCX+wggBiM S7a5eSm7DGJ53xf10R1T0+d4t2+d32MXaTSs1VN0E4sp8g+NnTQl/1ct13Z2dqLqWllCM G2cjMFcDco6LneOb8hryVH3zZJNH312oYEA4wdepwAW5rfCeJ6GTWEBUgEiSow3BCUw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796084376; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:In-Reply-To: Mime-Version:References:Message-ID:Subject:From:To:Cc:Content-Type; bh=LQICodlXh2p8AliFWD9vma+7Kdaw+lThDzlcTxOhaQI=; b=T4l2AEDp2vh8wug9B0vvihGgdqO62++yGBQDR0rzbnsD9pwfb97SOCZQzoITfz2MB5Ui zDX9HpMkzmNu6XEFaFQsV+ciFhv24QTY2a5M88Csum6Sm0rYtmPsSZoUtW0tLSWSqcNEC jL3+xmJC8GCxdoPrfPnKnZ5t/WHsjjacuibgw9SBetUY7LyIFovM3/LRP4trk0lUBSxb2 zqLDlCNmbI+KGtJAmWQ3O/IDeSKNyiRHOTLrpbOmyHKjwgYWVaUahJ4Ly5sxOylTeTLS8 Qi/p/9BGI1iFMRFRamviz6lwAx8qsqhdQqIN0InG73xy/9S1Az/9gC0xLparbV9Lnqw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=p7NJivji; arc=none smtp.remote-ip=209.85.214.200 Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) (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 72D25606A320 for ; Tue, 1 Dec 2026 00:19:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 72D25606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kuniyu.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=p7NJivji Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2f05b674e3eso86434215ad.0 for ; Mon, 30 Nov 2026 16:19:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796084376; x=1796689176; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=LQICodlXh2p8AliFWD9vma+7Kdaw+lThDzlcTxOhaQI=; b=p7NJivjiiHgcSRyiE61l0//1CTEzcsphCiphUVicVXBDO2fTBTUlVGutLMDOLuhE/Y 6Vah/goaev92cXc+7HYpiwH7S+DiMPFLdykvM58BpflXBIX/z06TyOVNZxTOTj0ezOS3 c9dbVtf6x77+w52pPLgWpgGBJHNPRfMtPc92lFaxPuYBxB6EvafN7/gTXb8O8ii1wK1m Zzwje/CldWl12Tiy60Ss3QDWfA1w8bH48GID8hsZDE7efbXcyeMlll/6VOWkCtDpmKZZ 0RDBGINS8i6ZxjttyU7UdqT1zCpwBr8P96GXwcAa0aiOsppiUm3ebYV39MnaACD3OkmJ Gl5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796084376; x=1796689176; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=LQICodlXh2p8AliFWD9vma+7Kdaw+lThDzlcTxOhaQI=; b=L3K/NNVTZc/3e3eOEzowko8025teQTitLX9/9V5eoQVgKykSSs1GiMTvOcR3omcfwA 70bum6VHR+Oms5Gnh8iivwc3CoRnqUdBcmYbnMIyv2befxww7gj3gGwZ1EwiBqgxQr+c b4EoxJxuCh6LRzPkj8Y+GqbgPMRPuu5/rLQ0zzLPIphY3lbed8xR5FCHkOqLUGFozyKO hG9d1/KBp2MkP+RKKCMRVIqvv+mAg9MU8Ntq2o+nGmaufymuEIn5l1BPx5CL4Cm+1P/d FU4mGgWGjaeLlPwQIDc+NEWQJsAZCK8+gVKvnyY3/E14on9DkwKpYnm1W740V8NfQxI5 dQ/g== X-Forwarded-Encrypted: i=1; AL+hErGiqWWO+hkSmRYorHq2DFfrMRK5MS9LoLR71Zm9CSRyOd8Pnhk0B2+aH8LWgmma/p1gwyY=@vger.kernel.org X-Gm-Message-State: APuU4Z/UuB83ReUHVb+7RM1yckxy6rBMu6wFFOc3MhCp0hYQX2+k5Nf+ MJhgU9m4aDREKdqsBKdqtJYlsdaHZNpeB596g/nSurs5lZqOmX+Kj0PLEofSduXAyHvdytfWFYb xfuyTIg== X-Received: from plog24.prod.google.com ([2002:a17:902:8698:b0:2f0:2741:753a]) (user=kuniyu job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:32cc:b0:2f0:2e6d:f2e5 with SMTP id d9443c01a7336-2f03f1c08bamr373672785ad.41.1796084375518; Mon, 30 Nov 2026 16:19:35 -0800 (PST) Date: Tue, 1 Dec 2026 09:19:35 +0900 In-Reply-To: X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 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> Message-ID: Subject: Re: [PATCH net 10/10] tcp: do not pass a BPF reqsk to an MPTCP listener From: Kuniyuki Iwashima To: Jiayuan Chen Cc: "Matthieu Baerts (NGI0)" , Eric Dumazet , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , Mat Martineau , Geliang Tang , Christoph Paasch , Florian Westphal , netdev@vger.kernel.org, mptcp@lists.linux.dev, Davide Caratti , Chris Mason , stable@vger.kernel.org, Neal Cardwell , Martin KaFai Lau , Daniel Borkmann , Alexei Starovoitov , Martin KaFai Lau , bpf@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Fri, 27 Nov 2026 19:10:01 +0800, Jiayuan Chen wrote: > > > On 11/23/26 9:24 PM, Matthieu Baerts (NGI0) wrote: > > From: Chris Mason > > > > 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. Hmm... do we want to support this setup ... ? Maybe only useful when someone wants to migrate TCP to MPTCP gradually ? > > 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: > > > > 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 > > > > 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 > > [ Shorter comment. Commit message: how the issue was found, its > > symptoms, and that the connection then fails. ] > > Signed-off-by: Matthieu Baerts (NGI0) > > > Reviewed-by: Jiayuan Chen > > > Actually, we still have a few issues with bpf_sk_assign semantics... > > > --- > > Cc: Neal Cardwell > > Cc: Kuniyuki Iwashima > > Cc: Martin KaFai Lau > > Cc: Daniel Borkmann > > Cc: Alexei Starovoitov > > Cc: Martin KaFai Lau > > 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; > > } >