b984f6e86ce81f4998bb85981c9b94132c313a01
[openwrt/openwrt.git] / target / linux / generic / patches-3.18 / 096-tcp-make-challenge-acks-less-predictable.patch
1 From 75ff39ccc1bd5d3c455b6822ab09e533c551f758 Mon Sep 17 00:00:00 2001
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Sun, 10 Jul 2016 10:04:02 +0200
4 Subject: [PATCH] tcp: make challenge acks less predictable
5
6 Yue Cao claims that current host rate limiting of challenge ACKS
7 (RFC 5961) could leak enough information to allow a patient attacker
8 to hijack TCP sessions. He will soon provide details in an academic
9 paper.
10
11 This patch increases the default limit from 100 to 1000, and adds
12 some randomization so that the attacker can no longer hijack
13 sessions without spending a considerable amount of probes.
14
15 Based on initial analysis and patch from Linus.
16
17 Note that we also have per socket rate limiting, so it is tempting
18 to remove the host limit in the future.
19
20 v2: randomize the count of challenge acks per second, not the period.
21
22 Fixes: 282f23c6ee34 ("tcp: implement RFC 5961 3.2")
23 Reported-by: Yue Cao <ycao009@ucr.edu>
24 Signed-off-by: Eric Dumazet <edumazet@google.com>
25 Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
26 Cc: Yuchung Cheng <ycheng@google.com>
27 Cc: Neal Cardwell <ncardwell@google.com>
28 Acked-by: Neal Cardwell <ncardwell@google.com>
29 Acked-by: Yuchung Cheng <ycheng@google.com>
30 Signed-off-by: David S. Miller <davem@davemloft.net>
31 ---
32 net/ipv4/tcp_input.c | 15 ++++++++++-----
33 1 file changed, 10 insertions(+), 5 deletions(-)
34
35 --- a/net/ipv4/tcp_input.c
36 +++ b/net/ipv4/tcp_input.c
37 @@ -88,7 +88,7 @@ int sysctl_tcp_adv_win_scale __read_most
38 EXPORT_SYMBOL(sysctl_tcp_adv_win_scale);
39
40 /* rfc5961 challenge ack rate limiting */
41 -int sysctl_tcp_challenge_ack_limit = 100;
42 +int sysctl_tcp_challenge_ack_limit = 1000;
43
44 int sysctl_tcp_stdurg __read_mostly;
45 int sysctl_tcp_rfc1337 __read_mostly;
46 @@ -3325,12 +3325,18 @@ static void tcp_send_challenge_ack(struc
47 static u32 challenge_timestamp;
48 static unsigned int challenge_count;
49 u32 now = jiffies / HZ;
50 + u32 count;
51
52 if (now != challenge_timestamp) {
53 + u32 half = (sysctl_tcp_challenge_ack_limit + 1) >> 1;
54 +
55 challenge_timestamp = now;
56 - challenge_count = 0;
57 + WRITE_ONCE(challenge_count, half +
58 + prandom_u32_max(sysctl_tcp_challenge_ack_limit));
59 }
60 - if (++challenge_count <= sysctl_tcp_challenge_ack_limit) {
61 + count = READ_ONCE(challenge_count);
62 + if (count > 0) {
63 + WRITE_ONCE(challenge_count, count - 1);
64 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPCHALLENGEACK);
65 tcp_send_ack(sk);
66 }