316-v6.3-wifi-mac80211-add-a-workaround-for-receiving-non-sta.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Fri, 9 Dec 2022 21:15:04 +0100
  3. Subject: [PATCH] wifi: mac80211: add a workaround for receiving
  4. non-standard mesh A-MSDU
  5. At least ath10k and ath11k supported hardware (maybe more) does not implement
  6. mesh A-MSDU aggregation in a standard compliant way.
  7. 802.11-2020 9.3.2.2.2 declares that the Mesh Control field is part of the
  8. A-MSDU header. As such, its length must not be included in the subframe
  9. length field.
  10. Hardware affected by this bug treats the mesh control field as part of the
  11. MSDU data and sets the length accordingly.
  12. In order to avoid packet loss, keep track of which stations are affected
  13. by this and take it into account when converting A-MSDU to 802.3 + mesh control
  14. packets.
  15. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  16. ---
  17. --- a/include/net/cfg80211.h
  18. +++ b/include/net/cfg80211.h
  19. @@ -6194,6 +6194,19 @@ static inline int ieee80211_data_to_8023
  20. }
  21. /**
  22. + * ieee80211_is_valid_amsdu - check if subframe lengths of an A-MSDU are valid
  23. + *
  24. + * This is used to detect non-standard A-MSDU frames, e.g. the ones generated
  25. + * by ath10k and ath11k, where the subframe length includes the length of the
  26. + * mesh control field.
  27. + *
  28. + * @skb: The input A-MSDU frame without any headers.
  29. + * @mesh_hdr: use standard compliant mesh A-MSDU subframe header
  30. + * Returns: true if subframe header lengths are valid for the @mesh_hdr mode
  31. + */
  32. +bool ieee80211_is_valid_amsdu(struct sk_buff *skb, bool mesh_hdr);
  33. +
  34. +/**
  35. * ieee80211_amsdu_to_8023s - decode an IEEE 802.11n A-MSDU frame
  36. *
  37. * Decode an IEEE 802.11 A-MSDU and convert it to a list of 802.3 frames.
  38. --- a/net/mac80211/rx.c
  39. +++ b/net/mac80211/rx.c
  40. @@ -2899,7 +2899,6 @@ __ieee80211_rx_h_amsdu(struct ieee80211_
  41. static ieee80211_rx_result res;
  42. struct ethhdr ethhdr;
  43. const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
  44. - bool mesh = false;
  45. if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
  46. check_da = NULL;
  47. @@ -2917,7 +2916,6 @@ __ieee80211_rx_h_amsdu(struct ieee80211_
  48. case NL80211_IFTYPE_MESH_POINT:
  49. check_sa = NULL;
  50. check_da = NULL;
  51. - mesh = true;
  52. break;
  53. default:
  54. break;
  55. @@ -2932,10 +2930,21 @@ __ieee80211_rx_h_amsdu(struct ieee80211_
  56. data_offset, true))
  57. return RX_DROP_UNUSABLE;
  58. + if (rx->sta && rx->sta->amsdu_mesh_control < 0) {
  59. + bool valid_std = ieee80211_is_valid_amsdu(skb, true);
  60. + bool valid_nonstd = ieee80211_is_valid_amsdu(skb, false);
  61. +
  62. + if (valid_std && !valid_nonstd)
  63. + rx->sta->amsdu_mesh_control = 1;
  64. + else if (valid_nonstd && !valid_std)
  65. + rx->sta->amsdu_mesh_control = 0;
  66. + }
  67. +
  68. ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
  69. rx->sdata->vif.type,
  70. rx->local->hw.extra_tx_headroom,
  71. - check_da, check_sa, mesh);
  72. + check_da, check_sa,
  73. + rx->sta->amsdu_mesh_control);
  74. while (!skb_queue_empty(&frame_list)) {
  75. rx->skb = __skb_dequeue(&frame_list);
  76. --- a/net/mac80211/sta_info.c
  77. +++ b/net/mac80211/sta_info.c
  78. @@ -591,6 +591,9 @@ __sta_info_alloc(struct ieee80211_sub_if
  79. sta->sta_state = IEEE80211_STA_NONE;
  80. + if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  81. + sta->amsdu_mesh_control = -1;
  82. +
  83. /* Mark TID as unreserved */
  84. sta->reserved_tid = IEEE80211_TID_UNRESERVED;
  85. --- a/net/mac80211/sta_info.h
  86. +++ b/net/mac80211/sta_info.h
  87. @@ -702,6 +702,7 @@ struct sta_info {
  88. struct codel_params cparams;
  89. u8 reserved_tid;
  90. + s8 amsdu_mesh_control;
  91. struct cfg80211_chan_def tdls_chandef;
  92. --- a/net/wireless/util.c
  93. +++ b/net/wireless/util.c
  94. @@ -776,6 +776,38 @@ __ieee80211_amsdu_copy(struct sk_buff *s
  95. return frame;
  96. }
  97. +bool ieee80211_is_valid_amsdu(struct sk_buff *skb, bool mesh_hdr)
  98. +{
  99. + int offset = 0, remaining, subframe_len, padding;
  100. +
  101. + for (offset = 0; offset < skb->len; offset += subframe_len + padding) {
  102. + struct {
  103. + __be16 len;
  104. + u8 mesh_flags;
  105. + } hdr;
  106. + u16 len;
  107. +
  108. + if (skb_copy_bits(skb, offset + 2 * ETH_ALEN, &hdr, sizeof(hdr)) < 0)
  109. + return false;
  110. +
  111. + if (mesh_hdr)
  112. + len = le16_to_cpu(*(__le16 *)&hdr.len) +
  113. + __ieee80211_get_mesh_hdrlen(hdr.mesh_flags);
  114. + else
  115. + len = ntohs(hdr.len);
  116. +
  117. + subframe_len = sizeof(struct ethhdr) + len;
  118. + padding = (4 - subframe_len) & 0x3;
  119. + remaining = skb->len - offset;
  120. +
  121. + if (subframe_len > remaining)
  122. + return false;
  123. + }
  124. +
  125. + return true;
  126. +}
  127. +EXPORT_SYMBOL(ieee80211_is_valid_amsdu);
  128. +
  129. void ieee80211_amsdu_to_8023s(struct sk_buff *skb, struct sk_buff_head *list,
  130. const u8 *addr, enum nl80211_iftype iftype,
  131. const unsigned int extra_headroom,