Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2883464pxj; Mon, 31 May 2021 13:35:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE2zwGlVhtLeGoGCYzyQQ0lJVNe3Utdmf4uRG1ow0JcoCoJehJDEjOY8WkfF2p6jJ9i27I X-Received: by 2002:a17:906:6bd8:: with SMTP id t24mr17736584ejs.501.1622493316078; Mon, 31 May 2021 13:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622493316; cv=none; d=google.com; s=arc-20160816; b=kEsmFBJUDgdZornxk/a/G2LlINoxKr+6Jjgz5+qH+UaWHC2HWuFvsdCIKJU7nlFZea 1Rd+V/y3iVK6CtIckqtWj85ud/jSyfYfmGNPg4y3008orqnFr1OxGTnGLzHlc1d0J11k beqj7n+6Xuc2VQUe55EMpf2yaEnGnJjX3cumRwKxJAlTA0n2Uhd2RqllHwyNY8hJSTmM Sm8345F6U0ew4ctgCGaglqSQKGwgA61RoTCanqrPA0QEGcr7UukUgjXvECONFP+ccgub nWjvYImMcbAFTcremKk+pjmXdL+EHYVdevHfs3gjvodM9FXMVEyEpDJoc4Zk2YhQMLhk mAaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=5rGG2ezDvtYkWeIK0ulz+o9bUC2P8ftz1HhtKnBWEw4=; b=Cu4qvZHA1DTm++72wsB62glH74tJTWu6LeMH8o1djRwiPHwjQ81yaQE4RPhbaObr1k npXnQavC9/fXN79jhJeQ5P8pQfZl3zqOZSTUNk6B2e/gQ6oOj+J2FBk4eqPxAaZMedkw W0EpfkBaDGu3w7eoGnO6oMDCbHWGG4OajvihCEhnQgOEUv8l3nf7D5F50ztCTMQSmgEu AQ6lXGWqOmO7Y2awNFib6kREQAZC/G5Zu17I8IVfbao5XFRLlP7VcIZY8odl/4WpVaK2 WTxC3IOAgymPm+0zj+MD7CYuZIiLN1jo/esxZZL8QTh8gLelbseA/KH1hN6mRnrFCzWV hr/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a11si14369869edf.280.2021.05.31.13.34.53; Mon, 31 May 2021 13:35:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232394AbhEaUde (ORCPT + 99 others); Mon, 31 May 2021 16:33:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232384AbhEaUdU (ORCPT ); Mon, 31 May 2021 16:33:20 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C2CCC061756; Mon, 31 May 2021 13:31:40 -0700 (PDT) Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2) (envelope-from ) id 1lnoZW-000FBv-PB; Mon, 31 May 2021 22:31:38 +0200 From: Johannes Berg To: linux-wireless@vger.kernel.org Cc: stable@vger.kernel.org, Mathy Vanhoef Subject: [PATCH v4.14 02/10] mac80211: prevent mixed key and fragment cache attacks Date: Mon, 31 May 2021 22:31:27 +0200 Message-Id: <20210531203135.180427-3-johannes@sipsolutions.net> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531203135.180427-1-johannes@sipsolutions.net> References: <20210531203135.180427-1-johannes@sipsolutions.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Mathy Vanhoef 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 Link: https://lore.kernel.org/r/20210511200110.3f8290e59823.I622a67769ed39257327a362cfc09c812320eb979@changeid Signed-off-by: Johannes Berg --- net/mac80211/ieee80211_i.h | 1 + net/mac80211/key.c | 7 +++++++ net/mac80211/key.h | 2 ++ net/mac80211/rx.c | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 651705565dfb..74186c2d9e6e 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -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; }; diff --git a/net/mac80211/key.c b/net/mac80211/key.c index fa10c6142244..d122031e389a 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c @@ -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) diff --git a/net/mac80211/key.h b/net/mac80211/key.h index ebdb80b85dc3..d8e187bcb751 100644 --- a/net/mac80211/key.h +++ b/net/mac80211/key.h @@ -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 diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c index 9b313c2f7d49..8c126854aa06 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -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]++; -- 2.31.1