1
0

010-TDLS-Reject-TPK-TK-reconfiguration.patch 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. From: Jouni Malinen <j@w1.fi>
  2. Date: Fri, 22 Sep 2017 11:03:15 +0300
  3. Subject: [PATCH] TDLS: Reject TPK-TK reconfiguration
  4. Do not try to reconfigure the same TPK-TK to the driver after it has
  5. been successfully configured. This is an explicit check to avoid issues
  6. related to resetting the TX/RX packet number. There was already a check
  7. for this for TPK M2 (retries of that message are ignored completely), so
  8. that behavior does not get modified.
  9. For TPK M3, the TPK-TK could have been reconfigured, but that was
  10. followed by immediate teardown of the link due to an issue in updating
  11. the STA entry. Furthermore, for TDLS with any real security (i.e.,
  12. ignoring open/WEP), the TPK message exchange is protected on the AP path
  13. and simple replay attacks are not feasible.
  14. As an additional corner case, make sure the local nonce gets updated if
  15. the peer uses a very unlikely "random nonce" of all zeros.
  16. Signed-off-by: Jouni Malinen <j@w1.fi>
  17. ---
  18. --- a/src/rsn_supp/tdls.c
  19. +++ b/src/rsn_supp/tdls.c
  20. @@ -112,6 +112,7 @@ struct wpa_tdls_peer {
  21. u8 tk[16]; /* TPK-TK; assuming only CCMP will be used */
  22. } tpk;
  23. int tpk_set;
  24. + int tk_set; /* TPK-TK configured to the driver */
  25. int tpk_success;
  26. int tpk_in_progress;
  27. @@ -192,6 +193,20 @@ static int wpa_tdls_set_key(struct wpa_s
  28. u8 rsc[6];
  29. enum wpa_alg alg;
  30. + if (peer->tk_set) {
  31. + /*
  32. + * This same TPK-TK has already been configured to the driver
  33. + * and this new configuration attempt (likely due to an
  34. + * unexpected retransmitted frame) would result in clearing
  35. + * the TX/RX sequence number which can break security, so must
  36. + * not allow that to happen.
  37. + */
  38. + wpa_printf(MSG_INFO, "TDLS: TPK-TK for the peer " MACSTR
  39. + " has already been configured to the driver - do not reconfigure",
  40. + MAC2STR(peer->addr));
  41. + return -1;
  42. + }
  43. +
  44. os_memset(rsc, 0, 6);
  45. switch (peer->cipher) {
  46. @@ -209,12 +224,15 @@ static int wpa_tdls_set_key(struct wpa_s
  47. return -1;
  48. }
  49. + wpa_printf(MSG_DEBUG, "TDLS: Configure pairwise key for peer " MACSTR,
  50. + MAC2STR(peer->addr));
  51. if (wpa_sm_set_key(sm, alg, peer->addr, -1, 1,
  52. rsc, sizeof(rsc), peer->tpk.tk, key_len) < 0) {
  53. wpa_printf(MSG_WARNING, "TDLS: Failed to set TPK to the "
  54. "driver");
  55. return -1;
  56. }
  57. + peer->tk_set = 1;
  58. return 0;
  59. }
  60. @@ -696,7 +714,7 @@ static void wpa_tdls_peer_clear(struct w
  61. peer->cipher = 0;
  62. peer->qos_info = 0;
  63. peer->wmm_capable = 0;
  64. - peer->tpk_set = peer->tpk_success = 0;
  65. + peer->tk_set = peer->tpk_set = peer->tpk_success = 0;
  66. peer->chan_switch_enabled = 0;
  67. os_memset(&peer->tpk, 0, sizeof(peer->tpk));
  68. os_memset(peer->inonce, 0, WPA_NONCE_LEN);
  69. @@ -1159,6 +1177,7 @@ skip_rsnie:
  70. wpa_tdls_peer_free(sm, peer);
  71. return -1;
  72. }
  73. + peer->tk_set = 0; /* A new nonce results in a new TK */
  74. wpa_hexdump(MSG_DEBUG, "TDLS: Initiator Nonce for TPK handshake",
  75. peer->inonce, WPA_NONCE_LEN);
  76. os_memcpy(ftie->Snonce, peer->inonce, WPA_NONCE_LEN);
  77. @@ -1751,6 +1770,19 @@ static int wpa_tdls_addset_peer(struct w
  78. }
  79. +static int tdls_nonce_set(const u8 *nonce)
  80. +{
  81. + int i;
  82. +
  83. + for (i = 0; i < WPA_NONCE_LEN; i++) {
  84. + if (nonce[i])
  85. + return 1;
  86. + }
  87. +
  88. + return 0;
  89. +}
  90. +
  91. +
  92. static int wpa_tdls_process_tpk_m1(struct wpa_sm *sm, const u8 *src_addr,
  93. const u8 *buf, size_t len)
  94. {
  95. @@ -2004,7 +2036,8 @@ skip_rsn:
  96. peer->rsnie_i_len = kde.rsn_ie_len;
  97. peer->cipher = cipher;
  98. - if (os_memcmp(peer->inonce, ftie->Snonce, WPA_NONCE_LEN) != 0) {
  99. + if (os_memcmp(peer->inonce, ftie->Snonce, WPA_NONCE_LEN) != 0 ||
  100. + !tdls_nonce_set(peer->inonce)) {
  101. /*
  102. * There is no point in updating the RNonce for every obtained
  103. * TPK M1 frame (e.g., retransmission due to timeout) with the
  104. @@ -2020,6 +2053,7 @@ skip_rsn:
  105. "TDLS: Failed to get random data for responder nonce");
  106. goto error;
  107. }
  108. + peer->tk_set = 0; /* A new nonce results in a new TK */
  109. }
  110. #if 0