1
0

015-Clear-PMK-length-and-check-for-this-when-deriving-PT.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. From b488a12948751f57871f09baa345e59b23959a41 Mon Sep 17 00:00:00 2001
  2. From: Jouni Malinen <j@w1.fi>
  3. Date: Sun, 8 Oct 2017 13:18:02 +0300
  4. Subject: [PATCH] Clear PMK length and check for this when deriving PTK
  5. Instead of setting the default PMK length for the cleared PMK, set the
  6. length to 0 and explicitly check for this when deriving PTK to avoid
  7. unexpected key derivation with an all-zeroes key should it be possible
  8. to somehow trigger PTK derivation to happen before PMK derivation.
  9. Signed-off-by: Jouni Malinen <j@w1.fi>
  10. ---
  11. src/common/wpa_common.c | 5 +++++
  12. src/rsn_supp/wpa.c | 7 ++++---
  13. 2 files changed, 9 insertions(+), 3 deletions(-)
  14. --- a/src/common/wpa_common.c
  15. +++ b/src/common/wpa_common.c
  16. @@ -225,6 +225,11 @@ int wpa_pmk_to_ptk(const u8 *pmk, size_t
  17. u8 tmp[WPA_KCK_MAX_LEN + WPA_KEK_MAX_LEN + WPA_TK_MAX_LEN];
  18. size_t ptk_len;
  19. + if (pmk_len == 0) {
  20. + wpa_printf(MSG_ERROR, "WPA: No PMK set for PT derivation");
  21. + return -1;
  22. + }
  23. +
  24. if (os_memcmp(addr1, addr2, ETH_ALEN) < 0) {
  25. os_memcpy(data, addr1, ETH_ALEN);
  26. os_memcpy(data + ETH_ALEN, addr2, ETH_ALEN);
  27. --- a/src/rsn_supp/wpa.c
  28. +++ b/src/rsn_supp/wpa.c
  29. @@ -584,7 +584,8 @@ static void wpa_supplicant_process_1_of_
  30. /* Calculate PTK which will be stored as a temporary PTK until it has
  31. * been verified when processing message 3/4. */
  32. ptk = &sm->tptk;
  33. - wpa_derive_ptk(sm, src_addr, key, ptk);
  34. + if (wpa_derive_ptk(sm, src_addr, key, ptk) < 0)
  35. + goto failed;
  36. if (sm->pairwise_cipher == WPA_CIPHER_TKIP) {
  37. u8 buf[8];
  38. /* Supplicant: swap tx/rx Mic keys */
  39. @@ -2705,8 +2706,8 @@ void wpa_sm_set_pmk_from_pmksa(struct wp
  40. sm->pmk_len = sm->cur_pmksa->pmk_len;
  41. os_memcpy(sm->pmk, sm->cur_pmksa->pmk, sm->pmk_len);
  42. } else {
  43. - sm->pmk_len = PMK_LEN;
  44. - os_memset(sm->pmk, 0, PMK_LEN);
  45. + sm->pmk_len = 0;
  46. + os_memset(sm->pmk, 0, PMK_LEN_MAX);
  47. }
  48. }