0002.patch 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. diff -rcNP linux/include/net/tcp.h tirdad/include/net/tcp.h
  2. *** linux/include/net/tcp.h 2021-02-22 10:35:19.000000000 +0200
  3. --- tirdad/include/net/tcp.h 2021-02-22 10:25:37.000000000 +0200
  4. ***************
  5. *** 241,246 ****
  6. --- 241,247 ----
  7. /* sysctl variables for tcp */
  8. extern int sysctl_tcp_max_orphans;
  9. + extern int sysctl_tcp_random_isn;
  10. extern long sysctl_tcp_mem[3];
  11. extern int sysctl_tcp_simult_connect;
  12. diff -rcNP linux/net/core/secure_seq.c tirdad/net/core/secure_seq.c
  13. *** linux/net/core/secure_seq.c 2021-02-17 11:35:20.000000000 +0200
  14. --- tirdad/net/core/secure_seq.c 2021-02-22 10:28:57.000000000 +0200
  15. ***************
  16. *** 21,26 ****
  17. --- 21,27 ----
  18. #include <net/tcp.h>
  19. static siphash_key_t net_secret __read_mostly;
  20. + static siphash_key_t last_secret = {{0,0}};
  21. static siphash_key_t ts_secret __read_mostly;
  22. static __always_inline void net_secret_init(void)
  23. ***************
  24. *** 134,140 ****
  25. --- 135,160 ----
  26. __be16 sport, __be16 dport)
  27. {
  28. u32 hash;
  29. + u32 temp;
  30. + net_secret_init();
  31. +
  32. + if (sysctl_tcp_random_isn){
  33. + if (!last_secret.key[0] && !last_secret.key[1]){
  34. + memcpy(&last_secret,&net_secret,sizeof(last_secret));
  35. + }else{
  36. + temp = *((u32*)&(net_secret.key[0]));
  37. + temp >>= 8;
  38. + last_secret.key[0]+=temp;
  39. + temp = *((u32*)&(net_secret.key[1]));
  40. + temp >>= 8;
  41. + last_secret.key[1]+=temp;
  42. + }
  43. + hash = siphash_3u32((__force u32)saddr, (__force u32)daddr,
  44. + (__force u32)sport << 16 | (__force u32)dport,
  45. + &last_secret);
  46. + return hash;
  47. + }
  48. net_secret_init();
  49. hash = siphash_3u32((__force u32)saddr, (__force u32)daddr,
  50. (__force u32)sport << 16 | (__force u32)dport,
  51. diff -rcNP linux/net/ipv4/sysctl_net_ipv4.c tirdad/net/ipv4/sysctl_net_ipv4.c
  52. *** linux/net/ipv4/sysctl_net_ipv4.c 2021-02-22 10:35:20.000000000 +0200
  53. --- tirdad/net/ipv4/sysctl_net_ipv4.c 2021-02-22 10:30:09.000000000 +0200
  54. ***************
  55. *** 471,476 ****
  56. --- 471,483 ----
  57. static struct ctl_table ipv4_table[] = {
  58. {
  59. + .procname = "tcp_random_isn",
  60. + .data = &sysctl_tcp_random_isn,
  61. + .maxlen = sizeof(int),
  62. + .mode = 0644,
  63. + .proc_handler = proc_dointvec
  64. + },
  65. + {
  66. .procname = "tcp_max_orphans",
  67. .data = &sysctl_tcp_max_orphans,
  68. .maxlen = sizeof(int),
  69. diff -rcNP linux/net/ipv4/tcp_input.c tirdad/net/ipv4/tcp_input.c
  70. *** linux/net/ipv4/tcp_input.c 2021-02-22 10:35:20.000000000 +0200
  71. --- tirdad/net/ipv4/tcp_input.c 2021-02-22 10:31:04.000000000 +0200
  72. ***************
  73. *** 81,86 ****
  74. --- 81,87 ----
  75. #include <net/busy_poll.h>
  76. int sysctl_tcp_max_orphans __read_mostly = NR_FILE;
  77. + int sysctl_tcp_random_isn __read_mostly = 0;
  78. int sysctl_tcp_simult_connect __read_mostly = IS_ENABLED(CONFIG_TCP_SIMULT_CONNECT_DEFAULT_ON);
  79. #define FLAG_DATA 0x01 /* Incoming frame contained data. */