From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381929; b=aUBUdEQyEq0YUs1DGP9lxTrsZ+ALIU5UPFi1G1KQHBi9Kj8Zi0krv5FFgdHjR5v2dGKJ OQJqOfAKKdbUHkka5wR3LgtRN4iYjEkL5pNppmsAxRceriRbz4GbTsc6U1IDsWBb8aBaF C6bGBYLA67m5vwOCUAxxyDq2UM2DduDsU8NgCzeTZ7z3kLlMu+Jz06P2B1+n9IOM5W25t GklG8q4a4tjeBH49z3DvSTscXeSImILJxnLHC1EX5KKHvbZDsJLVXeUx5LDFsonYoV5En 3FnH1xy/YAhi/TnAfgq5sRuExVRHr+sXIjwv1vOly1eNt5/cwppCf4VeHSEIsryteeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381929; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=gD1AWik4z/fsq1ZBGlFHxC0knWc/BpyfClsu8P7vBQQ=; b=tg+66tPRt0qRA0wZ67EIKGLlf0gEIxp0CcLqyt6hhI7G5VNTvxGuRFkyAk9756JbjMP0 rZLfgnpryvcsJlSAhG6vpAT3CS5Pc5+3KYNCiCkg6iKNP4HTaMCzfw/sgtwktODYfwbot cCyc6ACnn8TbFjM1y0yKOM7f5tZsMLcpb1QP23G+CtfSvFVc9APi6kyZTInLbNwPLmcjT QSmbVo9GHs/kmMEhmIbvqGWoh+0gH8Cja+BkPw08HPTE/HSb9fJ1Xe7WMd4sMTKA27DsV 1hNqJ4qzwm6mw8dX0yLdKaLOhanhgTIufn4dOLzZQ2NdiyIbbN2DtN0AZ4+LgRAuSpg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=HaBxpi1G; arc=none smtp.remote-ip=100.103.45.18 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 9A138606A322; Fri, 4 Dec 2026 10:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=HaBxpi1G Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1655E1F0092C; Fri, 4 Dec 2026 10:58:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381929; bh=gD1AWik4z/fsq1ZBGlFHxC0knWc/BpyfClsu8P7vBQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=HaBxpi1G2T6+f+gronvsw30gMXzNB8OoNpMaUG3Sg4g5yZ8QGu/KZUCx9tBBrMzxN UvqIWauqHt9EVHh7nFZl/ItSlvs3PZdx2r6fj9vU3QycbvKyymM7HN3+eMkjYA/bDi jIPwOqGh8A42nPYS8azoFf78TqTkumreYYWQdPeg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Thaison Phan , "Matthieu Baerts (NGI0)" , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.18 193/703] tcp: accecn: initialize AccECN fields in syncookie path Date: Fri, 4 Dec 2026 19:01:32 +0900 Message-ID: <20261204100632.990972692@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thaison Phan [ Upstream commit ce28b1a4d137842e428a578269c35d6c84109438 ] cookie_tcp_reqsk_alloc() and bpf_sk_assign_tcp_reqsk() allocate struct request_sock without __GFP_ZERO, leaving saw_accecn_opt, accecn_fail_mode, syn_ect_rcv, and syn_ect_snt uninitialized. When accecn_ok is negotiated in cookie_{v4,v6}_check(), tcp_ecn_openreq_child() reads all four fields to initialize the child socket's AccECN state. In addition, because the temporary request_sock used to send a cookie SYN-ACK is immediately freed, treq->syn_ect_snt is lost. For AccECN connections where the listener marks ECT on the SYN-ACK, leaving syn_ect_snt as 0 causes tcp_accecn_third_ack() to see a mismatch between the expected Not-ECT and the peer's reflected ECT in the ACE field, erroneously flagging TCP_ACCECN_ACE_FAIL_RECV in accecn_fail_mode. Refer to Table 4 of RFC 9768 for more details. Initialize the AccECN fields in cookie_tcp_reqsk_init() to match tcp_openreq_init(). For kernel-generated cookies (!req->syncookie), set syn_ect_snt from the listener's TOS/tclass in cookie_{v4,v6}_check() to match tcp_{v4,v6}_send_synack(); for BPF custom syncookies (req->syncookie), leave syn_ect_snt at 0 (Not-ECT) since the SYN-ACK was built by the BPF program rather than the kernel and bpf_tcp_req_attrs does not report the SYN-ACK ECN codepoint. Found by AI-assisted code inspection comparing tcp_openreq_init() and cookie_tcp_reqsk_init() while investigating the cookie_v6_check() LOOPBACK4_IPV6 bug. Reproduced in a QEMU VM with tcp_syncookies=2, tcp_ecn=3, SLUB_RCU_DEBUG=y, and slub_debug=P, observing bogus tcpi_accecn_fail_mode and tcpi_accecn_opt_seen values in TCP_INFO on the accepted child socket (and tcpi_accecn_fail_mode=0x2 on ECT(0) listeners), and tested with packetdrill AccECN and syncookie selftests. Fixes: 3cae34274c79 ("tcp: accecn: AccECN negotiation") Fixes: b40671b5ee58 ("tcp: accecn: AccECN option failure handling") Signed-off-by: Thaison Phan Reviewed-by: Matthieu Baerts (NGI0) Reviewed-by: Eric Dumazet Link: https://patch.msgid.link/20261118210933.2477423-3-thaisonphan@google.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/syncookies.c | 7 +++++++ net/ipv6/syncookies.c | 3 +++ 2 files changed, 10 insertions(+) diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c index 39dd078cd7034..9fb7e850430e9 100644 --- a/net/ipv4/syncookies.c +++ b/net/ipv4/syncookies.c @@ -288,6 +288,10 @@ static int cookie_tcp_reqsk_init(struct sock *sk, struct sk_buff *skb, treq->rcv_isn = ntohl(th->seq) - 1; treq->snt_isn = ntohl(th->ack_seq) - 1; treq->syn_tos = TCP_SKB_CB(skb)->ip_dsfield; + treq->saw_accecn_opt = TCP_ACCECN_OPT_NOT_SEEN; + treq->accecn_fail_mode = 0; + treq->syn_ect_rcv = 0; + treq->syn_ect_snt = 0; #if IS_ENABLED(CONFIG_MPTCP) treq->is_mptcp = sk_is_mptcp(sk); @@ -502,6 +506,9 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) ireq->rcv_wscale = rcv_wscale; ireq->ecn_ok &= cookie_ecn_ok(net, &rt->dst); treq->accecn_ok = ireq->ecn_ok && cookie_accecn_ok(th); + /* SYN-ACK was not sent by the kernel if req->syncookie is set. */ + if (!req->syncookie) + treq->syn_ect_snt = READ_ONCE(inet_sk(sk)->tos) & INET_ECN_MASK; ret = tcp_get_cookie_sock(sk, skb, req, &rt->dst); /* ip_queue_xmit() depends on our flow being setup diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c index e0758a6a6a8f7..f3c6ba3f8457d 100644 --- a/net/ipv6/syncookies.c +++ b/net/ipv6/syncookies.c @@ -274,6 +274,9 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) ireq->rcv_wscale = rcv_wscale; ireq->ecn_ok &= cookie_ecn_ok(net, dst); tcp_rsk(req)->accecn_ok = ireq->ecn_ok && cookie_accecn_ok(th); + /* SYN-ACK was not sent by the kernel if req->syncookie is set. */ + if (!req->syncookie) + tcp_rsk(req)->syn_ect_snt = READ_ONCE(np->tclass) & INET_ECN_MASK; ret = tcp_get_cookie_sock(sk, skb, req, dst); if (!ret) { -- 2.53.0