Skip to content

Commit 5f1f390

Browse files
zx2c4gregkh
authored andcommitted
mac80211/wpa: use constant time memory comparison for MACs
commit 98c67d187db7808b1f3c95f2110dd4392d034182 upstream. Otherwise, we enable all sorts of forgeries via timing attack. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: linux-wireless@vger.kernel.org Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 156f006 commit 5f1f390

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

net/mac80211/wpa.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <asm/unaligned.h>
1717
#include <net/mac80211.h>
1818
#include <crypto/aes.h>
19+
#include <crypto/algapi.h>
1920

2021
#include "ieee80211_i.h"
2122
#include "michael.h"
@@ -152,7 +153,7 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
152153
data_len = skb->len - hdrlen - MICHAEL_MIC_LEN;
153154
key = &rx->key->conf.key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY];
154155
michael_mic(key, hdr, data, data_len, mic);
155-
if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0)
156+
if (crypto_memneq(mic, data + data_len, MICHAEL_MIC_LEN))
156157
goto mic_fail;
157158

158159
/* remove Michael MIC from payload */
@@ -1044,7 +1045,7 @@ ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx)
10441045
bip_aad(skb, aad);
10451046
ieee80211_aes_cmac(key->u.aes_cmac.tfm, aad,
10461047
skb->data + 24, skb->len - 24, mic);
1047-
if (memcmp(mic, mmie->mic, sizeof(mmie->mic)) != 0) {
1048+
if (crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) {
10481049
key->u.aes_cmac.icverrors++;
10491050
return RX_DROP_UNUSABLE;
10501051
}
@@ -1094,7 +1095,7 @@ ieee80211_crypto_aes_cmac_256_decrypt(struct ieee80211_rx_data *rx)
10941095
bip_aad(skb, aad);
10951096
ieee80211_aes_cmac_256(key->u.aes_cmac.tfm, aad,
10961097
skb->data + 24, skb->len - 24, mic);
1097-
if (memcmp(mic, mmie->mic, sizeof(mmie->mic)) != 0) {
1098+
if (crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) {
10981099
key->u.aes_cmac.icverrors++;
10991100
return RX_DROP_UNUSABLE;
11001101
}
@@ -1198,7 +1199,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct ieee80211_rx_data *rx)
11981199
if (ieee80211_aes_gmac(key->u.aes_gmac.tfm, aad, nonce,
11991200
skb->data + 24, skb->len - 24,
12001201
mic) < 0 ||
1201-
memcmp(mic, mmie->mic, sizeof(mmie->mic)) != 0) {
1202+
crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) {
12021203
key->u.aes_gmac.icverrors++;
12031204
return RX_DROP_UNUSABLE;
12041205
}

0 commit comments

Comments
 (0)