Skip to contentSkip to conversation

suspicious logic in tcp_make_synack()

DISCUSSION David Miller 3 participants 5 messages Oct 26, 2008 – Oct 27, 2008

Subsystems (3)
lore
Share & tools
lore

David Miller

author maintainer
#0 lore raw

I've been debugging something over the past few days and noticed something I can't explain in your change:

commit 33ad798c924b4a1afad3593f2796d465040aadd5

Author: Adam Langley <[email protected]>
Date:   Sat Jul 19 00:04:31 2008 -0700

tcp: options clean up

specifically this hunk of the change:

@@ -2244,18 +2295,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
else
#endif
- TCP_SKB_CB(skb)->when = tcp_time_stamp;
- tcp_syn_build_options((__be32 *)(th + 1), dst_metric(dst, RTAX_ADVMSS), ireq->tstamp_ok,

-			      ireq->sack_ok, ireq->wscale_ok, ireq->rcv_wscale,
-			      TCP_SKB_CB(skb)->when,
-			      req->ts_recent,
-			      (

-#ifdef CONFIG_TCP_MD5SIG
- md5 ? &md5_hash_location :
-#endif
- NULL)
- );
-
+ tcp_options_write((__be32 *)(th + 1), tp, &opts, &md5_hash_location);

the code right above this stuff reads:

#ifdef CONFIG_SYN_COOKIES
	if (unlikely(req->cookie_ts))
		TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
	else

#endif

The old code unconditionally built TCP options for the SYNACK, but now it doesn't build those options if req->cookie_ts, that call falls into the "else" branch, is that intentional?

That req->cookie_ts test is meant to only control how TCP_SKB_CB(skb)->when gets calculated.

This looks like a bug to me. It means also we now won't set ->when if CONFIG_SYN_COOKIES is enabled and req->cookie_ts is false.

#1 lore raw
Quoted 36 lines · David Miller

I've been debugging something over the past few days and noticed something I can't explain in your change:

commit 33ad798c924b4a1afad3593f2796d465040aadd5

Author: Adam Langley <[email protected]>
Date:   Sat Jul 19 00:04:31 2008 -0700

tcp: options clean up

specifically this hunk of the change:

(quoted diff) +1 -12
@@ -2244,18 +2295,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
 		TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
 	else
 #endif
-	TCP_SKB_CB(skb)->when = tcp_time_stamp;
-	tcp_syn_build_options((__be32 *)(th + 1), dst_metric(dst, RTAX_ADVMSS), ireq->tstamp_ok,
-			      ireq->sack_ok, ireq->wscale_ok, ireq->rcv_wscale,
-			      TCP_SKB_CB(skb)->when,
-			      req->ts_recent,
-			      (
-#ifdef CONFIG_TCP_MD5SIG
-			       md5 ? &md5_hash_location :
-#endif
-			       NULL)
-			      );
-
+	tcp_options_write((__be32 *)(th + 1), tp, &opts, &md5_hash_location);
 

the code right above this stuff reads:

#ifdef CONFIG_SYN_COOKIES
	if (unlikely(req->cookie_ts))
		TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
	else
Quoted 5 lines

#endif

The old code unconditionally built TCP options for the SYNACK, but now it doesn't build those options if req->cookie_ts, that call falls into the "else" branch, is that intentional?

I hope not 8-)

It essentially disables 4dfc2817025965a2fc78a18c50f540736a6b5c24 ('[Syncookies]: Add support for TCP options via timestamps.'), thanks for catching this.

Quoted 2 lines

That req->cookie_ts test is meant to only control how TCP_SKB_CB(skb)->when gets calculated.

Yes. Moving the #ifdef CONFIG_SYN_COOKIES block allows syncookies to use a tcp option subset again:

From: Florian Westphal <[email protected]>
Date: Sun, 26 Oct 2008 16:25:11 +0100
Subject: [PATCH] syncookies: fix inclusion of tcp options in syn-ack

David Miller noticed that commit 33ad798c924b4a1afad3593f2796d465040aadd5 '(tcp: options clean up') did not move the req->cookie_ts check.
This essentially disabled commit 4dfc2817025965a2fc78a18c50f540736a6b5c24 '[Syncookies]: Add support for TCP options via timestamps.'.

This restores the original logic.

---
 net/ipv4/tcp_output.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
net/ipv4/tcp_output.c +5 -5
index e4c5ac9..ba85d88 100644
@@ -2279,6 +2279,11 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
 	}
 
 	memset(&opts, 0, sizeof(opts));
+#ifdef CONFIG_SYN_COOKIES
+	if (unlikely(req->cookie_ts))
+		TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
+	else
+#endif
 	TCP_SKB_CB(skb)->when = tcp_time_stamp;
 	tcp_header_size = tcp_synack_options(sk, req, mss,
 					     skb, &opts, &md5) +
@@ -2304,11 +2309,6 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
 
 	/* RFC1323: The window in SYN & SYN/ACK segments is never scaled. */
 	th->window = htons(min(req->rcv_wnd, 65535U));
-#ifdef CONFIG_SYN_COOKIES
-	if (unlikely(req->cookie_ts))
-		TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
-	else
-#endif
 	tcp_options_write((__be32 *)(th + 1), tp, &opts, &md5_hash_location);
 	th->doff = (tcp_header_size >> 2);
 	TCP_INC_STATS(sock_net(sk), TCP_MIB_OUTSEGS);
author maintainer Applied
#2 lore raw

From: Florian Westphal <[email protected]>
Date: Sun, 26 Oct 2008 18:41:47 +0100

Quoted 11 lines

syncookies: fix inclusion of tcp options in syn-ack

David Miller noticed that commit 33ad798c924b4a1afad3593f2796d465040aadd5 '(tcp: options clean up') did not move the req->cookie_ts check.
This essentially disabled commit 4dfc2817025965a2fc78a18c50f540736a6b5c24 '[Syncookies]: Add support for TCP options via timestamps.'.

This restores the original logic.

Applied, thanks a lot Florian.

I can't count on my two hands how many bugs were caused by that one single commit :-(

#3 lore raw
Quoted 2 lines · David Miller

I can't count on my two hands how many bugs were caused by that one single commit :-(

I should have made more of an effort to keep up with netdev during the .27 release, rather than just the rc's, so I fear that I didn't see all the bugs. I'll go though the archives today.

Although that commit was born of an attempt to save some people from some of the pitfalls of modifying the previous code it clearly wasn't something that I should have attempted. The cost of newbies touching code in that area is too great both in tickling bugs in other systems (with option ordering) and in stupid omissions like this. It's probably been too long to revert it wholesale now, so I can only attempt to be more parsimonious in the future and hope that that's the last of the pain. If nothing else, suspicion of that commit has probably been raised to such a level that competent folks have checked it all over now.

AGL

Signature · 1 line
Adam Langley [email protected] http://www.imperialviolet.org
author maintainer
#4 lore raw

From: "Adam Langley" <[email protected]>
Date: Mon, 27 Oct 2008 08:51:19 -0700

Quoted 5 lines

Although that commit was born of an attempt to save some people from some of the pitfalls of modifying the previous code it clearly wasn't something that I should have attempted. The cost of newbies touching code in that area is too great both in tickling bugs in other systems (with option ordering) and in stupid omissions like this.

Adam, as I said, you and I share this burdon :-) I should have reviewed your changes more thoroughly, and for this change that is true no matter who actually wrote it.

Quoted 2 lines

If nothing else, suspicion of that commit has probably been raised to such a level that competent folks have checked it all over now.

Yes, I think we've fixed up all the issues by now.