* [PATCH rtw-next 0/3] wifi: rtw88: keep bogus CCMP PNs from stalling the connection
@ 2026-12-03 20:14 Bob Beckett
2026-12-03 20:14 ` [PATCH rtw-next 1/3] wifi: rtw88: do not trust a claimed decryption Bob Beckett
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Bob Beckett @ 2026-12-03 20:14 UTC (permalink / raw)
To: Ping-Ke Shih
Cc: Luka Gejak, Po-Hao Huang, Bitterblue Smith, matthew.leach, kernel,
linux-wireless, Bob Beckett
Steam Deck LCD units (RTL8822CE) on some 5 GHz APs lose connectivity
during large downloads. The device occasionally hands up a frame as
hardware-decrypted whose CCMP header carries a bogus PN; mac80211 adopts
it as the replay counter and drops every genuine frame after it as a
replay until the next rekey.
This series keeps such frames away from the replay check. Patch 1 is
Luka's check [1] that only trusts a claimed decryption for frames that
passed the CRC and ICV checks and have a well-formed CCMP header. Patch 2
drops hardware-decrypted frames whose PN jumps implausibly far beyond the
transmitter's sequence, which catches the remaining case: a well-formed
header with garbage in the upper PN octets. Patch 3 adds an opt-in
sw_crypto module parameter for users who would rather have mac80211
verify every MIC than rely on the device's verdict.
Tested on a Steam Deck LCD at VHT80 2SS: frames corrupted like those seen
in the field no longer stall the link, and throughput is unaffected.
See also the original report and RFC discussion [2].
[1] https://lore.kernel.org/r/20261017083313.56113-1-luka.gejak@linux.dev
[2] https://lore.kernel.org/linux-wireless/20261016191100.1781056-1-bob.beckett@collabora.com/
---
Luka Gejak (1):
wifi: rtw88: do not trust a claimed decryption
Robert Beckett (2):
wifi: rtw88: drop hardware-decrypted frames with an implausible CCMP PN
wifi: rtw88: add a module parameter to leave crypto to mac80211
drivers/net/wireless/realtek/rtw88/mac80211.c | 7 ++
drivers/net/wireless/realtek/rtw88/main.c | 5 +
drivers/net/wireless/realtek/rtw88/main.h | 31 ++++++
drivers/net/wireless/realtek/rtw88/pci.c | 2 +-
drivers/net/wireless/realtek/rtw88/rx.c | 153 +++++++++++++++++++++++++-
drivers/net/wireless/realtek/rtw88/rx.h | 4 +
drivers/net/wireless/realtek/rtw88/sdio.c | 5 +
drivers/net/wireless/realtek/rtw88/usb.c | 3 +
8 files changed, 207 insertions(+), 3 deletions(-)
---
base-commit: f496c65cc2870f2342ff37736dd31d0748588c72
change-id: 20261203-bob-rtw-next-pn-guard-5b3acbede66f
Best regards,
--
Robert Beckett <bob.beckett@collabora.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH rtw-next 1/3] wifi: rtw88: do not trust a claimed decryption
2026-12-03 20:14 [PATCH rtw-next 0/3] wifi: rtw88: keep bogus CCMP PNs from stalling the connection Bob Beckett
@ 2026-12-03 20:14 ` Bob Beckett
2026-12-03 20:14 ` [PATCH rtw-next 2/3] wifi: rtw88: drop hardware-decrypted frames with an implausible CCMP PN Robert Beckett
2026-12-03 20:14 ` [PATCH rtw-next 3/3] wifi: rtw88: add a module parameter to leave crypto to mac80211 Robert Beckett
2 siblings, 0 replies; 7+ messages in thread
From: Bob Beckett @ 2026-12-03 20:14 UTC (permalink / raw)
To: Ping-Ke Shih
Cc: Luka Gejak, Po-Hao Huang, Bitterblue Smith, matthew.leach, kernel,
linux-wireless, Bob Beckett, Robert Beckett
From: Luka Gejak <luka.gejak@linux.dev>
The RX descriptor says how the CRC and ICV checks on the device's own copy
of the frame went, not that the bytes in our buffer are that frame. For a
frame that is marked decrypted mac80211 reads the PN out of the CCMP header
and stores it as the key's last PN, rejecting only a lower PN, so a single
frame with a garbage CCMP header makes every genuine frame after it be
dropped as a replay.
Only claim decryption for a frame that passed the CRC and ICV checks, and
only for an AES frame whose CCMP or GCMP header is well formed. Such a
frame is left to mac80211, which drops it without moving the replay
counter. Mark a frame that failed the ICV with RX_FLAG_FAILED_FCS_CRC,
the way rtw89 does.
Reported-by: Bob Beckett <bob.beckett@collabora.com>
Closes: https://lore.kernel.org/all/20261016191100.1781056-1-bob.beckett@collabora.com/
Signed-off-by: Luka Gejak <luka.gejak@linux.dev>
Link: https://lore.kernel.org/r/20261017083313.56113-1-luka.gejak@linux.dev
Signed-off-by: Robert Beckett <bob.beckett@collabora.com>
---
drivers/net/wireless/realtek/rtw88/rx.c | 30 ++++++++++++++++++++++++++++--
1 file changed, 28 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw88/rx.c b/drivers/net/wireless/realtek/rtw88/rx.c
index fde21c840ac0..45ff18fa8c7b 100644
--- a/drivers/net/wireless/realtek/rtw88/rx.c
+++ b/drivers/net/wireless/realtek/rtw88/rx.c
@@ -208,7 +208,7 @@ static void rtw_rx_fill_rx_status(struct rtw_dev *rtwdev,
if (rtw_fw_feature_check(&rtwdev->fw, FW_FEATURE_SCAN_OFFLOAD) &&
test_bit(RTW_FLAG_SCANNING, rtwdev->flags))
rtw_set_rx_freq_by_pktstat(pkt_stat, rx_status);
- if (pkt_stat->crc_err)
+ if (pkt_stat->crc_err || pkt_stat->icv_err)
rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
if (pkt_stat->decrypted)
rx_status->flag |= RX_FLAG_DECRYPTED;
@@ -264,6 +264,24 @@ static void rtw_rx_fill_rx_status(struct rtw_dev *rtwdev,
}
}
+static bool rtw_rx_ccmp_hdr_valid(struct rtw_rx_pkt_stat *pkt_stat,
+ struct ieee80211_hdr *hdr)
+{
+ u32 hdr_len = ieee80211_hdrlen(hdr->frame_control);
+ u8 *iv;
+
+ if (!ieee80211_has_protected(hdr->frame_control))
+ return true;
+
+ if (pkt_stat->pkt_len < hdr_len + IEEE80211_CCMP_HDR_LEN + FCS_LEN)
+ return false;
+
+ iv = (u8 *)hdr + hdr_len;
+
+ /* reserved octet is zero, key ID octet has ExtIV set */
+ return iv[2] == 0 && (iv[3] & BIT(5));
+}
+
int rtw_rx_query_rx_desc(struct rtw_dev *rtwdev, void *rx_desc8,
struct rtw_rx_pkt_stat *pkt_stat,
struct ieee80211_rx_status *rx_status)
@@ -285,7 +303,8 @@ int rtw_rx_query_rx_desc(struct rtw_dev *rtwdev, void *rx_desc8,
pkt_stat->shift = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_SHIFT);
pkt_stat->phy_status = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_PHYST);
swdec = le32_get_bits(rx_desc->w0, RTW_RX_DESC_W0_SWDEC);
- pkt_stat->decrypted = !swdec && enc_type != RX_DESC_ENC_NONE;
+ pkt_stat->decrypted = !swdec && enc_type != RX_DESC_ENC_NONE &&
+ !pkt_stat->crc_err && !pkt_stat->icv_err;
pkt_stat->cam_id = le32_get_bits(rx_desc->w1, RTW_RX_DESC_W1_MACID);
@@ -328,6 +347,13 @@ int rtw_rx_query_rx_desc(struct rtw_dev *rtwdev, void *rx_desc8,
if (pkt_stat->phy_status)
rtwdev->chip->ops->query_phy_status(rtwdev, phy_status, pkt_stat);
+ if (pkt_stat->decrypted && enc_type == RX_DESC_ENC_AES &&
+ !rtw_rx_ccmp_hdr_valid(pkt_stat, hdr)) {
+ rtw_dbg(rtwdev, RTW_DBG_RX,
+ "AES frame without a usable CCMP header, drop the decryption flag\n");
+ pkt_stat->decrypted = false;
+ }
+
rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status);
return 0;
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH rtw-next 2/3] wifi: rtw88: drop hardware-decrypted frames with an implausible CCMP PN
2026-12-03 20:14 [PATCH rtw-next 0/3] wifi: rtw88: keep bogus CCMP PNs from stalling the connection Bob Beckett
2026-12-03 20:14 ` [PATCH rtw-next 1/3] wifi: rtw88: do not trust a claimed decryption Bob Beckett
@ 2026-12-03 20:14 ` Robert Beckett
2026-12-03 21:03 ` Luka Gejak
2026-12-03 20:14 ` [PATCH rtw-next 3/3] wifi: rtw88: add a module parameter to leave crypto to mac80211 Robert Beckett
2 siblings, 1 reply; 7+ messages in thread
From: Robert Beckett @ 2026-12-03 20:14 UTC (permalink / raw)
To: Ping-Ke Shih
Cc: Luka Gejak, Po-Hao Huang, Bitterblue Smith, matthew.leach, kernel,
linux-wireless, Robert Beckett
A Steam Deck LCD (RTL8822CE) on some 5 GHz APs goes to "limited
connectivity" during large downloads. The device occasionally delivers a
hardware-decrypted frame, with no CRC or ICV error and a well-formed CCMP
header, whose PN is far beyond the transmitter's sequence (in the field:
the low 16 bits follow the sequence, the upper 32 are garbage). mac80211
stores that PN as the key's replay counter and then drops every genuine
frame as a replay until the next rekey. The previous patch only catches
frames whose CCMP header is malformed.
The device also reports some frames whose CCMP MIC failed as decrypted
without error: with a wrong key installed, a few percent of the MPDUs from
the 3rd-7th of an A-MPDU on come up with neither the ICV error nor the
software-decryption bit set. So a frame's PN cannot be trusted just
because the hardware passed it.
A transmitter numbers all frames under a key from one PN counter shared by
every TID, so a genuine frame can only be ahead of the highest PN received
from it by the frames lost in between. Track that PN per transmitter for
the pairwise and the group key, starting from mac80211's RX sequence
counters when the key is installed, and drop a hardware-decrypted frame
that jumps more than 2^24 beyond it. A dropped PN never becomes the
reference. To cope with APs that announce a wrong group RSC, a run of
jumping PNs that keep increasing in small steps is accepted as the real
sequence; garbage PNs, and retransmissions of one, do not form such a run.
The dropped frame is just skipped on PCI, USB and SDIO, through a new
pkt_stat->drop, as an error return would abort the rest of a USB or SDIO
aggregate.
rtw89 has a similar workaround for abnormal PNs from some AP firmwares,
see commit bda294ed0ed0 ("wifi: rtw89: Drop malformed AMPDU frames with
abnormal PN").
Tested on a Steam Deck LCD by corrupting the CCMP header of received
frames the way the field's frames are: without this patch one such frame
stalls the link; with it the frame is dropped and throughput (~770 Mbit/s,
VHT80 2SS) is unaffected, including when the corrupted frame is the first
one under a new key.
Link: https://lore.kernel.org/linux-wireless/20261016191100.1781056-1-bob.beckett@collabora.com/
Signed-off-by: Robert Beckett <bob.beckett@collabora.com>
---
drivers/net/wireless/realtek/rtw88/mac80211.c | 3 +
drivers/net/wireless/realtek/rtw88/main.c | 1 +
drivers/net/wireless/realtek/rtw88/main.h | 30 +++++++
drivers/net/wireless/realtek/rtw88/pci.c | 2 +-
drivers/net/wireless/realtek/rtw88/rx.c | 123 ++++++++++++++++++++++++++
drivers/net/wireless/realtek/rtw88/rx.h | 4 +
drivers/net/wireless/realtek/rtw88/sdio.c | 5 ++
drivers/net/wireless/realtek/rtw88/usb.c | 3 +
8 files changed, 170 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wireless/realtek/rtw88/mac80211.c b/drivers/net/wireless/realtek/rtw88/mac80211.c
index b14d7fffb98f..496184ed216c 100644
--- a/drivers/net/wireless/realtek/rtw88/mac80211.c
+++ b/drivers/net/wireless/realtek/rtw88/mac80211.c
@@ -14,6 +14,7 @@
#include "debug.h"
#include "wow.h"
#include "sar.h"
+#include "rx.h"
static void rtw_ops_tx(struct ieee80211_hw *hw,
struct ieee80211_tx_control *control,
@@ -580,6 +581,8 @@ static int rtw_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
u8 hw_key_idx;
int ret = 0;
+ rtw_rx_pn_guard_set_key(rtwdev, cmd, vif, sta, key);
+
switch (key->cipher) {
case WLAN_CIPHER_SUITE_WEP40:
hw_key_type = RTW_CAM_WEP40;
diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
index 19b5c6f55daa..9f080fac55ad 100644
--- a/drivers/net/wireless/realtek/rtw88/main.c
+++ b/drivers/net/wireless/realtek/rtw88/main.c
@@ -2182,6 +2182,7 @@ int rtw_core_init(struct rtw_dev *rtwdev)
skb_queue_head_init(&rtwdev->tx_report.queue);
spin_lock_init(&rtwdev->txq_lock);
+ spin_lock_init(&rtwdev->rx_pn_seed_lock);
spin_lock_init(&rtwdev->tx_report.q_lock);
spin_lock_init(&rtwdev->hiq_lock);
rtwdev->hiq_budget = RTW_TX_HIQ_BUDGET_MAX;
diff --git a/drivers/net/wireless/realtek/rtw88/main.h b/drivers/net/wireless/realtek/rtw88/main.h
index 1401eff4397c..f05bed08f913 100644
--- a/drivers/net/wireless/realtek/rtw88/main.h
+++ b/drivers/net/wireless/realtek/rtw88/main.h
@@ -639,6 +639,30 @@ struct rtw_tx_pkt_info {
bool bt_null;
};
+enum rtw_rx_pn_key {
+ RTW_RX_PN_PAIRWISE,
+ RTW_RX_PN_GROUP,
+
+ RTW_RX_PN_KEYS,
+};
+
+/* highest CCMP PN received per transmitter and key, see rtw_rx_pn_guard() */
+struct rtw_rx_pn_guard {
+ u64 pn[RTW_RX_PN_KEYS];
+ u8 ta[RTW_RX_PN_KEYS][ETH_ALEN];
+ bool valid[RTW_RX_PN_KEYS];
+ u64 run_pn[RTW_RX_PN_KEYS];
+ u8 run_len[RTW_RX_PN_KEYS];
+ u32 gen;
+};
+
+/* starting point for rtw_rx_pn_guard() when a CCMP key is installed */
+struct rtw_rx_pn_seed {
+ u64 pn;
+ u8 ta[ETH_ALEN];
+ bool valid;
+};
+
struct rtw_rx_pkt_stat {
bool phy_status;
bool icv_err;
@@ -646,6 +670,7 @@ struct rtw_rx_pkt_stat {
bool decrypted;
bool is_c2h;
bool channel_invalid;
+ bool drop; /* rejected by the PN guard, don't pass it on */
s32 signal_power;
u16 pkt_len;
@@ -2074,6 +2099,11 @@ struct rtw_dev {
struct rtw_fw_state fw;
struct rtw_efuse efuse;
struct rtw_sec_desc sec;
+ struct rtw_rx_pn_guard rx_pn_guard;
+ atomic_t rx_pn_guard_gen;
+ struct rtw_rx_pn_seed rx_pn_seed[RTW_RX_PN_KEYS];
+ /* protects rx_pn_seed between set_key and the RX path */
+ spinlock_t rx_pn_seed_lock;
struct rtw_traffic_stats stats;
struct rtw_regd regd;
struct rtw_bf_info bf_info;
diff --git a/drivers/net/wireless/realtek/rtw88/pci.c b/drivers/net/wireless/realtek/rtw88/pci.c
index d612a6b3ac5f..9e7c8080770b 100644
--- a/drivers/net/wireless/realtek/rtw88/pci.c
+++ b/drivers/net/wireless/realtek/rtw88/pci.c
@@ -1091,7 +1091,7 @@ static u32 rtw_pci_rx_napi(struct rtw_dev *rtwdev, struct rtw_pci *rtwpci,
rx_desc = skb->data;
ret = rtw_rx_query_rx_desc(rtwdev, rx_desc,
&pkt_stat, &rx_status);
- if (ret)
+ if (ret || pkt_stat.drop)
goto next_rp;
/* offset from rx_desc to payload */
diff --git a/drivers/net/wireless/realtek/rtw88/rx.c b/drivers/net/wireless/realtek/rtw88/rx.c
index 45ff18fa8c7b..7fbb110ca1ec 100644
--- a/drivers/net/wireless/realtek/rtw88/rx.c
+++ b/drivers/net/wireless/realtek/rtw88/rx.c
@@ -2,6 +2,8 @@
/* Copyright(c) 2018-2019 Realtek Corporation
*/
+#include <linux/unaligned.h>
+
#include "main.h"
#include "mac.h"
#include "rx.h"
@@ -282,6 +284,124 @@ static bool rtw_rx_ccmp_hdr_valid(struct rtw_rx_pkt_stat *pkt_stat,
return iv[2] == 0 && (iv[3] & BIT(5));
}
+static u64 rtw_rx_ccmp_pn(const u8 *iv)
+{
+ /* PN0-PN1, then the reserved and key ID octets, then PN2-PN5 */
+ return get_unaligned_le16(iv) | (u64)get_unaligned_le32(iv + 4) << 16;
+}
+
+#define RTW_RX_PN_GUARD_JUMP BIT_ULL(24)
+#define RTW_RX_PN_GUARD_RUN 8
+#define RTW_RX_PN_GUARD_STEP BIT_ULL(16)
+
+void rtw_rx_pn_guard_set_key(struct rtw_dev *rtwdev, enum set_key_cmd cmd,
+ struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta,
+ struct ieee80211_key_conf *key)
+{
+ int idx = key->flags & IEEE80211_KEY_FLAG_PAIRWISE ?
+ RTW_RX_PN_PAIRWISE : RTW_RX_PN_GROUP;
+ struct rtw_rx_pn_seed *seed = &rtwdev->rx_pn_seed[idx];
+ struct ieee80211_key_seq seq;
+ u64 pn = 0;
+ int tid;
+
+ if (key->cipher != WLAN_CIPHER_SUITE_CCMP)
+ return;
+
+ if (cmd == SET_KEY) {
+ for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
+ ieee80211_get_key_rx_seq(key, tid, &seq);
+ pn = max(pn, get_unaligned_be48(seq.ccmp.pn));
+ }
+ }
+
+ guard(spinlock_bh)(&rtwdev->rx_pn_seed_lock);
+ if (cmd == SET_KEY) {
+ seed->pn = pn;
+ ether_addr_copy(seed->ta, sta ? sta->addr : vif->bss_conf.bssid);
+ }
+ seed->valid = cmd == SET_KEY;
+ atomic_inc(&rtwdev->rx_pn_guard_gen);
+}
+
+static void rtw_rx_pn_guard_load(struct rtw_dev *rtwdev,
+ struct rtw_rx_pn_guard *pg)
+{
+ int i;
+
+ guard(spinlock_bh)(&rtwdev->rx_pn_seed_lock);
+ for (i = 0; i < RTW_RX_PN_KEYS; i++) {
+ pg->pn[i] = rtwdev->rx_pn_seed[i].pn;
+ ether_addr_copy(pg->ta[i], rtwdev->rx_pn_seed[i].ta);
+ pg->valid[i] = rtwdev->rx_pn_seed[i].valid;
+ pg->run_len[i] = 0;
+ }
+}
+
+/*
+ * A run of jumping PNs that keep increasing in small steps is the
+ * transmitter's real sequence, e.g. after an AP announced a wrong group RSC.
+ * Garbage PNs do not form one, nor do retransmissions, which repeat a PN.
+ */
+static bool rtw_rx_pn_guard_run(struct rtw_rx_pn_guard *pg, int idx, u64 pn)
+{
+ if (pg->run_len[idx] && pn > pg->run_pn[idx] &&
+ pn - pg->run_pn[idx] <= RTW_RX_PN_GUARD_STEP) {
+ pg->run_pn[idx] = pn;
+ if (++pg->run_len[idx] < RTW_RX_PN_GUARD_RUN)
+ return false;
+ pg->run_len[idx] = 0;
+ return true;
+ }
+
+ if (!pg->run_len[idx] || pn != pg->run_pn[idx]) {
+ pg->run_pn[idx] = pn;
+ pg->run_len[idx] = 1;
+ }
+ return false;
+}
+
+static void rtw_rx_pn_guard(struct rtw_dev *rtwdev,
+ struct rtw_rx_pkt_stat *pkt_stat,
+ struct ieee80211_hdr *hdr)
+{
+ struct rtw_rx_pn_guard *pg = &rtwdev->rx_pn_guard;
+ u32 gen = atomic_read(&rtwdev->rx_pn_guard_gen);
+ int idx = is_multicast_ether_addr(hdr->addr1) ?
+ RTW_RX_PN_GROUP : RTW_RX_PN_PAIRWISE;
+ u64 pn, max;
+
+ if (pg->gen != gen) {
+ pg->gen = gen;
+ rtw_rx_pn_guard_load(rtwdev, pg);
+ }
+
+ if (!ieee80211_is_data(hdr->frame_control) ||
+ !ieee80211_has_protected(hdr->frame_control))
+ return;
+
+ if (!pg->valid[idx] || !ether_addr_equal(pg->ta[idx], hdr->addr2))
+ return;
+
+ /* rtw_rx_ccmp_hdr_valid() checked that the CCMP header is there */
+ pn = rtw_rx_ccmp_pn((u8 *)hdr + ieee80211_hdrlen(hdr->frame_control));
+ max = pg->pn[idx];
+ if (pn <= max)
+ return;
+
+ if (pn - max > RTW_RX_PN_GUARD_JUMP &&
+ !rtw_rx_pn_guard_run(pg, idx, pn)) {
+ pkt_stat->drop = true;
+ dev_warn_ratelimited(rtwdev->dev,
+ "dropping frame from %pM with CCMP PN 0x%012llx, expected about 0x%012llx\n",
+ hdr->addr2, pn, max);
+ return;
+ }
+
+ pg->pn[idx] = pn;
+}
+
int rtw_rx_query_rx_desc(struct rtw_dev *rtwdev, void *rx_desc8,
struct rtw_rx_pkt_stat *pkt_stat,
struct ieee80211_rx_status *rx_status)
@@ -354,6 +474,9 @@ int rtw_rx_query_rx_desc(struct rtw_dev *rtwdev, void *rx_desc8,
pkt_stat->decrypted = false;
}
+ if (pkt_stat->decrypted && enc_type == RX_DESC_ENC_AES)
+ rtw_rx_pn_guard(rtwdev, pkt_stat, hdr);
+
rtw_rx_fill_rx_status(rtwdev, pkt_stat, hdr, rx_status);
return 0;
diff --git a/drivers/net/wireless/realtek/rtw88/rx.h b/drivers/net/wireless/realtek/rtw88/rx.h
index 74359f641c76..cb574cf6a23b 100644
--- a/drivers/net/wireless/realtek/rtw88/rx.h
+++ b/drivers/net/wireless/realtek/rtw88/rx.h
@@ -48,6 +48,10 @@ void rtw_rx_stats(struct rtw_dev *rtwdev, struct ieee80211_vif *vif,
int rtw_rx_query_rx_desc(struct rtw_dev *rtwdev, void *rx_desc8,
struct rtw_rx_pkt_stat *pkt_stat,
struct ieee80211_rx_status *rx_status);
+void rtw_rx_pn_guard_set_key(struct rtw_dev *rtwdev, enum set_key_cmd cmd,
+ struct ieee80211_vif *vif,
+ struct ieee80211_sta *sta,
+ struct ieee80211_key_conf *key);
void rtw_update_rx_freq_from_ie(struct rtw_dev *rtwdev, struct sk_buff *skb,
struct ieee80211_rx_status *rx_status,
struct rtw_rx_pkt_stat *pkt_stat);
diff --git a/drivers/net/wireless/realtek/rtw88/sdio.c b/drivers/net/wireless/realtek/rtw88/sdio.c
index 82d7de41b172..f614c6544bfb 100644
--- a/drivers/net/wireless/realtek/rtw88/sdio.c
+++ b/drivers/net/wireless/realtek/rtw88/sdio.c
@@ -1387,6 +1387,11 @@ static void rtw_sdio_rx_skb(struct rtw_dev *rtwdev, struct sk_buff *skb,
u32 pkt_offset, struct rtw_rx_pkt_stat *pkt_stat,
struct ieee80211_rx_status *rx_status)
{
+ if (pkt_stat->drop) {
+ dev_kfree_skb_any(skb);
+ return;
+ }
+
if (pkt_stat->is_c2h) {
skb_put(skb, pkt_stat->pkt_len + pkt_offset);
rtw_fw_c2h_cmd_rx_irqsafe(rtwdev, pkt_offset, skb);
diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c
index ef2a0686b7cf..00334530040c 100644
--- a/drivers/net/wireless/realtek/rtw88/usb.c
+++ b/drivers/net/wireless/realtek/rtw88/usb.c
@@ -725,6 +725,9 @@ static void rtw_usb_rx_handler(struct work_struct *work)
break;
}
+ if (pkt_stat.drop)
+ goto skip_packet;
+
skb = alloc_skb(skb_len, GFP_ATOMIC);
if (!skb) {
rtw_dbg(rtwdev, RTW_DBG_USB,
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH rtw-next 3/3] wifi: rtw88: add a module parameter to leave crypto to mac80211
2026-12-03 20:14 [PATCH rtw-next 0/3] wifi: rtw88: keep bogus CCMP PNs from stalling the connection Bob Beckett
2026-12-03 20:14 ` [PATCH rtw-next 1/3] wifi: rtw88: do not trust a claimed decryption Bob Beckett
2026-12-03 20:14 ` [PATCH rtw-next 2/3] wifi: rtw88: drop hardware-decrypted frames with an implausible CCMP PN Robert Beckett
@ 2026-12-03 20:14 ` Robert Beckett
2026-12-03 21:03 ` Luka Gejak
2026-12-04 7:42 ` Ping-Ke Shih
2 siblings, 2 replies; 7+ messages in thread
From: Robert Beckett @ 2026-12-03 20:14 UTC (permalink / raw)
To: Ping-Ke Shih
Cc: Luka Gejak, Po-Hao Huang, Bitterblue Smith, matthew.leach, kernel,
linux-wireless, Robert Beckett
rtw88 offloads all CCMP decryption and trusts the device's verdict.
The RTL8822CE has been seen to report frames whose MIC failed as decrypted
without error (non-first MPDUs of long A-MPDUs, a few percent of them when
the MIC fails), and to deliver frames with a corrupted CCMP header as
hardware-decrypted. The previous patches keep such frames from poisoning
the replay counter, but a frame with a plausible PN and a corrupted
payload would still be passed up as valid.
Add rtw88_core.sw_crypto. With it set, rtw88 refuses new keys, so mac80211
does all encryption and decryption in software and checks every frame's
MIC itself, independent of the device's verdict. Like iwlwifi's swcrypto
and ath9k's nohwcrypt it is off by default; it applies to keys installed
after it is changed, i.e. from the next connection.
On a Steam Deck LCD (RTL8822CE, VHT80 2SS) throughput was unchanged
(about 600-750 Mbit/s either way); CPU use rose by about 4 points of the
8 threads' total (~0.3 of one core, in softirq) at ~600 Mbit/s.
Signed-off-by: Robert Beckett <bob.beckett@collabora.com>
---
drivers/net/wireless/realtek/rtw88/mac80211.c | 4 ++++
drivers/net/wireless/realtek/rtw88/main.c | 4 ++++
drivers/net/wireless/realtek/rtw88/main.h | 1 +
3 files changed, 9 insertions(+)
diff --git a/drivers/net/wireless/realtek/rtw88/mac80211.c b/drivers/net/wireless/realtek/rtw88/mac80211.c
index 496184ed216c..cd3377400f39 100644
--- a/drivers/net/wireless/realtek/rtw88/mac80211.c
+++ b/drivers/net/wireless/realtek/rtw88/mac80211.c
@@ -583,6 +583,10 @@ static int rtw_ops_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
rtw_rx_pn_guard_set_key(rtwdev, cmd, vif, sta, key);
+ /* keys installed while sw_crypto was set are never in the CAM */
+ if (cmd == SET_KEY && READ_ONCE(rtw_sw_crypto))
+ return -EOPNOTSUPP;
+
switch (key->cipher) {
case WLAN_CIPHER_SUITE_WEP40:
hw_key_type = RTW_CAM_WEP40;
diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
index 9f080fac55ad..05c7e2df5a84 100644
--- a/drivers/net/wireless/realtek/rtw88/main.c
+++ b/drivers/net/wireless/realtek/rtw88/main.c
@@ -34,14 +34,18 @@ EXPORT_SYMBOL(rtw_debug_mask);
* there is a tough reason to maintain rtw_edcca_enabled by device.
*/
bool rtw_edcca_enabled = true;
+bool rtw_sw_crypto;
module_param_named(disable_lps_deep, rtw_disable_lps_deep_mode, bool, 0644);
module_param_named(support_bf, rtw_bf_support, bool, 0644);
module_param_named(debug_mask, rtw_debug_mask, uint, 0644);
+module_param_named(sw_crypto, rtw_sw_crypto, bool, 0644);
MODULE_PARM_DESC(disable_lps_deep, "Set Y to disable Deep PS");
MODULE_PARM_DESC(support_bf, "Set Y to enable beamformee support");
MODULE_PARM_DESC(debug_mask, "Debugging mask");
+MODULE_PARM_DESC(sw_crypto,
+ "Set Y to leave encryption and decryption to mac80211 (applies to keys installed afterwards)");
static struct ieee80211_channel rtw_channeltable_2g[] = {
{.center_freq = 2412, .hw_value = 1,},
diff --git a/drivers/net/wireless/realtek/rtw88/main.h b/drivers/net/wireless/realtek/rtw88/main.h
index f05bed08f913..5f86a8dc88c8 100644
--- a/drivers/net/wireless/realtek/rtw88/main.h
+++ b/drivers/net/wireless/realtek/rtw88/main.h
@@ -44,6 +44,7 @@ extern bool rtw_bf_support;
extern bool rtw_disable_lps_deep_mode;
extern unsigned int rtw_debug_mask;
extern bool rtw_edcca_enabled;
+extern bool rtw_sw_crypto;
extern const struct ieee80211_ops rtw_ops;
#define RTW_MAX_CHANNEL_NUM_2G 14
--
2.55.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH rtw-next 2/3] wifi: rtw88: drop hardware-decrypted frames with an implausible CCMP PN
2026-12-03 20:14 ` [PATCH rtw-next 2/3] wifi: rtw88: drop hardware-decrypted frames with an implausible CCMP PN Robert Beckett
@ 2026-12-03 21:03 ` Luka Gejak
0 siblings, 0 replies; 7+ messages in thread
From: Luka Gejak @ 2026-12-03 21:03 UTC (permalink / raw)
To: Robert Beckett
Cc: Ping-Ke Shih, Luka Gejak, Po-Hao Huang, Bitterblue Smith,
matthew.leach, kernel, linux-wireless
Hi Bob,
Thanks for putting this together. Two comments below.
On December 3, 2026 8:14:09 PM GMT+00:00, Robert Beckett
<bob.beckett@collabora.com> wrote:
[ ... ]
> diff --git a/drivers/net/wireless/realtek/rtw88/rx.c b/drivers/net/wireless/realtek/rtw88/rx.c
> index 45ff18fa8c7b..7fbb110ca1ec 100644
> --- a/drivers/net/wireless/realtek/rtw88/rx.c
> +++ b/drivers/net/wireless/realtek/rtw88/rx.c
> @@ -282,6 +284,124 @@ static bool rtw_rx_ccmp_hdr_valid(struct rtw_rx_pkt_stat *pkt_stat,
> +void rtw_rx_pn_guard_set_key(struct rtw_dev *rtwdev, enum set_key_cmd cmd,
> + struct ieee80211_vif *vif,
> + struct ieee80211_sta *sta,
> + struct ieee80211_key_conf *key)
> +{
> + int idx = key->flags & IEEE80211_KEY_FLAG_PAIRWISE ?
> + RTW_RX_PN_PAIRWISE : RTW_RX_PN_GROUP;
> + struct rtw_rx_pn_seed *seed = &rtwdev->rx_pn_seed[idx];
[ ... ]
> + if (cmd == SET_KEY) {
> + seed->pn = pn;
> + ether_addr_copy(seed->ta, sta ? sta->addr : vif->bss_conf.bssid);
> + }
> + seed->valid = cmd == SET_KEY;
> + atomic_inc(&rtwdev->rx_pn_guard_gen);
I think this ends up tracking only the most recent client on an rtw88
AP. When a second client gets its key, its address goes into the
pairwise slot, so frames from the first client start skipping the
guard even though its key is still in the CAM.
There can also be two GTKs in the CAM during a rekey, and both would
be checked against the same PN. Could we keep the guard state with
each key?
[ ... ]
> + for (i = 0; i < RTW_RX_PN_KEYS; i++) {
> + pg->pn[i] = rtwdev->rx_pn_seed[i].pn;
> + ether_addr_copy(pg->ta[i], rtwdev->rx_pn_seed[i].ta);
> + pg->valid[i] = rtwdev->rx_pn_seed[i].valid;
> + pg->run_len[i] = 0;
> + }
So if I read it right, a GTK rekey during a long download also takes
the PTK guard back to its starting PN. If the unicast PN has already
moved more than 2^24 past that point, the next valid frames look like
jumps, so the guard can drop the first seven even if they all arrive
in order.
Could we reload just the state for the key that changed?
Best regards,
Luka Gejak
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH rtw-next 3/3] wifi: rtw88: add a module parameter to leave crypto to mac80211
2026-12-03 20:14 ` [PATCH rtw-next 3/3] wifi: rtw88: add a module parameter to leave crypto to mac80211 Robert Beckett
@ 2026-12-03 21:03 ` Luka Gejak
2026-12-04 7:42 ` Ping-Ke Shih
1 sibling, 0 replies; 7+ messages in thread
From: Luka Gejak @ 2026-12-03 21:03 UTC (permalink / raw)
To: Robert Beckett
Cc: Ping-Ke Shih, Luka Gejak, Po-Hao Huang, Bitterblue Smith,
matthew.leach, kernel, linux-wireless
Hi Bob,
One question about sw_crypto.
On December 3, 2026 8:14:10 PM GMT+00:00, Robert Beckett
<bob.beckett@collabora.com> wrote:
[ ... ]
> diff --git a/drivers/net/wireless/realtek/rtw88/main.c b/drivers/net/wireless/realtek/rtw88/main.c
> index 9f080fac55ad..05c7e2df5a84 100644
> --- a/drivers/net/wireless/realtek/rtw88/main.c
> +++ b/drivers/net/wireless/realtek/rtw88/main.c
> @@ -34,14 +34,18 @@ EXPORT_SYMBOL(rtw_debug_mask);
> +module_param_named(sw_crypto, rtw_sw_crypto, bool, 0644);
If I turn this on during a download, a GTK rekey can move multicast
to software while the download still uses hardware crypto. Turning
it off again can leave keys in software, since ieee80211_key_replace()
skips the upload when the old key at that index was in software.
Could we make sw_crypto read only after load, like swcrypto in
iwlwifi and nohwcrypt in ath9k?
Best regards,
Luka Gejak
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [PATCH rtw-next 3/3] wifi: rtw88: add a module parameter to leave crypto to mac80211
2026-12-03 20:14 ` [PATCH rtw-next 3/3] wifi: rtw88: add a module parameter to leave crypto to mac80211 Robert Beckett
2026-12-03 21:03 ` Luka Gejak
@ 2026-12-04 7:42 ` Ping-Ke Shih
1 sibling, 0 replies; 7+ messages in thread
From: Ping-Ke Shih @ 2026-12-04 7:42 UTC (permalink / raw)
To: Robert Beckett
Cc: Luka Gejak, Bernie Huang, Bitterblue Smith,
matthew.leach@collabora.com, kernel@collabora.com,
linux-wireless@vger.kernel.org
Robert Beckett <bob.beckett@collabora.com> wrote:
> +module_param_named(sw_crypto, rtw_sw_crypto, bool, 0644);
The module parameter is deprecated and discouraged API. Please avoid this.
For debug purpose, adding a debugfs entry might be a possible way.
Ping-Ke
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-04 7:42 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 20:14 [PATCH rtw-next 0/3] wifi: rtw88: keep bogus CCMP PNs from stalling the connection Bob Beckett
2026-12-03 20:14 ` [PATCH rtw-next 1/3] wifi: rtw88: do not trust a claimed decryption Bob Beckett
2026-12-03 20:14 ` [PATCH rtw-next 2/3] wifi: rtw88: drop hardware-decrypted frames with an implausible CCMP PN Robert Beckett
2026-12-03 21:03 ` Luka Gejak
2026-12-03 20:14 ` [PATCH rtw-next 3/3] wifi: rtw88: add a module parameter to leave crypto to mac80211 Robert Beckett
2026-12-03 21:03 ` Luka Gejak
2026-12-04 7:42 ` Ping-Ke Shih
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox