Skip to content

Commit 66760ea

Browse files
Felix Fietkaulinvjw
authored andcommitted
ath9k: improve reliability of MIC error detection
For unicast the hardware sometimes reports MIC errors even though the frame that it received actually contains a valid MIC - on some chips this can happen frequently enough to trigger TKIP countermeasures. Fix this issue by not reporting MIC errors for unicast frames with a valid key, letting mac80211 validate the MIC instead. Additionally, strip the MIC for all frames that the hardware considers valid to avoid wasting CPU cycles re-validating it. Signed-off-by: Felix Fietkau <nbd@openwrt.org> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent 933d594 commit 66760ea

1 file changed

Lines changed: 32 additions & 21 deletions

File tree

  • drivers/net/wireless/ath/ath9k

‎drivers/net/wireless/ath/ath9k/recv.c‎

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -814,16 +814,19 @@ static bool ath9k_rx_accept(struct ath_common *common,
814814
struct ath_rx_status *rx_stats,
815815
bool *decrypt_error)
816816
{
817-
#define is_mc_or_valid_tkip_keyix ((is_mc || \
818-
(rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID && \
819-
test_bit(rx_stats->rs_keyix, common->tkip_keymap))))
820-
817+
bool is_mc, is_valid_tkip, strip_mic, mic_error;
821818
struct ath_hw *ah = common->ah;
822819
__le16 fc;
823820
u8 rx_status_len = ah->caps.rx_status_len;
824821

825822
fc = hdr->frame_control;
826823

824+
is_mc = !!is_multicast_ether_addr(hdr->addr1);
825+
is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID &&
826+
test_bit(rx_stats->rs_keyix, common->tkip_keymap);
827+
strip_mic = is_valid_tkip && !(rx_stats->rs_status &
828+
(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC));
829+
827830
if (!rx_stats->rs_datalen)
828831
return false;
829832
/*
@@ -838,37 +841,30 @@ static bool ath9k_rx_accept(struct ath_common *common,
838841
if (rx_stats->rs_more)
839842
return true;
840843

844+
mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) &&
845+
!ieee80211_has_morefrags(fc) &&
846+
!(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
847+
(rx_stats->rs_status & ATH9K_RXERR_MIC);
848+
841849
/*
842850
* The rx_stats->rs_status will not be set until the end of the
843851
* chained descriptors so it can be ignored if rs_more is set. The
844852
* rs_more will be false at the last element of the chained
845853
* descriptors.
846854
*/
847855
if (rx_stats->rs_status != 0) {
848-
if (rx_stats->rs_status & ATH9K_RXERR_CRC)
856+
if (rx_stats->rs_status & ATH9K_RXERR_CRC) {
849857
rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
858+
mic_error = false;
859+
}
850860
if (rx_stats->rs_status & ATH9K_RXERR_PHY)
851861
return false;
852862

853863
if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
854864
*decrypt_error = true;
855-
} else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
856-
bool is_mc;
857-
/*
858-
* The MIC error bit is only valid if the frame
859-
* is not a control frame or fragment, and it was
860-
* decrypted using a valid TKIP key.
861-
*/
862-
is_mc = !!is_multicast_ether_addr(hdr->addr1);
863-
864-
if (!ieee80211_is_ctl(fc) &&
865-
!ieee80211_has_morefrags(fc) &&
866-
!(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
867-
is_mc_or_valid_tkip_keyix)
868-
rxs->flag |= RX_FLAG_MMIC_ERROR;
869-
else
870-
rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
865+
mic_error = false;
871866
}
867+
872868
/*
873869
* Reject error frames with the exception of
874870
* decryption and MIC failures. For monitor mode,
@@ -886,6 +882,18 @@ static bool ath9k_rx_accept(struct ath_common *common,
886882
}
887883
}
888884
}
885+
886+
/*
887+
* For unicast frames the MIC error bit can have false positives,
888+
* so all MIC error reports need to be validated in software.
889+
* False negatives are not common, so skip software verification
890+
* if the hardware considers the MIC valid.
891+
*/
892+
if (strip_mic)
893+
rxs->flag |= RX_FLAG_MMIC_STRIPPED;
894+
else if (is_mc && mic_error)
895+
rxs->flag |= RX_FLAG_MMIC_ERROR;
896+
889897
return true;
890898
}
891899

@@ -1938,6 +1946,9 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
19381946
sc->rx.rxotherant = 0;
19391947
}
19401948

1949+
if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
1950+
skb_trim(skb, skb->len - 8);
1951+
19411952
spin_lock_irqsave(&sc->sc_pm_lock, flags);
19421953

19431954
if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |

0 commit comments

Comments
 (0)