007-Extend-protection-of-GTK-IGTK-reinstallation-of-WNM-.patch 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. From: Jouni Malinen <j@w1.fi>
  2. Date: Sun, 1 Oct 2017 12:12:24 +0300
  3. Subject: [PATCH] Extend protection of GTK/IGTK reinstallation of WNM-Sleep
  4. Mode cases
  5. This extends the protection to track last configured GTK/IGTK value
  6. separately from EAPOL-Key frames and WNM-Sleep Mode frames to cover a
  7. corner case where these two different mechanisms may get used when the
  8. GTK/IGTK has changed and tracking a single value is not sufficient to
  9. detect a possible key reconfiguration.
  10. Signed-off-by: Jouni Malinen <j@w1.fi>
  11. ---
  12. --- a/src/rsn_supp/wpa.c
  13. +++ b/src/rsn_supp/wpa.c
  14. @@ -780,14 +780,17 @@ struct wpa_gtk_data {
  15. static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
  16. const struct wpa_gtk_data *gd,
  17. - const u8 *key_rsc)
  18. + const u8 *key_rsc, int wnm_sleep)
  19. {
  20. const u8 *_gtk = gd->gtk;
  21. u8 gtk_buf[32];
  22. /* Detect possible key reinstallation */
  23. - if (sm->gtk.gtk_len == (size_t) gd->gtk_len &&
  24. - os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) {
  25. + if ((sm->gtk.gtk_len == (size_t) gd->gtk_len &&
  26. + os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) ||
  27. + (sm->gtk_wnm_sleep.gtk_len == (size_t) gd->gtk_len &&
  28. + os_memcmp(sm->gtk_wnm_sleep.gtk, gd->gtk,
  29. + sm->gtk_wnm_sleep.gtk_len) == 0)) {
  30. wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
  31. "WPA: Not reinstalling already in-use GTK to the driver (keyidx=%d tx=%d len=%d)",
  32. gd->keyidx, gd->tx, gd->gtk_len);
  33. @@ -828,8 +831,14 @@ static int wpa_supplicant_install_gtk(st
  34. }
  35. os_memset(gtk_buf, 0, sizeof(gtk_buf));
  36. - sm->gtk.gtk_len = gd->gtk_len;
  37. - os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len);
  38. + if (wnm_sleep) {
  39. + sm->gtk_wnm_sleep.gtk_len = gd->gtk_len;
  40. + os_memcpy(sm->gtk_wnm_sleep.gtk, gd->gtk,
  41. + sm->gtk_wnm_sleep.gtk_len);
  42. + } else {
  43. + sm->gtk.gtk_len = gd->gtk_len;
  44. + os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len);
  45. + }
  46. return 0;
  47. }
  48. @@ -923,7 +932,7 @@ static int wpa_supplicant_pairwise_gtk(s
  49. (wpa_supplicant_check_group_cipher(sm, sm->group_cipher,
  50. gtk_len, gtk_len,
  51. &gd.key_rsc_len, &gd.alg) ||
  52. - wpa_supplicant_install_gtk(sm, &gd, key_rsc))) {
  53. + wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0))) {
  54. wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
  55. "RSN: Failed to install GTK");
  56. os_memset(&gd, 0, sizeof(gd));
  57. @@ -939,14 +948,18 @@ static int wpa_supplicant_pairwise_gtk(s
  58. #ifdef CONFIG_IEEE80211W
  59. static int wpa_supplicant_install_igtk(struct wpa_sm *sm,
  60. - const struct wpa_igtk_kde *igtk)
  61. + const struct wpa_igtk_kde *igtk,
  62. + int wnm_sleep)
  63. {
  64. size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher);
  65. u16 keyidx = WPA_GET_LE16(igtk->keyid);
  66. /* Detect possible key reinstallation */
  67. - if (sm->igtk.igtk_len == len &&
  68. - os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) {
  69. + if ((sm->igtk.igtk_len == len &&
  70. + os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) ||
  71. + (sm->igtk_wnm_sleep.igtk_len == len &&
  72. + os_memcmp(sm->igtk_wnm_sleep.igtk, igtk->igtk,
  73. + sm->igtk_wnm_sleep.igtk_len) == 0)) {
  74. wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
  75. "WPA: Not reinstalling already in-use IGTK to the driver (keyidx=%d)",
  76. keyidx);
  77. @@ -971,8 +984,14 @@ static int wpa_supplicant_install_igtk(s
  78. return -1;
  79. }
  80. - sm->igtk.igtk_len = len;
  81. - os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len);
  82. + if (wnm_sleep) {
  83. + sm->igtk_wnm_sleep.igtk_len = len;
  84. + os_memcpy(sm->igtk_wnm_sleep.igtk, igtk->igtk,
  85. + sm->igtk_wnm_sleep.igtk_len);
  86. + } else {
  87. + sm->igtk.igtk_len = len;
  88. + os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len);
  89. + }
  90. return 0;
  91. }
  92. @@ -995,7 +1014,7 @@ static int ieee80211w_set_keys(struct wp
  93. return -1;
  94. igtk = (const struct wpa_igtk_kde *) ie->igtk;
  95. - if (wpa_supplicant_install_igtk(sm, igtk) < 0)
  96. + if (wpa_supplicant_install_igtk(sm, igtk, 0) < 0)
  97. return -1;
  98. }
  99. @@ -1641,7 +1660,7 @@ static void wpa_supplicant_process_1_of_
  100. if (wpa_supplicant_rsc_relaxation(sm, key->key_rsc))
  101. key_rsc = null_rsc;
  102. - if (wpa_supplicant_install_gtk(sm, &gd, key_rsc) ||
  103. + if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 0) ||
  104. wpa_supplicant_send_2_of_2(sm, key, ver, key_info) < 0)
  105. goto failed;
  106. os_memset(&gd, 0, sizeof(gd));
  107. @@ -2540,8 +2559,10 @@ void wpa_sm_notify_assoc(struct wpa_sm *
  108. sm->tptk_set = 0;
  109. os_memset(&sm->tptk, 0, sizeof(sm->tptk));
  110. os_memset(&sm->gtk, 0, sizeof(sm->gtk));
  111. + os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep));
  112. #ifdef CONFIG_IEEE80211W
  113. os_memset(&sm->igtk, 0, sizeof(sm->igtk));
  114. + os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep));
  115. #endif /* CONFIG_IEEE80211W */
  116. }
  117. @@ -3095,8 +3116,10 @@ void wpa_sm_drop_sa(struct wpa_sm *sm)
  118. os_memset(&sm->ptk, 0, sizeof(sm->ptk));
  119. os_memset(&sm->tptk, 0, sizeof(sm->tptk));
  120. os_memset(&sm->gtk, 0, sizeof(sm->gtk));
  121. + os_memset(&sm->gtk_wnm_sleep, 0, sizeof(sm->gtk_wnm_sleep));
  122. #ifdef CONFIG_IEEE80211W
  123. os_memset(&sm->igtk, 0, sizeof(sm->igtk));
  124. + os_memset(&sm->igtk_wnm_sleep, 0, sizeof(sm->igtk_wnm_sleep));
  125. #endif /* CONFIG_IEEE80211W */
  126. #ifdef CONFIG_IEEE80211R
  127. os_memset(sm->xxkey, 0, sizeof(sm->xxkey));
  128. @@ -3161,7 +3184,7 @@ int wpa_wnmsleep_install_key(struct wpa_
  129. wpa_hexdump_key(MSG_DEBUG, "Install GTK (WNM SLEEP)",
  130. gd.gtk, gd.gtk_len);
  131. - if (wpa_supplicant_install_gtk(sm, &gd, key_rsc)) {
  132. + if (wpa_supplicant_install_gtk(sm, &gd, key_rsc, 1)) {
  133. os_memset(&gd, 0, sizeof(gd));
  134. wpa_printf(MSG_DEBUG, "Failed to install the GTK in "
  135. "WNM mode");
  136. @@ -3173,7 +3196,7 @@ int wpa_wnmsleep_install_key(struct wpa_
  137. const struct wpa_igtk_kde *igtk;
  138. igtk = (const struct wpa_igtk_kde *) (buf + 2);
  139. - if (wpa_supplicant_install_igtk(sm, igtk) < 0)
  140. + if (wpa_supplicant_install_igtk(sm, igtk, 1) < 0)
  141. return -1;
  142. #endif /* CONFIG_IEEE80211W */
  143. } else {
  144. --- a/src/rsn_supp/wpa_i.h
  145. +++ b/src/rsn_supp/wpa_i.h
  146. @@ -32,8 +32,10 @@ struct wpa_sm {
  147. int rx_replay_counter_set;
  148. u8 request_counter[WPA_REPLAY_COUNTER_LEN];
  149. struct wpa_gtk gtk;
  150. + struct wpa_gtk gtk_wnm_sleep;
  151. #ifdef CONFIG_IEEE80211W
  152. struct wpa_igtk igtk;
  153. + struct wpa_igtk igtk_wnm_sleep;
  154. #endif /* CONFIG_IEEE80211W */
  155. struct eapol_sm *eapol; /* EAPOL state machine from upper level code */