netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tcp: tcp_replace_ts_recent() should not be called from tcp_validate_incoming()
@ 2012-11-13  8:05 Eric Dumazet
  2012-11-13 12:02 ` Romain Francoise
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2012-11-13  8:05 UTC (permalink / raw)
  To: David Miller
  Cc: netdev, Neal Cardwell, Yuchung Cheng, Nandita Dukkipati,
	H.K. Jerry Chu

From: Eric Dumazet <edumazet@google.com>

We added support for RFC 5962 in latest kernels but TCP fails
to perform exhaustive check of ACK sequence.

We can update our view of peer tsval from a frame that is
later discarded by tcp_ack()

This makes timestamps enabled sessions vulnerable to injection of
a high tsval : peers start an ACK storm, since the victim
sends a dupack each time it receives an ACK from the other peer.

As tcp_validate_incoming() is called before tcp_ack(), we should
not peform tcp_replace_ts_recent() from it, and let callers do it
at the right time.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Nandita Dukkipati <nanditad@google.com>
Cc: H.K. Jerry Chu <hkchu@google.com>
---
 net/ipv4/tcp_input.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 7839d51..fc67831 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -5320,11 +5320,6 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
 		goto discard;
 	}
 
-	/* ts_recent update must be made after we are sure that the packet
-	 * is in window.
-	 */
-	tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
-
 	/* step 3: check security and precedence [ignored] */
 
 	/* step 4: Check for a SYN
@@ -5559,6 +5554,11 @@ step5:
 	if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
 		goto discard;
 
+	/* ts_recent update must be made after we are sure that the packet
+	 * is acceptable.
+	 */
+	tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
+
 	tcp_rcv_rtt_measure_ts(sk, skb);
 
 	/* Process urgent data. */
@@ -6137,6 +6137,11 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
 	} else
 		goto discard;
 
+	/* ts_recent update must be made after we are sure that the packet
+	 * is in acceptable.
+	 */
+	tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
+
 	/* step 6: check the URG bit */
 	tcp_urg(sk, skb, th);
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tcp: tcp_replace_ts_recent() should not be called from tcp_validate_incoming()
  2012-11-13  8:05 [PATCH] tcp: tcp_replace_ts_recent() should not be called from tcp_validate_incoming() Eric Dumazet
@ 2012-11-13 12:02 ` Romain Francoise
  2012-11-13 13:28   ` Eric Dumazet
  0 siblings, 1 reply; 5+ messages in thread
From: Romain Francoise @ 2012-11-13 12:02 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David Miller, netdev, Neal Cardwell, Yuchung Cheng,
	Nandita Dukkipati, H.K. Jerry Chu

Eric Dumazet <eric.dumazet@gmail.com> writes:

> We added support for RFC 5962 in latest kernels but TCP fails
> to perform exhaustive check of ACK sequence.

You probably meant 5961...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tcp: tcp_replace_ts_recent() should not be called from tcp_validate_incoming()
  2012-11-13 12:02 ` Romain Francoise
@ 2012-11-13 13:28   ` Eric Dumazet
  2012-11-13 15:37     ` [PATCH v2] " Eric Dumazet
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2012-11-13 13:28 UTC (permalink / raw)
  To: Romain Francoise
  Cc: David Miller, netdev, Neal Cardwell, Yuchung Cheng,
	Nandita Dukkipati, H.K. Jerry Chu

On Tue, 2012-11-13 at 13:02 +0100, Romain Francoise wrote:
> Eric Dumazet <eric.dumazet@gmail.com> writes:
> 
> > We added support for RFC 5962 in latest kernels but TCP fails
> > to perform exhaustive check of ACK sequence.
> 
> You probably meant 5961...

Oops you're right ;)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] tcp: tcp_replace_ts_recent() should not be called from tcp_validate_incoming()
  2012-11-13 13:28   ` Eric Dumazet
@ 2012-11-13 15:37     ` Eric Dumazet
  2012-11-13 19:35       ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2012-11-13 15:37 UTC (permalink / raw)
  To: Romain Francoise, David Miller
  Cc: netdev, Neal Cardwell, Yuchung Cheng, Nandita Dukkipati,
	H.K. Jerry Chu

From: Eric Dumazet <edumazet@google.com>

We added support for RFC 5961 in latest kernels but TCP fails
to perform exhaustive check of ACK sequence.

We can update our view of peer tsval from a frame that is
later discarded by tcp_ack()

This makes timestamps enabled sessions vulnerable to injection of
a high tsval : peers start an ACK storm, since the victim
sends a dupack each time it receives an ACK from the other peer.

As tcp_validate_incoming() is called before tcp_ack(), we should
not peform tcp_replace_ts_recent() from it, and let callers do it
at the right time.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Yuchung Cheng <ycheng@google.com>
Cc: Nandita Dukkipati <nanditad@google.com>
Cc: H.K. Jerry Chu <hkchu@google.com>
Cc: Romain Francoise <romain@orebokech.com>
---
v2: fix a typo in RFC number, as pointed out by Romain Francoise

 net/ipv4/tcp_input.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 7839d51..fc67831 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -5320,11 +5320,6 @@ static bool tcp_validate_incoming(struct sock *sk, struct sk_buff *skb,
 		goto discard;
 	}
 
-	/* ts_recent update must be made after we are sure that the packet
-	 * is in window.
-	 */
-	tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
-
 	/* step 3: check security and precedence [ignored] */
 
 	/* step 4: Check for a SYN
@@ -5559,6 +5554,11 @@ step5:
 	if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
 		goto discard;
 
+	/* ts_recent update must be made after we are sure that the packet
+	 * is in window.
+	 */
+	tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
+
 	tcp_rcv_rtt_measure_ts(sk, skb);
 
 	/* Process urgent data. */
@@ -6137,6 +6137,11 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
 	} else
 		goto discard;
 
+	/* ts_recent update must be made after we are sure that the packet
+	 * is in window.
+	 */
+	tcp_replace_ts_recent(tp, TCP_SKB_CB(skb)->seq);
+
 	/* step 6: check the URG bit */
 	tcp_urg(sk, skb, th);
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] tcp: tcp_replace_ts_recent() should not be called from tcp_validate_incoming()
  2012-11-13 15:37     ` [PATCH v2] " Eric Dumazet
@ 2012-11-13 19:35       ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2012-11-13 19:35 UTC (permalink / raw)
  To: eric.dumazet; +Cc: romain, netdev, ncardwell, ycheng, nanditad, hkchu

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Tue, 13 Nov 2012 07:37:18 -0800

> From: Eric Dumazet <edumazet@google.com>
> 
> We added support for RFC 5961 in latest kernels but TCP fails
> to perform exhaustive check of ACK sequence.
> 
> We can update our view of peer tsval from a frame that is
> later discarded by tcp_ack()
> 
> This makes timestamps enabled sessions vulnerable to injection of
> a high tsval : peers start an ACK storm, since the victim
> sends a dupack each time it receives an ACK from the other peer.
> 
> As tcp_validate_incoming() is called before tcp_ack(), we should
> not peform tcp_replace_ts_recent() from it, and let callers do it
> at the right time.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied, thanks a lot.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-11-13 19:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-13  8:05 [PATCH] tcp: tcp_replace_ts_recent() should not be called from tcp_validate_incoming() Eric Dumazet
2012-11-13 12:02 ` Romain Francoise
2012-11-13 13:28   ` Eric Dumazet
2012-11-13 15:37     ` [PATCH v2] " Eric Dumazet
2012-11-13 19:35       ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).