096-tcp-make-challenge-acks-less-predictable.patch 2.7 KB

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