Skip to contentSkip to conversation

tcp: initialize missing request_sock fields in syncookie path

PATCH Superseded Thaison Phan 4 participants 7 messages Nov 16 – Nov 18

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover tcp: initialize missing request_sock fields in syncookie path

Initialize missing request_sock fields for TCP connections accepted via SYN cookies, where cookie_tcp_reqsk_alloc() and bpf_sk_assign_tcp_reqsk() allocate without __GFP_ZERO:

- Patch 1 initializes ireq->ir_rmt_addr and ireq->ir_loc_addr to LOOPBACK4_IPV6 in cookie_v6_check(), matching tcp_v6_init_req().
- Patch 2 initializes saw_accecn_opt, accecn_fail_mode, and syn_ect_rcv in cookie_tcp_reqsk_init() and sets syn_ect_snt in cookie_{v4,v6}_check(), matching tcp_openreq_init() and tcp_{v4,v6}_send_synack().

An AI coding assistant helped audit the request_sock initialization paths, write the QEMU reproducer, and draft the changelogs.

v2:
- Patch 1: clarify how KASAN (via SLUB_RCU_DEBUG) exposed the bug, explain how it was observed, and include the inet_sock_set_state trace line (Eric Dumazet)
- Patch 2: drop redundant treq->syn_ect_snt = 0 in cookie_tcp_reqsk_init() and clarify how the bug was found and observed via TCP_INFO (Eric Dumazet)
- Add Eric Dumazet's Reviewed-by tags
v1: https://lore.kernel.org/netdev/[email protected]/

Thaison Phan (2):
tcp: initialize ir_rmt_addr and ir_loc_addr in cookie_v6_check()
tcp: accecn: initialize AccECN fields in syncookie path

 net/ipv4/syncookies.c | 4 ++++
 net/ipv6/syncookies.c | 4 ++++
 2 files changed, 8 insertions(+)

base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4

Signature · 1 line
2.56.0.611.g1030f0b940-goog
#1 lore raw

PATCH v2 1/2 tcp: initialize ir_rmt_addr and ir_loc_addr in cookie_v6_check()

Commit a3a128f611a9 ("inet: consolidate inet_csk_clone_lock()") moved the LOOPBACK4_IPV6 initialization for passive IPv6 TCP sockets from tcp_v6_syn_recv_sock() to tcp_v6_init_req().

IPv6 SYN cookie connections allocate a fresh request_sock without __GFP_ZERO and call tcp_v6_syn_recv_sock() without tcp_v6_init_req(), leaving ireq->ir_rmt_addr and ireq->ir_loc_addr uninitialized in cookie_v6_check(). inet_csk_clone_lock() then copies uninitialized slab bytes into sk_daddr, sk_rcv_saddr, and inet_saddr, exposing them to tracepoints and bpf_sock and causing inet_daddr != LOOPBACK4_IPV6 checks (such as IP_OPTIONS in do_ip_setsockopt()) to misclassify native IPv6 child sockets as IPv4-mapped.

This was originally noticed via an out-of-tree socket hook observing inet_sk(sk)->inet_saddr != LOOPBACK4_IPV6 on KASAN test runs. KASAN enables SLUB_RCU_DEBUG by default, introducing an RCU grace period that prevents cookie_v6_check() from reusing the warm request_sock initialized during the initial SYN. Upstream, with tcp_syncookies=2, SLUB_RCU_DEBUG=y, and slub_debug=P, sock:inet_sock_set_state shows slab poison instead of 127.0.0.6:

  ... sock:inet_sock_set_state: family=AF_INET6 protocol=IPPROTO_TCP \
      sport=59839 dport=41050 \
      saddr=90.90.90.90 daddr=90.90.90.90 \
      saddrv6=::1 daddrv6=::1 \
      oldstate=TCP_LISTEN newstate=TCP_SYN_RECV

Initialize ireq->ir_rmt_addr and ireq->ir_loc_addr to LOOPBACK4_IPV6 in cookie_v6_check() to match tcp_v6_init_req(). Tested against a QEMU reproducer checking inet_sock_set_state and IP_OPTIONS, as well as the packetdrill syncookie selftests.

Fixes a3a128f611a9 ("inet: consolidate inet_csk_clone_lock()")

---
v2:
- clarify how KASAN (via SLUB_RCU_DEBUG) exposed the uninitialized request_sock, how the issue was observed, and include the inet_sock_set_state trace line (Eric Dumazet)
- add Reviewed-by tag from Eric Dumazet
v1: https://lore.kernel.org/netdev/[email protected]/

 net/ipv6/syncookies.c | 3 +++
 1 file changed, 3 insertions(+)
net/ipv6/syncookies.c +3 -0
index b581cb1ee2e8..b33011b71fff 100644
@@ -17,6 +17,7 @@
 #include <net/ipv6.h>
 #include <net/tcp.h>
 #include <net/tcp_ecn.h>
