1
0

311-v6.2-wifi-mac80211-fix-and-simplify-unencrypted-drop-chec.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Thu, 1 Dec 2022 14:57:30 +0100
  3. Subject: [PATCH] wifi: mac80211: fix and simplify unencrypted drop check for
  4. mesh
  5. ieee80211_drop_unencrypted is called from ieee80211_rx_h_mesh_fwding and
  6. ieee80211_frame_allowed.
  7. Since ieee80211_rx_h_mesh_fwding can forward packets for other mesh nodes
  8. and is called earlier, it needs to check the decryptions status and if the
  9. packet is using the control protocol on its own, instead of deferring to
  10. the later call from ieee80211_frame_allowed.
  11. Because of that, ieee80211_drop_unencrypted has a mesh specific check
  12. that skips over the mesh header in order to check the payload protocol.
  13. This code is invalid when called from ieee80211_frame_allowed, since that
  14. happens after the 802.11->802.3 conversion.
  15. Fix this by moving the mesh specific check directly into
  16. ieee80211_rx_h_mesh_fwding.
  17. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  18. Link: https://lore.kernel.org/r/20221201135730.19723-1-nbd@nbd.name
  19. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  20. ---
  21. --- a/net/mac80211/rx.c
  22. +++ b/net/mac80211/rx.c
  23. @@ -2403,7 +2403,6 @@ static int ieee80211_802_1x_port_control
  24. static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
  25. {
  26. - struct ieee80211_hdr *hdr = (void *)rx->skb->data;
  27. struct sk_buff *skb = rx->skb;
  28. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  29. @@ -2414,31 +2413,6 @@ static int ieee80211_drop_unencrypted(st
  30. if (status->flag & RX_FLAG_DECRYPTED)
  31. return 0;
  32. - /* check mesh EAPOL frames first */
  33. - if (unlikely(rx->sta && ieee80211_vif_is_mesh(&rx->sdata->vif) &&
  34. - ieee80211_is_data(fc))) {
  35. - struct ieee80211s_hdr *mesh_hdr;
  36. - u16 hdr_len = ieee80211_hdrlen(fc);
  37. - u16 ethertype_offset;
  38. - __be16 ethertype;
  39. -
  40. - if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr))
  41. - goto drop_check;
  42. -
  43. - /* make sure fixed part of mesh header is there, also checks skb len */
  44. - if (!pskb_may_pull(rx->skb, hdr_len + 6))
  45. - goto drop_check;
  46. -
  47. - mesh_hdr = (struct ieee80211s_hdr *)(skb->data + hdr_len);
  48. - ethertype_offset = hdr_len + ieee80211_get_mesh_hdrlen(mesh_hdr) +
  49. - sizeof(rfc1042_header);
  50. -
  51. - if (skb_copy_bits(rx->skb, ethertype_offset, &ethertype, 2) == 0 &&
  52. - ethertype == rx->sdata->control_port_protocol)
  53. - return 0;
  54. - }
  55. -
  56. -drop_check:
  57. /* Drop unencrypted frames if key is set. */
  58. if (unlikely(!ieee80211_has_protected(fc) &&
  59. !ieee80211_is_any_nullfunc(fc) &&
  60. @@ -2892,8 +2866,16 @@ ieee80211_rx_h_mesh_fwding(struct ieee80
  61. hdr = (struct ieee80211_hdr *) skb->data;
  62. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  63. - if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
  64. - return RX_DROP_MONITOR;
  65. + if (ieee80211_drop_unencrypted(rx, hdr->frame_control)) {
  66. + int offset = hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr) +
  67. + sizeof(rfc1042_header);
  68. + __be16 ethertype;
  69. +
  70. + if (!ether_addr_equal(hdr->addr1, rx->sdata->vif.addr) ||
  71. + skb_copy_bits(rx->skb, offset, &ethertype, 2) != 0 ||
  72. + ethertype != rx->sdata->control_port_protocol)
  73. + return RX_DROP_MONITOR;
  74. + }
  75. /* frame is in RMC, don't forward */
  76. if (ieee80211_is_data(hdr->frame_control) &&