Skip to contentSkip to conversation

tcp: Disable usec TS for SYN Cookie.

PATCH In review Kuniyuki Iwashima 2 participants 4 messages Apr 18

Subsystems (3)
lore
Share & tools
lore

Kuniyuki Iwashima

author reviewer
#0 lore raw

PATCH 1/1 tcp: Disable usec TS for SYN Cookie.

cookie_tcp_reqsk_alloc() sets tcp_rsk(req)->req_usec_ts to false unconditionally.

If want_cookie is true in tcp_conn_request(), we should not set tcp_rsk(req)->req_usec_ts.

Let's not call dst_tcp_usec_ts() for SYN Cookie.

Fixes 614e8316aa4c ("tcp: add support for usec resolution in TCP TS values")
---
 net/ipv4/syncookies.c | 3 ---
 net/ipv4/tcp_input.c  | 3 ++-
 2 files changed, 2 insertions(+), 4 deletions(-)
net/ipv4/syncookies.c +0 -3
index b5f0a65c6786..f5cd9e325d01 100644
@@ -76,12 +76,9 @@ u64 cookie_init_timestamp(struct request_sock *req, u64 now)
 	if (ts > ts_now)
 		ts -= (1UL << TSBITS);
 
-	if (tcp_rsk(req)->req_usec_ts)
-		return ts * NSEC_PER_USEC;
 	return ts * NSEC_PER_MSEC;
 }
 
-
 static __u32 secure_tcp_syn_cookie(__be32 saddr, __be32 daddr, __be16 sport,
 				   __be16 dport, __u32 sseq, __u32 data)
 {
net/ipv4/tcp_input.c +2 -1
index cba89733d121..8bf202b95c68 100644
@@ -7720,7 +7720,8 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,
 		st = af_ops->init_seq_and_ts_off(net, skb);
 
 	if (tmp_opt.tstamp_ok) {
-		tcp_rsk(req)->req_usec_ts = dst_tcp_usec_ts(dst);
+		if (!want_cookie)
+			tcp_rsk(req)->req_usec_ts = dst_tcp_usec_ts(dst);
 		tcp_rsk(req)->ts_off = st.ts_off;
 	}
 	if (!want_cookie && !isn) {
Signature · 1 line
2.54.0.rc1.513.gad8abe7a5a-goog
#1 lore raw
Quoted 8 lines · Kuniyuki Iwashima

cookie_tcp_reqsk_alloc() sets tcp_rsk(req)->req_usec_ts to false unconditionally.

If want_cookie is true in tcp_conn_request(), we should not set tcp_rsk(req)->req_usec_ts.

Let's not call dst_tcp_usec_ts() for SYN Cookie.

May I ask why ?

TCP usec TS are based on routing. this feature is not part of SYN and/or SYNACK options.

Both side must have:

ip route ... feature tcp_usec_ts

syncookies are orthogonal to this constraint, so TCP flows can use usec TS just fine.

pw-bot: cr

author reviewer
#2 lore raw
Quoted 6 lines · Eric Dumazet
Quoted 4 lines · Kuniyuki Iwashima

cookie_tcp_reqsk_alloc() sets tcp_rsk(req)->req_usec_ts to false unconditionally.

Quoted 6 lines
Quoted 4 lines

If want_cookie is true in tcp_conn_request(), we should not set tcp_rsk(req)->req_usec_ts.

Let's not call dst_tcp_usec_ts() for SYN Cookie.

May I ask why ?

Sorry, I missed tcp_skb_timestamp_ts() properly restores the cookie TS generated by cookie_init_timestamp() to ms unit.

Still we don't need to call dst_tcp_usec_ts() for SYN cookie, but this was more like a cleanup patch.

Quoted 12 lines

TCP usec TS are based on routing. this feature is not part of SYN and/or SYNACK options.

Both side must have:

ip route ... feature tcp_usec_ts

syncookies are orthogonal to this constraint, so TCP flows can use usec TS just fine.

pw-bot: cr

#3 lore raw
Quoted 13 lines · Kuniyuki Iwashima
Quoted 11 lines · Eric Dumazet
Quoted 8 lines · Kuniyuki Iwashima

cookie_tcp_reqsk_alloc() sets tcp_rsk(req)->req_usec_ts to false unconditionally.

If want_cookie is true in tcp_conn_request(), we should not set tcp_rsk(req)->req_usec_ts.

Let's not call dst_tcp_usec_ts() for SYN Cookie.

Quoted 7 lines
Quoted 1 line

May I ask why ?

Sorry, I missed tcp_skb_timestamp_ts() properly restores the cookie TS generated by cookie_init_timestamp() to ms unit.

Still we don't need to call dst_tcp_usec_ts() for SYN cookie, but this was more like a cleanup patch.

Okay, but consider the standard path (or fast path) has to call it. dst_tcp_usec_ts() is a mere dst_feature(dst, RTAX_FEATURE_TCP_USEC_TS), which is pretty fast.
Adding a conditional branch won't help.