+#include <net/transp_v6.h>
 
 #define COOKIEBITS 24	/* Upper bits store count */
 #define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1)
@@ -205,6 +206,8 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
 
 	ireq->ir_v6_rmt_addr = ipv6_hdr(skb)->saddr;
 	ireq->ir_v6_loc_addr = ipv6_hdr(skb)->daddr;
+	ireq->ir_rmt_addr = LOOPBACK4_IPV6;
+	ireq->ir_loc_addr = LOOPBACK4_IPV6;
 
 	if (security_inet_conn_request(sk, skb, req)) {
 		SKB_DR_SET(reason, SECURITY_HOOK);
Signature · 1 line
2.56.0.611.g1030f0b940-goog
#2 lore raw

PATCH v2 2/2 tcp: accecn: initialize AccECN fields in syncookie path

In reply to Thaison Phan

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")

---
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/[email protected]/

 net/ipv4/syncookies.c | 4 ++++
 net/ipv6/syncookies.c | 1 +
 2 files changed, 5 insertions(+)
net/ipv4/syncookies.c +4 -0
index 4e0ff3b82062..1a837ed6efa0 100644
@@ -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;
 
 	ret = tcp_get_cookie_sock(sk, skb, req, &rt->dst);
 	/* ip_queue_xmit() depends on our flow being setup
net/ipv6/syncookies.c +1 -0
index b33011b71fff..7435ebcc366c 100644
@@ -276,6 +276,7 @@ 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);
+	tcp_rsk(req)->syn_ect_snt = READ_ONCE(np->tclass) & INET_ECN_MASK;
 
 	ret = tcp_get_cookie_sock(sk, skb, req, dst);
 	if (!ret) {
Signature · 1 line
2.56.0.611.g1030f0b940-goog
Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH net v2 2/2] tcp: accecn: initialize AccECN fields in syncookie path

Hello,

Quoted 13 lines · Thaison Phan

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.

Quoted 4 lines

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().

I got a review from Sashiko [1] asking me to fix the same issue, and I was going to send the same patch. So this v2 looks good to me:

[1] https://lore.kernel.org/[email protected]

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.
#4 lore raw

Re: [PATCH net v2 2/2] tcp: accecn: initialize AccECN fields in syncookie path

In reply to Thaison Phan
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 2 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] On the BPF custom-syncookie path, the new syn_ect_snt assignment in cookie_v4_check() (net/ipv4/syncookies.c:508) and…
- [Medium] tcp: accecn: missing option init on 3rd ACK in syncookie path

--

tcp: accecn: initialize AccECN fields in syncookie path

This commit initializes saw_accecn_opt, accecn_fail_mode and syn_ect_rcv in cookie_tcp_reqsk_init() so they match tcp_openreq_init(). It also sets syn_ect_snt from the listener's tos/tclass in cookie_v4_check() and cookie_v6_check(), so the child socket's AccECN validation knows which ECN codepoint the cookie SYN-ACK carried.

Quoted 4 lines
net/ipv4/syncookies.c +0 -0
index 4e0ff3b820627..1a837ed6efa00 100644

[ ... ]

net/ipv4/syncookies.c struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) · line 508

Quoted 5 lines
net/ipv4/syncookies.c +1 -0
@@ -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;

[Severity: Medium]
Is the AccECN option on the third ACK ever looked at on the syncookie path? With cookies the listener kept no state, so the client's first AccECN option arrives on the same ACK that cookie_v4_check() and cookie_v6_check() turn into a child. On the normal SYN_RECV path, tcp_check_req() records it before the child is created:

net/ipv4/tcp_minisocks.c:tcp_check_req() {
    ...
	if (tcp_rsk(req)->accecn_ok && tmp_opt.accecn &&
	    tcp_rsk(req)->saw_accecn_opt < TCP_ACCECN_OPT_COUNTER_SEEN) {
		u8 saw_opt = tcp_accecn_option_init(skb, tmp_opt.accecn);

		tcp_rsk(req)->saw_accecn_opt = saw_opt;
    ...
}

Here cookie_tcp_reqsk_init() sets saw_accecn_opt to TCP_ACCECN_OPT_NOT_SEEN. Nothing between cookie_tcp_check() and tcp_ecn_openreq_child() calls tcp_accecn_option_init(), even though cookie_tcp_check() already parses the options into tcp_opt.accecn. The child therefore starts with tp->saw_accecn_opt == TCP_ACCECN_OPT_NOT_SEEN.

The tcp_child_process() -> tcp_rcv_state_process() -> tcp_ack() pass on the same skb does not fix this. snd_una already equals ack_seq, and ts_recent was copied from req->ts_recent. So neither FLAG_FORWARD_PROGRESS nor FLAG_TS_PROGRESS is set, and __tcp_accecn_process() returns before it reaches tcp_accecn_process_option().

With saw_accecn_opt stuck at zero:

- tcp_established_options() never emits AccECN options, even though accecn_opt_demand is set.
- A zeroed option on the third ACK is not caught as TCP_ACCECN_OPT_FAIL_SEEN.
- TCP_INFO reports tcpi_accecn_opt_seen as 0.
- Later processing in tcp_accecn_process_option() can flag TCP_ACCECN_OPT_FAIL_RECV on a connection where the peer did send the option.

This patch is aligning the cookie path with tcp_openreq_init(), so should cookie_v4_check() and cookie_v6_check() also do the equivalent of the tcp_check_req() block once accecn_ok is known? The parsed tcp_opt is local to cookie_tcp_check() and is not available on the cookie_bpf_check() path. Would you prefer to re-parse the options there or plumb them through? Or is this meant as a separate fix?

[Severity: Medium]
Does this assignment also apply to requests that come from cookie_bpf_check()? On that path the kernel never sent the SYN-ACK. A TC/XDP program built it, and bpf_sk_assign_tcp_reqsk() only gets an ecn_ok bit from struct bpf_tcp_req_attrs:

net/core/filter.c:bpf_sk_assign_tcp_reqsk() {
    ...
	ireq->ecn_ok = !!attrs->ecn_ok;
    ...
}

So the program has no way to report which ECN codepoint it put on the SYN-ACK, and the listener's tos/tclass is only a guess here.

The in-tree reference program sends Not-ECT for both families, in tools/testing/selftests/bpf/progs/test_tcp_custom_syncookie.c:tcp_handle_syn():

	ctx->ipv4->tos = 0;
    ...
	*(__be32 *)ctx->ipv6 = bpf_htonl(0x60000000);

When the listener runs DCTCP or another TCP_CONG_NEEDS_ECN CC, its tos/tclass carries ECT(0), so syn_ect_snt becomes ECT(0) here.

An AccECN client that receives the Not-ECT SYN-ACK reflects it in the third ACK through tcp_accecn_reflector_flags(), giving ACE=0b010. cookie_accecn_ok() then sets accecn_ok, and the child setup does:

tcp_get_cookie_sock()
->syn_recv_sock()

    tcp_ecn_openreq_child()
      tcp_accecn_third_ack(sk, skb, treq->syn_ect_snt)
        tcp_accecn_validate_syn_feedback()
            if (!tcp_ect_transition_valid(sent_ect, ect)) {
                tcp_accecn_fail_mode_set(tp, TCP_ACCECN_ACE_FAIL_RECV);

Would this set a false TCP_ACCECN_ACE_FAIL_RECV, the same failure the commit message describes, on every BPF syncookie connection to an ECT-marking listener? Before this patch the field was uninitialized. On zeroed memory it read as 0, which happened to match the Not-ECT SYN-ACK from that program.

The same applies to the IPv6 line below, which uses np->tclass.

Could the listener's tos/tclass be skipped for BPF-validated requests (req->syncookie set by the kfunc)? Alternatively, struct bpf_tcp_req_attrs could carry the SYN-ACK ECN codepoint.

Quoted 12 lines
net/ipv4/syncookies.c +0 -0
 	ret = tcp_get_cookie_sock(sk, skb, req, &rt->dst);
 	/* ip_queue_xmit() depends on our flow being setup
net/ipv6/syncookies.c +1 -0
index b33011b71fff6..7435ebcc366cd 100644
@@ -276,6 +276,7 @@ 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);
+	tcp_rsk(req)->syn_ect_snt = READ_ONCE(np->tclass) & INET_ECN_MASK;

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116023709.132684-1-thaisonphan%40google.com
maintainer
#5 lore raw

Re: [PATCH net v2 2/2] tcp: accecn: initialize AccECN fields in syncookie path

In reply to Thaison Phan
Quoted 59 lines · Thaison Phan

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")

---
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/[email protected]/

 net/ipv4/syncookies.c | 4 ++++
 net/ipv6/syncookies.c | 1 +
 2 files changed, 5 insertions(+)
net/ipv4/syncookies.c +3 -0
index 4e0ff3b82062..1a837ed6efa0 100644
@@ -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);

net/ipv4/syncookies.c struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) · line 508

Quoted 4 lines
net/ipv4/syncookies.c +1 -0
@@ -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

#6 lore raw

Re: [PATCH net v2 2/2] tcp: accecn: initialize AccECN fields in syncookie path

Quoted 6 lines · Eric Dumazet

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.

[...]

Quoted 20 lines

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.

Quoted 7 lines

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.

Makes sense, thanks for catching that and suggesting the fix. Since v3 [1] already went out yesterday for Chia-Yu's changelog clarification, I'll fold the !req->syncookie check, restore treq->syn_ect_snt = 0, and note the BPF custom syncookie behavior in v4.

I think the Sashiko remark on the (AccEcn Option carried by the third ACK) is correct as well, but I agree we can fix that in a separate patch set as it isn't directly related to uninitialized fields.

[1] https://lore.kernel.org/netdev/[email protected]/