Re: [PATCH net v2 2/2] tcp: accecn: initialize AccECN fields in syncookie path
From: Eric Dumazet
Date: Wed Nov 18 2026 - 04:31:21 EST
Le lun. 16 nov. 2026 à 03:37, Thaison Phan <thaisonphan@xxxxxxxxxx> 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@xxxxxxxxxx>
> Reviewed-by: Eric Dumazet <edumazet@xxxxxxxxxx>
> ---
> 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@xxxxxxxxxx/
>
> 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