Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3751301pxj; Tue, 11 May 2021 11:03:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwIo1bgp8gqfH21rhYAMolCZqPg6/9v9p6HaBaTheKLSnaaHIT9+qYfaUH4/r0EI06y2BSa X-Received: by 2002:a2e:b88b:: with SMTP id r11mr3426053ljp.277.1620756234177; Tue, 11 May 2021 11:03:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620756234; cv=none; d=google.com; s=arc-20160816; b=ocOBYw/VRW3h/7eX7fYTdO9h9GgAXPf+Shc6VdXCWmLGvOIe2R/l+Iie7Z5gkIWzw+ R4egcDW9D70YJN9rvO5P0H8IOuJ0N49MpWM2OEujvFvc552iFvsvMJeDzdYigRuZoiGA O2pPtrxlIs6UYtEelULppTQN4XzhBAB77b/634ospOEbO/S+yxv3zWS/3YccuWMAJ0u7 gFZSU06/+SWvYPSOh7y/70Xu1mSdCl4fQJj40ZupqREVMRlBLdG37kevG6dpCJwgoK5d 574c6MjF9GtFLE7ga2OYWuneiJFynkc8EearxWt20XIG3LZDN3QE8IjHsfxacvSlUMfU oHlg== 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=2DWUGmME1H1yDFMmYghc/CM76SjAOWjoLeIBmiDcj3c=; b=FfVpI6qGFz1zdxyXlZwrffj8W7eJ1Kylj91mC+3n2rn3B066NbFd30sYal1TErRoXM fVI1yFzzJVBshQTBbeGkY5gSbHT1q2N1ZD/w0HuTBLZs7CH5z5TDWTPiWN8y9D+3MvIb 5tk9afEf92ySs7y6tVG0k8COvNEz3hSHaDOICsbrrCxBJYKSCpwEB6O+068S4/Ygg+ep hJqrmK9yOvPs0HM2dv8rz/Pn1CNjg0y7Qwlu3sR24+l9HTVIhcda9r7LW4CiId8UGDxj qRR4kzapSZCK/NnkTguJXvulQ14ZBNboK9/Oye6EMm83AKC/n4EHkrJsLvHDSaqoTBXO 5zqw== 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 k10si4906922ljg.323.2021.05.11.11.03.23; Tue, 11 May 2021 11:03:54 -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 S231877AbhEKSEX (ORCPT + 99 others); Tue, 11 May 2021 14:04:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231459AbhEKSEV (ORCPT ); Tue, 11 May 2021 14:04:21 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9F7CC061574; Tue, 11 May 2021 11:03:10 -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 1lgWir-007aAS-1i; Tue, 11 May 2021 20:03:09 +0200 From: Johannes Berg To: linux-wireless@vger.kernel.org Cc: Mathy Vanhoef , stable@vger.kernel.org Subject: [PATCH 02/18] mac80211: prevent mixed key and fragment cache attacks Date: Tue, 11 May 2021 20:02:43 +0200 Message-Id: <20210511200110.3f8290e59823.I622a67769ed39257327a362cfc09c812320eb979@changeid> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210511180259.159598-1-johannes@sipsolutions.net> References: <20210511180259.159598-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 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 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 8fcbaa1eedf3..874ffe7819e5 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -97,6 +97,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 56c068cb49c4..f695fc80088b 100644 --- a/net/mac80211/key.c +++ b/net/mac80211/key.c @@ -799,6 +799,7 @@ int ieee80211_key_link(struct ieee80211_key *key, struct ieee80211_sub_if_data *sdata, struct sta_info *sta) { + 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; @@ -850,6 +851,12 @@ int ieee80211_key_link(struct ieee80211_key *key, key->sdata = sdata; key->sta = sta; + /* + * 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); + increment_tailroom_need_count(sdata); ret = ieee80211_key_replace(sdata, sta, pairwise, old_key, key); diff --git a/net/mac80211/key.h b/net/mac80211/key.h index 7ad72e9b4991..1e326c89d721 100644 --- a/net/mac80211/key.h +++ b/net/mac80211/key.h @@ -128,6 +128,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 65fc674e27cc..531232b91bc4 100644 --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c @@ -2255,6 +2255,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); @@ -2292,6 +2293,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.30.2