wifi: rtw89: monitor mode and raw frame injection fixes
v6 cover wifi: rtw89: monitor mode and raw frame injection fixes
This series fixes a NULL vif dereference and a negative radiotap rate index bug on the TX path, restores the operating channel after monitor down/up on non-chanctx devices, and fixes control-frame seq_ctrl reads, sequence preservation, NO_ACK, and retry limits for raw 802.11 frame injection.
Tested on RTL8852AE (10ec:8852, firmware 0.13.36.2) across 2.4 GHz and 5 GHz.
Changes in v6:
- Focus the series strictly on the standalone monitor interface case (plus the concurrent NULL-vif crash guard in patch 1), dropping former patches 3, 4, 5, 6, and 8 (RX filter changes, RCU pure_monitor_mode_vif, AP self role, NL80211_FEATURE_ACTIVE_MONITOR, and host TX hook skips).
- Rewrite all commit messages concisely without function-level flow.
- Patch 1: use vif_to_rtwvif_safe().
- Patch 2: clamp negative rate indices to 0 with max_t().
- Patch 3 (was 10): move before injection changes, add rtwdev->support_chanctx, and reuse IEEE80211_CONF_CHANGE_CHANNEL in rtw89_ops_config().
- Patch 4 (was 7): keep control frames on the AC queue and only set seq = 0 for control frames.
- Patch 5 (was 9): simplify ASSIGN_SEQ handling and drop dead RTS/CTS, rate-index clamping, upd_wlan_hdr, and pci.c counter changes.
- Rebase onto latest rtw-next and wrap all lines to <= 80 columns.
Changes in v5:
- Split the NULL vif fix and negative rate index fix out as standalone patches 1-2 with Fixes: and Cc: stable tags.
- Split monitor injection into focused patches.
- Honor ASSIGN_SEQ, retries, and NO_ACK for injected frames.
- Restore channel on leaving idle for non-chanctx devices.
Changes in v3:
- Split into a patch series and use driver abstractions instead of direct register writes.
v5: https://lore.kernel.org/linux-wireless/[email protected]/
v3: https://lore.kernel.org/linux-wireless/[email protected]/
v2: https://lore.kernel.org/linux-wireless/[email protected]/
v1 (RFC): https://lore.kernel.org/linux-wireless/[email protected]/
Enver Ikromov (5):
wifi: rtw89: avoid NULL vif dereference in rtw89_ops_tx()
wifi: rtw89: handle negative rate index for injected frames
wifi: rtw89: restore channel when leaving idle on non-chanctx devices
wifi: rtw89: avoid reading seq_ctrl on control frames
wifi: rtw89: honor ASSIGN_SEQ, retries, and NO_ACK for injected frames
drivers/net/wireless/realtek/rtw89/core.c | 27 ++++++++++++++++--- drivers/net/wireless/realtek/rtw89/core.h | 3 +++ drivers/net/wireless/realtek/rtw89/mac.h | 2 ++ drivers/net/wireless/realtek/rtw89/mac80211.c | 16 ++++++++++- 4 files changed, 44 insertions(+), 4 deletions(-)
base-commit: badf4c3c7679871a50cff1150f66e63187201757
Signature · 1 line
2.56.0.windows.4
PATCH v6 1/5 wifi: rtw89: avoid NULL vif dereference in rtw89_ops_tx()
Injecting a raw frame on a passive monitor interface while a station or AP interface is also up causes a kernel NULL pointer dereference, because mac80211 has no virtual monitor vif in concurrent mode and passes a NULL vif to the driver TX path.
Check the vif pointer with vif_to_rtwvif_safe() and drop frames without a vif.
--- drivers/net/wireless/realtek/rtw89/mac80211.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/mac80211.c +6 -1
@@ -23,11 +23,16 @@ static void rtw89_ops_tx(struct ieee80211_hw *hw,struct rtw89_dev *rtwdev = hw->priv;struct ieee80211_tx_info *info =IEEE80211_SKB_CB (skb);struct ieee80211_vif *vif = info->control.vif; -struct rtw89_vif *rtwvif =vif_to_rtwvif (vif); +struct rtw89_vif *rtwvif =vif_to_rtwvif_safe (vif);struct ieee80211_sta *sta = control->sta;u32 flags =IEEE80211_SKB_CB (skb)->flags;int ret, qsel; +if (unlikely (!rtwvif)) { +ieee80211_free_txskb (hw, skb); +return ; + } +if (rtwvif->offchan && !(flags &IEEE80211_TX_CTL_TX_OFFCHAN ) && sta) {struct rtw89_sta *rtwsta =sta_to_rtwsta (sta);
Signature · 1 line
2.56.0.windows.4
PATCH v6 2/5 wifi: rtw89: handle negative rate index for injected frames
In reply to Enver IkromovWhen user space injects a frame with a radiotap rate that is not supported on the current band (for example 1 Mbps CCK on 5 GHz), mac80211 sets the rate index to -1. Storing that index in an unsigned byte turns it into 0xff and programs an invalid hardware rate into the TX descriptor.
Clamp negative rate indices to 0 so the lowest valid band rate (1 Mbps on 2.4 GHz, 6 Mbps on 5/6 GHz) is selected.
--- drivers/net/wireless/realtek/rtw89/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/core.c +1 -1
@@ -1259,7 +1259,7 @@ static void rtw89_core_tx_update_injection(struct rtw89_dev *rtwdev,enum mac80211_rate_control_flags flags = info->control.rates[0 ].flags;struct rtw89_tx_desc_info *desc_info = &tx_req->desc_info;const struct rtw89_chan *chan; -u8 idx = info->control.rates[0 ].idx; +u8 idx =max_t (s8, info->control.rates[0 ].idx,0 );u8 nss, mcs; desc_info->use_rate = true;
Signature · 1 line
2.56.0.windows.4
PATCH v6 3/5 wifi: rtw89: restore channel when leaving idle on non-chanctx devices
In reply to Enver IkromovFix the operating channel not being restored after bringing a monitor interface down and back up on devices that do not use native chanctx callbacks (such as RTL8852AE when firmware lacks beacon filtering).
Stopping the interface powers down the PHY while mac80211 retains the previous chandef and omits IEEE80211_CONF_CHANGE_CHANNEL on restart. Record support_chanctx in rtwdev and set IEEE80211_CONF_CHANGE_CHANNEL when re-entering monitor mode from idle on non-chanctx devices so the channel is applied again.
--- drivers/net/wireless/realtek/rtw89/core.c | 1 + drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/mac80211.c | 9 +++++++++ 3 files changed, 11 insertions(+)
drivers/net/wireless/realtek/rtw89/core.c +1 -0
@@ -7761,6 +7761,7 @@ struct rtw89_dev *rtw89_alloc_ieee80211_hw(struct device *device, rtwdev->board = info->board; rtwdev->fw.req.firmware = firmware; rtwdev->fw.fw_format = fw_format; + rtwdev->support_chanctx = !no_chanctx; rtwdev->support_mlo = support_mlo;bitmap_copy (rtwdev->quirks, &chip->default_quirks,NUM_OF_RTW89_QUIRKS );
drivers/net/wireless/realtek/rtw89/core.h +1 -0
@@ -7703,6 +7703,7 @@ struct rtw89_dev {const struct rtw89_io_ops *io;bool dbcc_en; +bool support_chanctx;bool support_mlo;enum rtw89_mlo_dbcc_mode mlo_dbcc_mode;struct rtw89_hw_scan_info scan_info;
drivers/net/wireless/realtek/rtw89/mac80211.c +9 -0
@@ -89,6 +89,7 @@ static void rtw89_ops_stop(struct ieee80211_hw *hw, bool suspend)static int rtw89_ops_config (struct ieee80211_hw *hw,int radio_idx,u32 changed) {struct rtw89_dev *rtwdev = hw->priv; +bool no_chanctx = !rtwdev->support_chanctx;lockdep_assert_wiphy (hw->wiphy);
@@ -97,6 +98,14 @@ static int rtw89_ops_config(struct ieee80211_hw *hw, int radio_idx, u32 changed)rtw89_leave_ps_mode (rtwdev); +if (no_chanctx && + (changed & (IEEE80211_CONF_CHANGE_IDLE | +IEEE80211_CONF_CHANGE_MONITOR )) == + (IEEE80211_CONF_CHANGE_IDLE |IEEE80211_CONF_CHANGE_MONITOR )) { +if (!(hw->conf.flags &IEEE80211_CONF_IDLE )) + changed |=IEEE80211_CONF_CHANGE_CHANNEL ; + } +if ((changed &IEEE80211_CONF_CHANGE_IDLE ) && !(hw->conf.flags &IEEE80211_CONF_IDLE ))rtw89_leave_ips (rtwdev);
Signature · 1 line
2.56.0.windows.4
RE: [PATCH rtw-next v6 3/5] wifi: rtw89: restore channel when leaving idle on non-chanctx devices
Quoted 63 lines · Enver Ikromov
Fix the operating channel not being restored after bringing a monitor interface down and back up on devices that do not use native chanctx callbacks (such as RTL8852AE when firmware lacks beacon filtering).
Stopping the interface powers down the PHY while mac80211 retains the previous chandef and omits
IEEE80211_CONF_CHANGE_CHANNELon restart. Recordsupport_chanctxin rtwdev and setIEEE80211_CONF_CHANGE_CHANNEL
when re-entering monitor mode from idle on non-chanctx devices so the channel is applied again.Signed-off-by Enver Ikromov <[email protected]>--- drivers/net/wireless/realtek/rtw89/core.c | 1 + drivers/net/wireless/realtek/rtw89/core.h | 1 + drivers/net/wireless/realtek/rtw89/mac80211.c | 9 +++++++++ 3 files changed, 11 insertions(+)drivers/net/wireless/realtek/rtw89/core.c +1
-0@@ -7761,6 +7761,7 @@ struct rtw89_dev *rtw89_alloc_ieee80211_hw(struct device *device, rtwdev->board = info->board; rtwdev->fw.req.firmware = firmware; rtwdev->fw.fw_format = fw_format; + rtwdev->support_chanctx = !no_chanctx; rtwdev->support_mlo = support_mlo;bitmap_copy(rtwdev->quirks, &chip->default_quirks,
NUM_OF_RTW89_QUIRKS);drivers/net/wireless/realtek/rtw89/core.h +1
-0@@ -7703,6 +7703,7 @@ struct rtw89_dev {const struct rtw89_io_ops *io;bool dbcc_en; +bool support_chanctx;bool support_mlo;enum rtw89_mlo_dbcc_mode mlo_dbcc_mode;struct rtw89_hw_scan_info scan_info;drivers/net/wireless/realtek/rtw89/mac80211.c +1
-0@@ -89,6 +89,7 @@ static void rtw89_ops_stop(struct ieee80211_hw *hw, bool suspend)static int rtw89_ops_config (struct ieee80211_hw *hw,int radio_idx,u32 changed) {struct rtw89_dev *rtwdev = hw->priv; +bool no_chanctx = !rtwdev->support_chanctx;lockdep_assert_wiphy(hw->wiphy);
drivers/net/wireless/realtek/rtw89/mac80211.c static int rtw89_ops_config(struct ieee80211_hw *hw, · line 107
Quoted 10 lines
drivers/net/wireless/realtek/rtw89/mac80211.c +5
-0@@ -97,6 +98,14 @@ static int rtw89_ops_config(struct ieee80211_hw *hw, int radio_idx, u32 changed)rtw89_leave_ps_mode (rtwdev ); +if (no_chanctx && + (changed & (IEEE80211_CONF_CHANGE_IDLE | +IEEE80211_CONF_CHANGE_MONITOR )) == + (IEEE80211_CONF_CHANGE_IDLE |IEEE80211_CONF_CHANGE_MONITOR )) { +if (!(hw->conf.flags &IEEE80211_CONF_IDLE ))
How about
If (!rtwdev->support_chanctx &&
changed & IEEE80211_CONF_CHANGE_IDLE &&
changed & IEEE80211_CONF_CHANGE_ MONITOR &&
!(hw->conf.flags & IEEE80211_CONF_IDLE))Additionally,
(changed & (IEEE80211_CONF_CHANGE_IDLE |
IEEE80211_CONF_CHANGE_MONITOR))seems to be true for any first iface (even if not a monitor) by ieee80211_hw_conf_init(). So, perhaps the condition should be
If (!rtwdev->support_chanctx &&
changed & IEEE80211_CONF_CHANGE_IDLE &&
changed & IEEE80211_CONF_CHANGE_ MONITOR &&
!(hw->conf.flags & IEEE80211_CONF_IDLE) &&
hw->conf.flags & IEEE80211_CONF_MONITOR)Quoted 9 lines
drivers/net/wireless/realtek/rtw89/mac80211.c +3
-0+ changed |=IEEE80211_CONF_CHANGE_CHANNEL ; + } +if ((changed & IEEE80211_CONF_CHANGE_IDLE) && !(hw->conf.flags & IEEE80211_CONF_IDLE)) rtw89_leave_ips(rtwdev);--
2.56.0.windows.4
Re: [PATCH rtw-next v6 3/5] wifi: rtw89: restore channel when leaving idle on non-chanctx devices
Quoted 11 lines · Zong-Zhe Yang
Additionally,
(changed & (IEEE80211_CONF_CHANGE_IDLE | IEEE80211_CONF_CHANGE_MONITOR))seems to be true for any first iface (even if not a monitor) by
ieee80211_hw_conf_init(). So, perhaps the condition should beIf (!rtwdev->support_chanctx && changed & IEEE80211_CONF_CHANGE_IDLE && changed & IEEE80211_CONF_CHANGE_ MONITOR && !(hw->conf.flags & IEEE80211_CONF_IDLE) && hw->conf.flags & IEEE80211_CONF_MONITOR)
Good catch on ieee80211_hw_conf_init(). I will drop the local variable and add the IEEE80211_CONF_MONITOR check in v7.
Thanks,
Enver
PATCH v6 4/5 wifi: rtw89: avoid reading seq_ctrl on control frames
In reply to Enver IkromovInjected 802.11 control frames such as 10-byte ACK/CTS or 16-byte RTS do not carry a sequence control field and are shorter than a 24-byte 3-address header.
Set seq to 0 for control frames instead of reading hdr->seq_ctrl.
--- drivers/net/wireless/realtek/rtw89/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/core.c +4 -1
@@ -1317,7 +1317,10 @@ rtw89_core_tx_update_desc_info(struct rtw89_dev *rtwdev,else if (tx_req->vif) desc_info->mlo =ieee80211_vif_is_mld (tx_req->vif); - seq = (le16_to_cpu (hdr->seq_ctrl) &IEEE80211_SCTL_SEQ ) >>4 ; +if (ieee80211_is_ctl (hdr->frame_control)) + seq =0 ; +else + seq = (le16_to_cpu (hdr->seq_ctrl) &IEEE80211_SCTL_SEQ ) >>4 ; addr_cam =rtw89_get_addr_cam_of (tx_req->rtwvif_link, tx_req->rtwsta_link);if (addr_cam->valid && desc_info->mlo)
Signature · 1 line
2.56.0.windows.4
PATCH v6 5/5 wifi: rtw89: honor ASSIGN_SEQ, retries, and NO_ACK for injected frames
In reply to Enver IkromovInjected management frames currently overwrite caller-supplied sequence numbers because hardware sequence numbering remains enabled when IEEE80211_TX_CTL_ASSIGN_SEQ is unset, and injected frames ignore NO_ACK and explicit radiotap retry limits.
Preserve the caller's sequence number when IEEE80211_TX_CTL_ASSIGN_SEQ is not set, apply NO_ACK in TX descriptors and completion status, and honor radiotap retry counts up to RTW89_TX_DATA_CNT_LMT_MAX (63).
--- drivers/net/wireless/realtek/rtw89/core.c | 19 ++++++++++++++++++- drivers/net/wireless/realtek/rtw89/core.h | 2 ++ drivers/net/wireless/realtek/rtw89/mac.h | 2 ++ 3 files changed, 22 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/core.c +18 -1
@@ -1265,6 +1265,20 @@ static void rtw89_core_tx_update_injection(struct rtw89_dev *rtwdev, desc_info->use_rate = true; desc_info->dis_data_fb = true; +if (!(info->flags &IEEE80211_TX_CTL_ASSIGN_SEQ )) { + desc_info->hw_ssn_sel =0 ; + desc_info->hw_seq_mode =0 ; + } + +if (info->flags &IEEE80211_TX_CTL_NO_ACK ) { + desc_info->no_ack = true; + desc_info->tx_cnt_lmt_en = true; + desc_info->tx_cnt_lmt =1 ; + }else if (info->control.rates[0 ].count) { + desc_info->tx_cnt_lmt_en = true; + desc_info->tx_cnt_lmt = info->control.rates[0 ].count; + } +if (flags &IEEE80211_TX_RC_160_MHZ_WIDTH ) desc_info->data_bw =3 ;else if (flags &IEEE80211_TX_RC_80_MHZ_WIDTH )
@@ -1800,7 +1814,9 @@ static __le32 rtw89_build_txwd_body5_v2(struct rtw89_tx_desc_info *desc_info)static __le32 rtw89_build_txwd_body6_v2 (struct rtw89_tx_desc_info *desc_info) { -u32 dword =FIELD_PREP (BE_TXD_BODY6_UPD_WLAN_HDR , desc_info->upd_wlan_hdr); +u32 dword =FIELD_PREP (BE_TXD_BODY6_NO_ACK , desc_info->no_ack) | +FIELD_PREP (BE_TXD_BODY6_UPD_WLAN_HDR , + desc_info->upd_wlan_hdr);return cpu_to_le32 (dword); }
@@ -7540,6 +7556,7 @@ static int rtw89_core_register_hw(struct rtw89_dev *rtwdev) hw->queues =IEEE80211_NUM_ACS ; hw->max_rx_aggregation_subframes = chip->max_rx_agg_num; hw->max_tx_aggregation_subframes = chip->max_tx_agg_num; + hw->max_rate_tries =RTW89_TX_DATA_CNT_LMT_MAX ; hw->uapsd_max_sp_len =IEEE80211_WMM_IE_STA_QOSINFO_SP_ALL ; hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FEC |
drivers/net/wireless/realtek/rtw89/core.h +2 -0
@@ -1278,6 +1278,7 @@ struct rtw89_tx_desc_info {bool tx_cnt_lmt_en; u8 sn: 4; u8 tx_cnt_lmt: 6; +#define RTW89_TX_DATA_CNT_LMT_MAX 0x3fu8 addr_info_nr;u8 sec_keyid;u8 sec_type;
@@ -1300,6 +1301,7 @@ struct rtw89_tx_desc_info {bool stbc;bool ldpc;bool upd_wlan_hdr; +bool no_ack;bool mlo;bool sw_mld; };
drivers/net/wireless/realtek/rtw89/mac.h +2 -0
@@ -1896,6 +1896,8 @@ void rtw89_tx_rpt_tx_status(struct rtw89_dev *rtwdev, struct sk_buff *skb, info =IEEE80211_SKB_CB (skb);ieee80211_tx_info_clear_status (info); +if (info->flags &IEEE80211_TX_CTL_NO_ACK ) + info->flags |=IEEE80211_TX_STAT_NOACK_TRANSMITTED ;if (tx_status ==RTW89_TX_DONE ) info->flags |=IEEE80211_TX_STAT_ACK ;else
Signature · 1 line
2.56.0.windows.4