From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796084377; b=26xBsr7WpwS2zuIM1io0mm7PXeOkZIYnpF2UXGK3w6o6Pyrq6tV3qtIW96m2rGn9nGOR mMwk5lfo+9zePSVL/xAR7JPjGYl+XtxD67R1fxElg6KD+Jukgr01mM06U1DbxPHyakMTg kkY+coJiT95p4zGnWz2xBJzIibBZyXC3d4eLUaZ4Nx6AHfRMgtbBL1ewbdXOjhdiZbqoQ Pq+3ERCkzy/R2MgUgR8mDVONEF0GmSjCcOMwKfXUCZyFp5r7b3Ysot2klRe3xkdu/o6ES M5g+RU+XrmCoB58wJec/8UQhe8fY0AQ0QyvvLLjoV7qhWBO0EmtUsfnW2lqb/F6NDvw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796084377; 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=cTtPnm6D2RxwHaUiDYoDZG/6BLILX9n/X+AAcLkaCh0jAinO3IE9eSGJQS28Yl6oEy9w Fk7iBmEQ8DBzTTbd3rfeP5d4EB7vIWcM+1yLgfcCnHXGLja5wAui3gZhdje0SzfoolMo/ eXNFym2AXgWm/bo20hSt8+GeIN8TwtOCJuiDZubDtllekf+SIO4OpGCwqNAHDTT4C+92U rJoaJgNnZbcF+M+cI4AOR8t44SfWEo/vrMIVzV4X2LLIxaFFfrnfjSdBbSq26+HPhO8Nv IOOr1jkXqO7aE09hK0VAmll5tfKbwCnRpziZiRj7O+639jJXB/dBltY14OVefMsSv4A== 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.198 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (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 7679F606A325 for ; Tue, 1 Dec 2026 00:19:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7679F606A325 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-f198.google.com with SMTP id d9443c01a7336-2f14314e32eso12690705ad.1 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=F7Faop6uLt1XFmNgb/iuhuzTp2d8iXaNgTwBjM5f3nhnm031J1M9Xwk0t26dTuJNph mmpbf5L05PRhDAnSlRNcA1hNGEHZsgiae6AcQpSjZ8onnyqmzT/sxDDGZc7BB8LvqFaJ Y4f9A4lgkJaNvFZ4PQBzGSbZeb+WqRQnDrIVhXT5Tm041bjnMWubC+pN6jly8U5oAwDh gBUfk9w9Lp82OGTsd7i8Nk47ENNbsRvW8UQZsVrsc7yio7cmYhRWBR1AA0+8XcuWSjUV HKIwQF1ulKI4MlLCWBuBbt8PUVnffLG/9FFsC6EJZmQOe4woO0VdzGE9Mm7elSrFub7z NYnw== X-Forwarded-Encrypted: i=1; AL+hErGAlcEvTXf8bvOAif6py/0t3KygTmPwfYQ3nUTmQHYxvCxHgi1pt+YQksPdl13mfsB1SPle/vc=@vger.kernel.org X-Gm-Message-State: APuU4Z/rFnI6zZ8H6zXrwEUfCJ7IB6/zMhi0qCZDW7PLe1r3w/btltA+ ea5PR9Bm84tUj/QYfP39778QZFhEsKx5y+Eo75VgbiEsrVUlrNI84HDORQNDVPA9BGDEFZn/DYV C0LmL2w== 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: stable@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; > > } >