wifi: rtw89: monitor mode and raw frame injection fixes
Subsystems (2)
v8 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 v8:
- Patch 1: update Fixes tag to e3ec7017f6a2 ("rtw89: add Realtek 802.11ax driver").
- Patch 4: add a blank line after setting seq.
- Patch 5: note in the commit message that Wi-Fi 6 chips such as RTL8852AE lack a TX descriptor NO_ACK field, and unwrap rtw89_build_txwd_body6_v2().
- Collect Acked-by and Reviewed-by tags on patches 1-4.
Changes in v7:
- Patch 3: drop the local no_chanctx variable and check IEEE80211_CONF_MONITOR in rtw89_ops_config() so the channel flag is not set for non-monitor first interfaces in ieee80211_hw_conf_init().
- Rebase onto latest rtw-next.
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.
- Shorten commit messages and rebase onto rtw-next.
- 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 code.
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.
v7: https://lore.kernel.org/linux-wireless/[email protected]/
v6: https://lore.kernel.org/linux-wireless/[email protected]/
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 | 14 +++++++++- 4 files changed, 42 insertions(+), 4 deletions(-)
base-commit: 0bdc579dbfc251a6b6838ee9459b6771b948c617
Signature · 1 line
2.56.0.windows.4
PATCH v8 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
Ping-Ke Shih
maintainerRe: [PATCH rtw-next v8 1/5] wifi: rtw89: avoid NULL vif dereference in rtw89_ops_tx()
Quoted 5 lines · Enver Ikromov
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.
Quoted 7 lines
Check the vif pointer with
vif_to_rtwvif_safe()and drop frames without a vif.Fixes e3ec7017f6a2 ("rtw89: add Realtek 802.11ax driver")Signed-off-by Enver Ikromov <[email protected]>Acked-by Ping-Ke Shih <[email protected]>
5 patch(es) applied to rtw-next branch of rtw.git, thanks.
0202cb50fe9f wifi: rtw89: avoid NULL vif dereference in rtw89_ops_tx() 260247bfbc5b wifi: rtw89: handle negative rate index for injected frames e07c9af7bbc8 wifi: rtw89: restore channel when leaving idle on non-chanctx devices 4175fc84dbe9 wifi: rtw89: avoid reading seq_ctrl on control frames 92608bb5f14f wifi: rtw89: honor ASSIGN_SEQ, retries, and NO_ACK for injected frames
PATCH v8 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 v8 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 | 7 +++++++ 3 files changed, 9 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 +7 -0
@@ -97,6 +97,13 @@ static int rtw89_ops_config(struct ieee80211_hw *hw, int radio_idx, u32 changed)rtw89_leave_ps_mode (rtwdev); +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 ) + 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
PATCH v8 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 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/core.c +5 -1
@@ -1317,7 +1317,11 @@ 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 v8 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, honor radiotap retry counts up to RTW89_TX_DATA_CNT_LMT_MAX (63), and report IEEE80211_TX_STAT_NOACK_TRANSMITTED for NO_ACK frames. Set BE_TXD_BODY6_NO_ACK on Wi-Fi 7 chips that carry NO_ACK in the TX descriptor; Wi-Fi 6 chips such as RTL8852AE do not have a TX descriptor NO_ACK field and only limit transmission to a single attempt via tx_cnt_lmt = 1.
--- drivers/net/wireless/realtek/rtw89/core.c | 18 +++++++++++++++++- drivers/net/wireless/realtek/rtw89/core.h | 2 ++ drivers/net/wireless/realtek/rtw89/mac.h | 2 ++ 3 files changed, 21 insertions(+), 1 deletion(-)
drivers/net/wireless/realtek/rtw89/core.c +17 -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 )
@@ -1801,7 +1815,8 @@ 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); }
@@ -7541,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
RE: [PATCH rtw-next v8 5/5] wifi: rtw89: honor ASSIGN_SEQ, retries, and NO_ACK for injected frames
Quoted 11 lines · Enver Ikromov
Injected management frames currently overwrite caller-supplied sequence numbers because hardware sequence numbering remains enabled when
IEEE80211_TX_CTL_ASSIGN_SEQis unset, and injected frames ignoreNO_ACKand explicit radiotap retry limits.Preserve the caller's sequence number when
IEEE80211_TX_CTL_ASSIGN_SEQis not set, honor radiotap retry counts up toRTW89_TX_DATA_CNT_LMT_MAX(63), and reportIEEE80211_TX_STAT_NOACK_TRANSMITTEDforNO_ACKframes.Set
BE_TXD_BODY6_NO_ACKon Wi-Fi 7 chips that carryNO_ACKin the TX descriptor;
I'd add "(not tested)" here.
No need v9 because of this.
Quoted 5 lines
Wi-Fi 6 chips such as RTL8852AE do not have a TX descriptor
NO_ACKfield and only limit transmission to a single attempt viatx_cnt_lmt= 1.Signed-off-by Enver Ikromov <[email protected]>