Linux wireless drivers development
 help / color / mirror / Atom feed
From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH mt76-next 13/19] wifi: mt76: check the RX PN of CCMP-256, GCMP and GCMP-256 keys
Date: Tue, 17 Nov 2026 19:01:28 +0100	[thread overview]
Message-ID: <20261117180134.2940930-13-nbd@nbd.name> (raw)
In-Reply-To: <20261117180134.2940930-1-nbd@nbd.name>

mt76_wcid_key_link_setup() enables the RX PN check for CCMP keys only.
mac80211 does not check the PN either, because the IV is stripped, so
on mt7996, whose hardware does not check it, replayed frames of the
other AES ciphers reach the stack.

Check the PN for all four ciphers. Keep the PN state of a wcid when an
IGTK or BIGTK is installed on it, since these keys do not use it.

Fixes: 04b8e65922f6 ("mt76: add mac80211 driver for MT7615 PCIe-based chipsets")
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 13 +++++--
 drivers/net/wireless/mediatek/mt76/mt76.h     | 34 ++++++++++++++++++-
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c
index b1789be134d6..6b496dfda5cc 100644
--- a/drivers/net/wireless/mediatek/mt76/mac80211.c
+++ b/drivers/net/wireless/mediatek/mt76/mac80211.c
@@ -1279,21 +1279,28 @@ void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,
 			 struct ieee80211_key_conf *key)
 {
 	struct ieee80211_key_seq seq;
+	u8 *pn;
 	int i;
 
 	mt76_wcid_key_link_setup(wcid, key);
-	if (!wcid->rx_check_pn)
+	if (!key || !mt76_key_has_rx_pn(key))
 		return;
 
+	if (key->cipher == WLAN_CIPHER_SUITE_GCMP ||
+	    key->cipher == WLAN_CIPHER_SUITE_GCMP_256)
+		pn = seq.gcmp.pn;
+	else
+		pn = seq.ccmp.pn;
+
 	/* data frame */
 	for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
 		ieee80211_get_key_rx_seq(key, i, &seq);
-		memcpy(wcid->rx_key_pn[i], seq.ccmp.pn, sizeof(seq.ccmp.pn));
+		memcpy(wcid->rx_key_pn[i], pn, sizeof(wcid->rx_key_pn[i]));
 	}
 
 	/* robust management frame */
 	ieee80211_get_key_rx_seq(key, -1, &seq);
-	memcpy(wcid->rx_key_pn[i], seq.ccmp.pn, sizeof(seq.ccmp.pn));
+	memcpy(wcid->rx_key_pn[i], pn, sizeof(wcid->rx_key_pn[i]));
 
 }
 EXPORT_SYMBOL(mt76_wcid_key_setup);
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 0b16567920fa..7a2a6afc3c21 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -1590,11 +1590,43 @@ int mt76_rx_aggr_start(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid,
 		       u16 ssn, u16 size);
 void mt76_rx_aggr_stop(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tid);
 
+static inline bool
+mt76_key_has_rx_pn(struct ieee80211_key_conf *key)
+{
+	switch (key->cipher) {
+	case WLAN_CIPHER_SUITE_CCMP:
+	case WLAN_CIPHER_SUITE_CCMP_256:
+	case WLAN_CIPHER_SUITE_GCMP:
+	case WLAN_CIPHER_SUITE_GCMP_256:
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool
+mt76_key_is_bip(struct ieee80211_key_conf *key)
+{
+	switch (key->cipher) {
+	case WLAN_CIPHER_SUITE_AES_CMAC:
+	case WLAN_CIPHER_SUITE_BIP_CMAC_256:
+	case WLAN_CIPHER_SUITE_BIP_GMAC_128:
+	case WLAN_CIPHER_SUITE_BIP_GMAC_256:
+		return true;
+	default:
+		return false;
+	}
+}
+
 static inline void
 mt76_wcid_key_link_setup(struct mt76_wcid *wcid,
 			 struct ieee80211_key_conf *key)
 {
-	wcid->rx_check_pn = key && key->cipher == WLAN_CIPHER_SUITE_CCMP;
+	/* an IGTK or BIGTK shares the wcid of the GTK */
+	if (key && mt76_key_is_bip(key))
+		return;
+
+	wcid->rx_check_pn = key && mt76_key_has_rx_pn(key);
 }
 
 void mt76_wcid_key_setup(struct mt76_dev *dev, struct mt76_wcid *wcid,
-- 
2.47.3


  parent reply	other threads:[~2026-11-17 18:01 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 18:01 [PATCH mt76-next 01/19] wifi: mt76: don't pin undrainable PS stations in the tx scheduler Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 02/19] wifi: mt76: mt7996: return a negative error for a firmware status Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 03/19] wifi: mt76: mt7996: use the default timeout for STA_REC and BSS_INFO Felix Fietkau
2026-11-18  8:22   ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 04/19] wifi: mt76: mt7915: " Felix Fietkau
2026-11-18  8:23   ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 05/19] wifi: mt76: delete only the RX NAPIs that were added Felix Fietkau
2026-11-18  8:32   ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 06/19] wifi: mt76: mt7996: report radar on the channel context of its band Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 07/19] wifi: mt76: mt7996: stop WED before the DMA reset of a full reset Felix Fietkau
2026-11-18  8:38   ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 08/19] wifi: mt76: skip the radiotap TLVs in mt76_skb_get_hdr() Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 09/19] wifi: mt76: find the first A-MSDU subframe behind the radiotap data Felix Fietkau
2026-11-18  8:43   ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 10/19] wifi: mt76: mark all but the last subframe of an A-MSDU chain Felix Fietkau
2026-11-18  8:47   ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 11/19] wifi: mt76: mt7996: set qos_ctl of a frame that hardware reordered Felix Fietkau
2026-11-18  8:50   ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 12/19] wifi: mt76: check the PN of a BA session frame at its release Felix Fietkau
2026-11-18  8:55   ` Lorenzo Bianconi
2026-11-17 18:01 ` Felix Fietkau [this message]
2026-11-17 18:01 ` [PATCH mt76-next 14/19] wifi: mt76: connac: return a negative error for a firmware status Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 15/19] wifi: mt76: guard the tx_list of every phy with one lock Felix Fietkau
2026-11-18  8:52   ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 16/19] wifi: mt76: keep an unpublished wcid off the TX and poll lists Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 17/19] wifi: mt76: mt7925: do not take iflist_mtx under the mutex Felix Fietkau
2026-11-17 18:01 ` [PATCH mt76-next 18/19] wifi: mt76: mt7925: take each polled link under sta_poll_lock Felix Fietkau
2026-11-18  8:58   ` Lorenzo Bianconi
2026-11-17 18:01 ` [PATCH mt76-next 19/19] wifi: mt76: mt7615: take each polled station " Felix Fietkau
2026-11-18  8:57   ` Lorenzo Bianconi
2026-11-18  8:20 ` [PATCH mt76-next 01/19] wifi: mt76: don't pin undrainable PS stations in the tx scheduler Lorenzo Bianconi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261117180134.2940930-13-nbd@nbd.name \
    --to=nbd@nbd.name \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox