387-mac80211-prevent-attacks-on-TKIP-WEP-as-well.patch 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. From: Johannes Berg <[email protected]>
  2. Date: Tue, 11 May 2021 20:02:49 +0200
  3. Subject: [PATCH] mac80211: prevent attacks on TKIP/WEP as well
  4. Similar to the issues fixed in previous patches, TKIP and WEP
  5. should be protected even if for TKIP we have the Michael MIC
  6. protecting it, and WEP is broken anyway.
  7. However, this also somewhat protects potential other algorithms
  8. that drivers might implement.
  9. Cc: [email protected]
  10. Signed-off-by: Johannes Berg <[email protected]>
  11. ---
  12. --- a/net/mac80211/rx.c
  13. +++ b/net/mac80211/rx.c
  14. @@ -2284,6 +2284,7 @@ ieee80211_rx_h_defragment(struct ieee802
  15. * next fragment has a sequential PN value.
  16. */
  17. entry->check_sequential_pn = true;
  18. + entry->is_protected = true;
  19. entry->key_color = rx->key->color;
  20. memcpy(entry->last_pn,
  21. rx->key->u.ccmp.rx_pn[queue],
  22. @@ -2296,6 +2297,9 @@ ieee80211_rx_h_defragment(struct ieee802
  23. sizeof(rx->key->u.gcmp.rx_pn[queue]));
  24. BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
  25. IEEE80211_GCMP_PN_LEN);
  26. + } else if (rx->key && ieee80211_has_protected(fc)) {
  27. + entry->is_protected = true;
  28. + entry->key_color = rx->key->color;
  29. }
  30. return RX_QUEUED;
  31. }
  32. @@ -2337,6 +2341,14 @@ ieee80211_rx_h_defragment(struct ieee802
  33. if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
  34. return RX_DROP_UNUSABLE;
  35. memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
  36. + } else if (entry->is_protected &&
  37. + (!rx->key || !ieee80211_has_protected(fc) ||
  38. + rx->key->color != entry->key_color)) {
  39. + /* Drop this as a mixed key or fragment cache attack, even
  40. + * if for TKIP Michael MIC should protect us, and WEP is a
  41. + * lost cause anyway.
  42. + */
  43. + return RX_DROP_UNUSABLE;
  44. }
  45. skb_pull(rx->skb, ieee80211_hdrlen(fc));
  46. --- a/net/mac80211/sta_info.h
  47. +++ b/net/mac80211/sta_info.h
  48. @@ -455,7 +455,8 @@ struct ieee80211_fragment_entry {
  49. u16 extra_len;
  50. u16 last_frag;
  51. u8 rx_queue;
  52. - bool check_sequential_pn; /* needed for CCMP/GCMP */
  53. + u8 check_sequential_pn:1, /* needed for CCMP/GCMP */
  54. + is_protected:1;
  55. u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
  56. unsigned int key_color;
  57. };