mac80211: prevent mixed key and fragment cache attacks
authorMathy Vanhoef <Mathy.Vanhoef@kuleuven.be>
Mon, 31 May 2021 20:31:27 +0000 (22:31 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 3 Jun 2021 06:36:13 +0000 (08:36 +0200)
commit 94034c40ab4a3fcf581fbc7f8fdf4e29943c4a24 upstream.

Simultaneously prevent mixed key attacks (CVE-2020-24587) and fragment
cache attacks (CVE-2020-24586). This is accomplished by assigning a
unique color to every key (per interface) and using this to track which
key was used to decrypt a fragment. When reassembling frames, it is
now checked whether all fragments were decrypted using the same key.

To assure that fragment cache attacks are also prevented, the ID that is
assigned to keys is unique even over (re)associations and (re)connects.
This means fragments separated by a (re)association or (re)connect will
not be reassembled. Because mac80211 now also prevents the reassembly of
mixed encrypted and plaintext fragments, all cache attacks are prevented.

Cc: stable@vger.kernel.org
Signed-off-by: Mathy Vanhoef <Mathy.Vanhoef@kuleuven.be>
Link: https://lore.kernel.org/r/20210511200110.3f8290e59823.I622a67769ed39257327a362cfc09c812320eb979@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/mac80211/ieee80211_i.h
net/mac80211/key.c
net/mac80211/key.h
net/mac80211/rx.c

index 651705565dfb9d2b2147b2a9870b4c5c78dd18bc..74186c2d9e6e50d9311793d0c485c497bc61d07a 100644 (file)
@@ -99,6 +99,7 @@ struct ieee80211_fragment_entry {
        u8 rx_queue;
        bool check_sequential_pn; /* needed for CCMP/GCMP */
        u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
+       unsigned int key_color;
 };
 
 
index fa10c61422440b8faaa5f37fb327490cbb43d60f..d122031e389ab7d037712a7e0b6740347aba81e5 100644 (file)
@@ -648,6 +648,7 @@ int ieee80211_key_link(struct ieee80211_key *key,
                       struct sta_info *sta)
 {
        struct ieee80211_local *local = sdata->local;
+       static atomic_t key_color = ATOMIC_INIT(0);
        struct ieee80211_key *old_key;
        int idx = key->conf.keyidx;
        bool pairwise = key->conf.flags & IEEE80211_KEY_FLAG_PAIRWISE;
@@ -659,6 +660,12 @@ int ieee80211_key_link(struct ieee80211_key *key,
        bool delay_tailroom = sdata->vif.type == NL80211_IFTYPE_STATION;
        int ret;
 
+       /*
+        * Assign a unique ID to every key so we can easily prevent mixed
+        * key and fragment cache attacks.
+        */
+       key->color = atomic_inc_return(&key_color);
+
        mutex_lock(&sdata->local->key_mtx);
 
        if (sta && pairwise)
index ebdb80b85dc3aa3b12da1f8925df3552a51674b3..d8e187bcb7510349766789627bb0439e8e113be5 100644 (file)
@@ -127,6 +127,8 @@ struct ieee80211_key {
        } debugfs;
 #endif
 
+       unsigned int color;
+
        /*
         * key config, must be last because it contains key
         * material as variable length member
index 9b313c2f7d49d2106554927fb347c2abf1c485fa..8c126854aa067b3788b1e048ea08f4ed39c902b9 100644 (file)
@@ -2029,6 +2029,7 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
                         * next fragment has a sequential PN value.
                         */
                        entry->check_sequential_pn = true;
+                       entry->key_color = rx->key->color;
                        memcpy(entry->last_pn,
                               rx->key->u.ccmp.rx_pn[queue],
                               IEEE80211_CCMP_PN_LEN);
@@ -2066,6 +2067,11 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
 
                if (!requires_sequential_pn(rx, fc))
                        return RX_DROP_UNUSABLE;
+
+               /* Prevent mixed key and fragment cache attacks */
+               if (entry->key_color != rx->key->color)
+                       return RX_DROP_UNUSABLE;
+
                memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
                for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
                        pn[i]++;