Article View: linux.kernel.netdev
Article #18404Re: [PATCH net v2 2/2] tcp: accecn: initialize AccECN fields in syncookie path
From: Eric Dumazet
Date: Wed, 18 Nov 2026 09:30
Date: Wed, 18 Nov 2026 09:30
127 lines
14452 bytes
14452 bytes
Le lun. 16 nov. 2026 à 03:37, Thaison Phan <thaisonphan@google.com> a écrit :
>
> 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. If the listener
> marks ECT (e.g. DCTCP), failing to record syn_ect_snt causes
> tcp_accecn_third_ack() to flag TCP_ACCECN_ACE_FAIL_RECV when the peer
> reflects ECT, disabling ECT for the rest of the connection.
>
> Initialize saw_accecn_opt, accecn_fail_mode, and syn_ect_rcv in
> cookie_tcp_reqsk_init() to match tcp_openreq_init(), and set syn_ect_snt
> from the listener's TOS/tclass in cookie_{v4,v6}_check() to match
> tcp_{v4,v6}_send_synack().
>
> 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 <thaisonphan@google.com>
> Reviewed-by: Eric Dumazet <edumazet@kernel.org>
> ---
> v2:
> - drop redundant treq->syn_ect_snt = 0 in cookie_tcp_reqsk_init()
> (Eric Dumazet)
> - clarify how the bug was discovered and observed via TCP_INFO
> (Eric Dumazet)
> - add Reviewed-by tag from Eric Dumazet
> v1: https://lore.kernel.org/netdev/20261114161248.3428695-3-thaisonphan@google.com/
>
> net/ipv4/syncookies.c | 4 ++++
> net/ipv6/syncookies.c | 1 +
> 2 files changed, 5 insertions(+)
>
> diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
> index 4e0ff3b82062..1a837ed6efa0 100644
> --- a/net/ipv4/syncookies.c
> +++ b/net/ipv4/syncookies.c
> @@ -290,6 +290,9 @@ static int cookie_tcp_reqsk_init(struct sock *sk, struct sk_buff *skb,
> */
> treq->txhash = treq->snt_isn;
> 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;
>
> #if IS_ENABLED(CONFIG_MPTCP)
> treq->is_mptcp = sk_is_mptcp(sk);
> @@ -502,6 +505,7 @@ 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);
> + treq->syn_ect_snt = READ_ONCE(inet_sk(sk)->tos) & INET_ECN_MASK;
Sashiko has a point about the BPF custom syncookie case.
Requests coming from cookie_bpf_check() also reach this line, but the
kernel did not send that SYN-ACK, a TC/XDP program did. The listener's
tos/tclass says nothing about the ECN codepoint the program used, and
struct bpf_tcp_req_attrs has no way to report it.
test_tcp_custom_syncookie.c sends its SYN-ACK as Not-ECT (tos = 0,
flow info 0x60000000) and only clears CWR, so an AccECN SYN gets
AE=1,ECE=1 back and the client should stay in AccECN mode. It then
reflects Not-ECT in the third ACK. With a listener that has ECT in
inet->tos (DCTCP for instance), we would get:
tcp_ecn_openreq_child()
tcp_accecn_third_ack(sk, skb, treq->syn_ect_snt) // ECT(0)
tcp_accecn_validate_syn_feedback()
tcp_ect_transition_valid(ECT(0), Not-ECT) -> false
tcp_accecn_fail_mode_set(tp, TCP_ACCECN_ACE_FAIL_RECV);
This is the failure your patch fixes for kernel generated cookies.
I asked you to drop the syn_ect_snt = 0 in v1 because it looked
redundant, sorry about that, it is needed for the BPF path.
Could you send a v3 doing something like this (untested)?
In cookie_tcp_reqsk_init():
treq->saw_accecn_opt = TCP_ACCECN_OPT_NOT_SEEN;
treq->accecn_fail_mode = 0;
treq->syn_ect_rcv = 0;
treq->syn_ect_snt = 0;
In cookie_v4_check():
/* 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;
And the same in cookie_v6_check() with np->tclass.
Letting the BPF program report the codepoint it used (a new field in
struct bpf_tcp_req_attrs) would be net-next material.
The other Sashiko remark (AccECN option carried by the third ACK is not
processed in the syncookie path, unlike tcp_check_req()) looks correct,
but this is not something added by this patch. It can be handled
separately, no need to grow this series.
Please mention the BPF case in the changelog. You can keep the
Reviewed-by tags on both patches.
Thanks.
pw-bot: cr
Technical Details
Message-ID:
<CAL4Wiir50_Z+m00GyU9BpRdAqgXs8V-L0S8kmmES=JiYyt==gg@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365988-linux-kernel-netdev=dewy.ruReferences:
<20261116023709.132684-1-thaisonphan@google.com> <20261116023709.132684-3-thaisonphan@google.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365988-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2 2/2] tcp: accecn: initialize AccECN fields in
syncookie path
Date: Wed, 18 Nov 2026 10:30:58 +0100
Organization: Usenet Network
Message-ID: <CAL4Wiir50_Z+m00GyU9BpRdAqgXs8V-L0S8kmmES=JiYyt==gg@mail.gmail.com>
References: <20261116023709.132684-1-thaisonphan@google.com> <20261116023709.132684-3-thaisonphan@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="2555879"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:MGWWuIc+pySi2EEamqH4ilkm3lo= sha256:76dw/0dYpWT006Xz8d0UEGglHQxaVOYcjoYSn+Jc7LQ=
sha1:8Ff9+Nb4iDduAmBfImxbuS/aADk= sha256:F1Mfnv1pOQZpRGO9Lzrx3rX+4tP9Rxphe0eg8zr2Gv0=
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 984A011521C; Wed, 18 Nov 2026 12:31:26 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.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 (2048-bit key)
header.d=kernel.org
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 xNtb6TFJJU13;
Wed, 18 Nov 2026 12:31:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-365988-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 99EBF1151F8; Wed, 18 Nov 2026 12:31:14 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 098793C2D4; Wed, 18 Nov 2026 09:31:12 +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=1794994271;
b=pzPd9QztUe8XpDxa+GqeF/zUqX2N6Kik6nQaT1lpkpHWL2C756o9qs0xOgfLvwMGdyEo
5zzq4hrWUkADn3iUfVtp3OjjD8aM4XoJ9nhK4v2V4T1gv+a0phAFZjwGvdrXLaUv559Iz
ST3uPyfnUZOuORO3u42crrq3jK1CV5Fjsp4NXpPYJl19/B9EDaUSOBZ7YJPQIAdU7fEoq
NWZzt/esn+dPkP49V6L1pq+uzM5VVLMwysE2xXsEFB3oDrU4GmXogmKa0SHazRCapy67B
vx5q0kcp+gMIbtmKYv/s1UoCx+GINZIK61DnrVzr9985Mju57y6FF92l4VZWjKwwLlw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794994271;
h=X-Original-To:Received:Received:DKIM-Signature:Received:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:References:In-Reply-To:From:Date:
X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
Content-Type:Content-Transfer-Encoding;
bh=0kn55mCijCWjeMsJaup/RZVejRphJIP7oArtyJYdwus=;
b=YKrwWrQ18pEQgFQGGTbQE7T17rlDXGuUYwVmVIgOX8vdKzeLX783YUYqJ7qYTZ9inrBZ
UED8bkTGnRm7tG/qg7A8oUkLNRLC5RwhsmdBtjFYr2PUyJVYArLCGqa9u2d3avAMQU0Jf
g6b6vN7dbp/7G7vp5KaUQV+B4q/2NBkJdO2EnlMw9zxHVXSFhCVaGYYxjnZ4HAgUqJ31V
FjVh+t3VRoSCEwZLo4aV2pbwpXD8V5hzRA+rW8WnrYgtiKcq4lYpdhCQ9YrrjcBbCgGsk
pikRZGhchHElRM1mvPTZGNP+cb9pZ+gthaah+abnCFOzuI/NsWfY7BXqhV9WjwaiUeQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BaSkeN5e;
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 12CB6606A33D;
Wed, 18 Nov 2026 09:31:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BaSkeN5e
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794994270;
b=SlMwOol0wkJ1RzKCXrZBonM2KnUGFg33WSSTbwQRb0vFfuBENdykkaTGYcgCsYa+NGTF
Gz+A0pPGjo2x90lcptEuERN8UQ5cQYgJ+4AtofW8ITp1gyoPhNHyRay6wE1kJJ46ujNbG
KvoHl8hhMKk7OY0IIUWuoOjky6kmri+6TXzpCykKTq3SKpnYwLYG060GKlu6nMqkluleU
MVnDCkFMEOooPD2hE1tpdXQY8KEKa3QabSrhsftltzT79cHG8PJSC6hi/1NoosrGZ8eNX
sGI14vre81BZCDhjZ/VsSsCYV6rCF5BFZa2y1NF4qo0hadxVsJuqolr9ZrDq6FFZusQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794994270;
h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
bh=0kn55mCijCWjeMsJaup/RZVejRphJIP7oArtyJYdwus=;
b=uHa6eCOCeNlqeZqJJWSAwWzTVgLl2ZmwENJXbYTGJcTIC22N6ytfLFBtb/xv1Jf8nG+v
mrSEOaZWTxrh2/f3aDy7JT+qwo+o295htiq255/kB5OYvMJgDu3JHl6xV18KXf0kTj9tp
2/xw3EcH1Bh9h1aniJMsEDL2dPSnWVN7F/FZeIi3liN38ylN6v7DrFiPMHABo3BtpDfq8
AgpZx+Fe4I5AbcixoyzYDSfx+cWwNLrsxuVoElM+2mZG9S8EDqTQje2JfNuxYdE6cSl01
mVlLz5D/WCL8xlX8jVrNTvYZI9xHOb9Ny1P8uTnEQSEqBU6JBR4lXT+ernLORr8Nztg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BaSkeN5e;
arc=none smtp.remote-ip=100.103.45.18
X-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 2FD76606A320
for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 09:31:10 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4B4F1F000CB
for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 09:31:09 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
s=k20260515; t=1794994269;
bh=0kn55mCijCWjeMsJaup/RZVejRphJIP7oArtyJYdwus=;
h=References:In-Reply-To:From:Date:Subject:To:Cc;
b=BaSkeN5exeFzGTBeQp9xWBiyjJ7dvHLMT2y5T3wuJFg7VXNEgjuKyHRNqdtd82HeX
OdemxYtLVjYXgBH7KTnOzq96sjvElSGxLpulqE+pqj/q71aXrKcu+xzFDUEWWL6RaW
VEbD6GFrMJwhby1yPzq6jzCzQgxOG1AhL8syTYs9adEEITk8rx6W673qs0DOlCOfua
hXexpwU4UFwoRUAq51WiZUCSswOWmppqfG3HIUM0eBwsmUjeoR7YOVaZxFDk7YC2TY
HwmHAT4ER+akdZ4CTJyZ2Q7xYz9trBHirX+F5zDtbbbD30iLcTEPisweBBLbH3nAQb
FNcyZ8akuFOpg==
X-Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-6b19e291cc6so644885eaf.2
for <netdev@vger.kernel.org>; Wed, 18 Nov 2026 01:31:09 -0800 (PST)
X-Forwarded-Encrypted: i=1; AL+hErFxrqZFYa6DyIL8WC9eWZzrIse8iyplgP0MdF0g/cznObUUVWf31VLa2cp8zUPwgxJNyMlnIiM=@vger.kernel.org
X-Gm-Message-State: APuU4Z9VEafSu/jHx5DnCCEToq2CLTSLUHBPJj50NOzgqRyTum7ZPUKN
VsA4zuIawpSyHSdkVtIkHrM94hXMRZ1F04L50pO4EX6TszprYW9JPdN3sU0NfxezygWHZmzjohl
HoKuxYzk/42+YYz3glb9g1on1eXN/Qdo=
X-Received: by 2002:a05:6820:2ad8:b0:717:da:ba40 with SMTP id
006d021491bc7-71b185657acmr1225893eaf.26.1794994269186; Wed, 18 Nov 2026
01:31:09 -0800 (PST)
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-In-Reply-To: <20261116023709.132684-3-thaisonphan@google.com>
X-Gmail-Original-Message-ID: <CAL4Wiir50_Z+m00GyU9BpRdAqgXs8V-L0S8kmmES=JiYyt==gg@mail.gmail.com>
X-Gm-Features: AclHuK9ptD7cBCsGNuyfU56eSbPiR5wyO28Z8shsRDEFiiGlM5HRM9FXIjfx3vE
X-Cc: Neal Cardwell <ncardwell@google.com>, Kuniyuki Iwashima <kuniyu@google.com>,
"David S . Miller" <davem@davemloft.net>, David Ahern <dsahern@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Ilpo Järvinen <ij@kernel.org>,
Olivier Tilmans <olivier.tilmans@nokia.com>,
Chia-Yu Chang <chia-yu.chang@nokia-bell-labs.com>, Stan Iliev <stani@google.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org