From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.197 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796084376; b=bdfmUvbXKKRt+jfwABherUYv8VUrGZQ0swB3HCvVyWZ9kucDC6bB5VRxuyP6bL+Ggijx 8t/pWwb05ut99R0QUUjLRYYJ+Rkx8i0Id5AIoyCRIEB4cV5h62z6fIK2eZOsOXnznXQ7F /v7pSF6CtKilcyScbVixUEI9Dvm868IPIns0mDm2LqLsJrmRa2oodsvVLVloOBk+UatHV v08j8Ik8Ssbdh2dcED+uNFvGC8BEziCjZWyhkOIG0unojIjMzJwBl1qTii39RccuN1eSL b7ZWvU3PgYg/kYzEkJAUkPqxQE+aJvMmjmIc+IwqPyGvqt7xFZlUrtT555t5KAZ2I7w== 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=GtQXoI8oi8hV4abJvYgo+DcWUpx86Y+z4/q6ojWw6tKyvh6ZVsqxENylcM3n4O+elTxs HF0V2rWT6YLMS54z9Wl4BN0cRP0zWEUKmgupeROTqP6sRyB2oJUoKti43GOnsBfSX09fP 7QkNN3I1g0SAPODRXHeoYQw+OrhrloJe3Yz2fQql2LfT/PS9IOaCmTqzlv/LGhYxLnErc XGO2lhZLJtDWABXxkSQfmxpJofknPRKF8c3+LPi5h/m1pyULZTULvJ4f35Nx6y2hNmeF+ paaVDjihHPFiST/1z7CwDjFMsFTsdy0OsSHxjI5AnGVfWhGkPFpyPGNHVy1hivFfK4w== 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=ACBO9UGA; arc=none smtp.remote-ip=209.85.214.197 Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.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 7C93F606A327 for ; Tue, 1 Dec 2026 00:19:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7C93F606A327 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=ACBO9UGA Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-2f0329e57eeso101484035ad.3 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=lists.linux.dev; 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=ACBO9UGA9G/er4Eaozk3A+KPePPh4rh1CJdUA0AIMJ3+JonxoQg+xGJ++2WJBshrkc PcCO/Rd27bgIMUYUFXUNaNazCNkhqARaO6TzrELgU/HSVlgeShKTSPQ6N/OZXFoIX3AP qmzBJf0AzADEIhiBKuPcqBdEef26v/D5F8Fm0eMmWUorBw37XZuDk41p4EZDI22cDB6y xzX5WAHz9RPn+lppSXy0PDfUdjrEQ7ltZ3ikkxNkOr4N6ygZ1/km+bNqTu+ziEoF4WW0 hE2rc4unG3fF6f/h2pyS19xOd4n8hESTdVhuB/yrgYrn8zsX7UIt8alzSZFnA73umXDa MoBQ== 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=B6isy5bjX/VFMjhC9thNm2E1rEM580Ut6PVSpV7t5EKK56L5zaW0ZHUt86itlkxnQV SBSnnjG5L7YwgE0fpRblIuyToqH4QaOwUlP0DBMozrm7ejhd/c09Un6d8rhW81900qm4 MXsrJRR9fIqyZvntIqKfVESG4npx/65gq1IbAtGWM3EbzBpF/gsPIB8rzXv0jIvPGtU2 ySb4rdkgijC84I3KVypgHelEIf8T/BOf/+gIQSKZjNa7PASTdefSysqenO7eKEJijHSB hsyJn+q3VcxBfw7I2fOvS0uwha0wbRiFPGkUOat18xKTn1NRkY/WL3aI+MKMVbctRRD7 bFfA== X-Forwarded-Encrypted: i=1; AL+hErFZ0jqxFtJQ3AgIcC6l5p4lln/zoQQ5qsmd6CGlJ/SvOFYFUy63/+h8SBz+omxCS+Z/dQmjpw==@lists.linux.dev X-Gm-Message-State: APuU4Z9mIHBX7Fs+xacvNtgzYaQRlf/9DfSC2J6jfpcwdAK2Sjn9QZIE UaaHE+ZfwiRWAyOTlRxLMVa1Sw49EOfBnmTFhVI1LXo5Bo68YdUAJl+P5m7uMIQGn3MEbw7Prb7 VPD2m+w== 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: mptcp@lists.linux.dev 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; > > } >