906-v2.6-0006-TDLS-Reject-TPK-TK-reconfiguration.patch 4.2 KB

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