388-mac80211-do-not-accept-forward-invalid-EAPOL-frames.patch 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. From: Johannes Berg <[email protected]>
  2. Date: Tue, 11 May 2021 20:02:50 +0200
  3. Subject: [PATCH] mac80211: do not accept/forward invalid EAPOL frames
  4. EAPOL frames are used for authentication and key management between the
  5. AP and each individual STA associated in the BSS. Those frames are not
  6. supposed to be sent by one associated STA to another associated STA
  7. (either unicast for broadcast/multicast).
  8. Similarly, in 802.11 they're supposed to be sent to the authenticator
  9. (AP) address.
  10. Since it is possible for unexpected EAPOL frames to result in misbehavior
  11. in supplicant implementations, it is better for the AP to not allow such
  12. cases to be forwarded to other clients either directly, or indirectly if
  13. the AP interface is part of a bridge.
  14. Accept EAPOL (control port) frames only if they're transmitted to the
  15. own address, or, due to interoperability concerns, to the PAE group
  16. address.
  17. Disable forwarding of EAPOL (or well, the configured control port
  18. protocol) frames back to wireless medium in all cases. Previously, these
  19. frames were accepted from fully authenticated and authorized stations
  20. and also from unauthenticated stations for one of the cases.
  21. Additionally, to avoid forwarding by the bridge, rewrite the PAE group
  22. address case to the local MAC address.
  23. Cc: [email protected]
  24. Co-developed-by: Jouni Malinen <[email protected]>
  25. Signed-off-by: Jouni Malinen <[email protected]>
  26. Signed-off-by: Johannes Berg <[email protected]>
  27. ---
  28. --- a/net/mac80211/rx.c
  29. +++ b/net/mac80211/rx.c
  30. @@ -2541,13 +2541,13 @@ static bool ieee80211_frame_allowed(stru
  31. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  32. /*
  33. - * Allow EAPOL frames to us/the PAE group address regardless
  34. - * of whether the frame was encrypted or not.
  35. + * Allow EAPOL frames to us/the PAE group address regardless of
  36. + * whether the frame was encrypted or not, and always disallow
  37. + * all other destination addresses for them.
  38. */
  39. - if (ehdr->h_proto == rx->sdata->control_port_protocol &&
  40. - (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
  41. - ether_addr_equal(ehdr->h_dest, pae_group_addr)))
  42. - return true;
  43. + if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
  44. + return ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
  45. + ether_addr_equal(ehdr->h_dest, pae_group_addr);
  46. if (ieee80211_802_1x_port_control(rx) ||
  47. ieee80211_drop_unencrypted(rx, fc))
  48. @@ -2572,8 +2572,28 @@ static void ieee80211_deliver_skb_to_loc
  49. cfg80211_rx_control_port(dev, skb, noencrypt);
  50. dev_kfree_skb(skb);
  51. } else {
  52. + struct ethhdr *ehdr = (void *)skb_mac_header(skb);
  53. +
  54. memset(skb->cb, 0, sizeof(skb->cb));
  55. + /*
  56. + * 802.1X over 802.11 requires that the authenticator address
  57. + * be used for EAPOL frames. However, 802.1X allows the use of
  58. + * the PAE group address instead. If the interface is part of
  59. + * a bridge and we pass the frame with the PAE group address,
  60. + * then the bridge will forward it to the network (even if the
  61. + * client was not associated yet), which isn't supposed to
  62. + * happen.
  63. + * To avoid that, rewrite the destination address to our own
  64. + * address, so that the authenticator (e.g. hostapd) will see
  65. + * the frame, but bridge won't forward it anywhere else. Note
  66. + * that due to earlier filtering, the only other address can
  67. + * be the PAE group address.
  68. + */
  69. + if (unlikely(skb->protocol == sdata->control_port_protocol &&
  70. + !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
  71. + ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
  72. +
  73. /* deliver to local stack */
  74. if (rx->list)
  75. #if LINUX_VERSION_IS_GEQ(4,19,0)
  76. @@ -2617,6 +2637,7 @@ ieee80211_deliver_skb(struct ieee80211_r
  77. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  78. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  79. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  80. + ehdr->h_proto != rx->sdata->control_port_protocol &&
  81. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
  82. if (is_multicast_ether_addr(ehdr->h_dest) &&
  83. ieee80211_vif_get_num_mcast_if(sdata) != 0) {