* [PATCH] wifi: rtw89: read the beacon header from the frame data
@ 2026-11-18 5:46 Shirong Zhao
2026-11-19 2:29 ` Ping-Ke Shih
2026-11-19 5:06 ` [PATCH v2] wifi: rtw89: read the beacon header from the skb data Shirong Zhao
0 siblings, 2 replies; 4+ messages in thread
From: Shirong Zhao @ 2026-11-18 5:46 UTC (permalink / raw)
To: Ping-Ke Shih; +Cc: linux-wireless, Johannes Berg, linux-kernel
rtw89_fw_h2c_update_beacon() and rtw89_fw_h2c_update_beacon_be()
cast the sk_buff pointer itself to struct ieee80211_hdr to compute the
TIM offset:
hdr = (struct ieee80211_hdr *)skb_beacon;
The 802.11 header lives in the frame data returned by
ieee80211_beacon_get_tim(), not at the start of struct sk_buff, so the
cast reads sk_buff metadata instead of frame_control.
For a freshly allocated skb skb->next is NULL, the value read is 0 and
ieee80211_hdrlen() happens to return the same 24 bytes as a real beacon
header, which masks the bug. As soon as the skb is on a list the
computed header length is garbage and the Group IE offset passed to the
firmware is wrong.
Point hdr at skb_beacon->data instead.
Found by code inspection; not observed at runtime.
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
---
drivers/net/wireless/realtek/rtw89/fw.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
index 21b548c..0eab77f 100644
--- a/drivers/net/wireless/realtek/rtw89/fw.c
+++ b/drivers/net/wireless/realtek/rtw89/fw.c
@@ -5130,7 +5130,7 @@ int rtw89_fw_h2c_update_beacon(struct rtw89_dev *rtwdev,
skb_put_data(skb_beacon, noa_data, noa_len);
}
- hdr = (struct ieee80211_hdr *)skb_beacon;
+ hdr = (struct ieee80211_hdr *)skb_beacon->data;
tim_offset -= ieee80211_hdrlen(hdr->frame_control);
bcn_total_len = len + skb_beacon->len;
@@ -5209,7 +5209,7 @@ int rtw89_fw_h2c_update_beacon_be(struct rtw89_dev *rtwdev,
skb_put_data(skb_beacon, noa_data, noa_len);
}
- hdr = (struct ieee80211_hdr *)skb_beacon;
+ hdr = (struct ieee80211_hdr *)skb_beacon->data;
tim_offset -= ieee80211_hdrlen(hdr->frame_control);
bcn_total_len = len + skb_beacon->len;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] wifi: rtw89: read the beacon header from the frame data
2026-11-18 5:46 [PATCH] wifi: rtw89: read the beacon header from the frame data Shirong Zhao
@ 2026-11-19 2:29 ` Ping-Ke Shih
2026-11-19 5:06 ` [PATCH v2] wifi: rtw89: read the beacon header from the skb data Shirong Zhao
1 sibling, 0 replies; 4+ messages in thread
From: Ping-Ke Shih @ 2026-11-19 2:29 UTC (permalink / raw)
To: Shirong Zhao
Cc: linux-wireless@vger.kernel.org, Johannes Berg,
linux-kernel@vger.kernel.org
Shirong Zhao <shxzhaosr@163.com> wrote:
> rtw89_fw_h2c_update_beacon() and rtw89_fw_h2c_update_beacon_be()
> cast the sk_buff pointer itself to struct ieee80211_hdr to compute the
> TIM offset:
>
> hdr = (struct ieee80211_hdr *)skb_beacon;
>
> The 802.11 header lives in the frame data returned by
> ieee80211_beacon_get_tim(), not at the start of struct sk_buff, so the
> cast reads sk_buff metadata instead of frame_control.
>
> For a freshly allocated skb skb->next is NULL, the value read is 0 and
> ieee80211_hdrlen() happens to return the same 24 bytes as a real beacon
> header, which masks the bug. As soon as the skb is on a list the
> computed header length is garbage and the Group IE offset passed to the
> firmware is wrong.
>
> Point hdr at skb_beacon->data instead.
This is key point, so I'd rephrase subject and commit message as:
subject: wifi: rtw89: read the beacon header from the skb data
message:
Point hdr at skb_beacon->data instead of skb_beacon pointer itself, to
get correct header length for TIM offset for firmware.
Fortunately, original (wrong) header fc is 0x0000, so header length is
recognized as 24 bytes, which is almost the same as AP mode application.
>
> Found by code inspection; not observed at runtime.
I tested with real hardware.
Tested-by: Ping-Ke Shih <pkshih@realtek.com>
Fixes: 69466b979a72 ("wifi: rtw89: use struct to fill H2C command to download beacon frame")
Fixes: a880b9283009 ("wifi: rtw89: add H2C command to download beacon frame for WiFi 7 chips")
> Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] wifi: rtw89: read the beacon header from the skb data
2026-11-18 5:46 [PATCH] wifi: rtw89: read the beacon header from the frame data Shirong Zhao
2026-11-19 2:29 ` Ping-Ke Shih
@ 2026-11-19 5:06 ` Shirong Zhao
2026-11-19 5:40 ` Ping-Ke Shih
1 sibling, 1 reply; 4+ messages in thread
From: Shirong Zhao @ 2026-11-19 5:06 UTC (permalink / raw)
To: Ping-Ke Shih; +Cc: linux-wireless, Johannes Berg, linux-kernel
(v2: reworded subject and commit message, added the two
Fixes: tags and Ping-Ke's Tested-by/Acked-by)
Point hdr at skb_beacon->data instead of the sk_buff pointer itself,
to get the correct header length for the TIM offset passed to firmware.
rtw89_fw_h2c_update_beacon() and rtw89_fw_h2c_update_beacon_be() cast
the sk_buff itself to struct ieee80211_hdr:
hdr = (struct ieee80211_hdr *)skb_beacon;
The 802.11 header lives in the frame data returned by
ieee80211_beacon_get_tim(), not at the start of struct sk_buff, so that
cast reads sk_buff metadata instead of frame_control.
Fortunately the original (wrong) header fc is 0x0000, so the header
length is recognized as 24 bytes, which is almost the same as the AP
mode application. The value is still wrong in principle and would
break as soon as the sk_buff layout supplies a non-zero value there.
Fixes: 69466b979a72 ("wifi: rtw89: use struct to fill H2C command to download beacon frame")
Fixes: a880b9283009 ("wifi: rtw89: add H2C command to download beacon frame for WiFi 7 chips")
Found by code inspection; not observed at runtime.
Tested-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
---
drivers/net/wireless/realtek/rtw89/fw.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/wireless/realtek/rtw89/fw.c b/drivers/net/wireless/realtek/rtw89/fw.c
index 21b548c..0eab77f 100644
--- a/drivers/net/wireless/realtek/rtw89/fw.c
+++ b/drivers/net/wireless/realtek/rtw89/fw.c
@@ -5130,7 +5130,7 @@ int rtw89_fw_h2c_update_beacon(struct rtw89_dev *rtwdev,
skb_put_data(skb_beacon, noa_data, noa_len);
}
- hdr = (struct ieee80211_hdr *)skb_beacon;
+ hdr = (struct ieee80211_hdr *)skb_beacon->data;
tim_offset -= ieee80211_hdrlen(hdr->frame_control);
bcn_total_len = len + skb_beacon->len;
@@ -5209,7 +5209,7 @@ int rtw89_fw_h2c_update_beacon_be(struct rtw89_dev *rtwdev,
skb_put_data(skb_beacon, noa_data, noa_len);
}
- hdr = (struct ieee80211_hdr *)skb_beacon;
+ hdr = (struct ieee80211_hdr *)skb_beacon->data;
tim_offset -= ieee80211_hdrlen(hdr->frame_control);
bcn_total_len = len + skb_beacon->len;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH v2] wifi: rtw89: read the beacon header from the skb data
2026-11-19 5:06 ` [PATCH v2] wifi: rtw89: read the beacon header from the skb data Shirong Zhao
@ 2026-11-19 5:40 ` Ping-Ke Shih
0 siblings, 0 replies; 4+ messages in thread
From: Ping-Ke Shih @ 2026-11-19 5:40 UTC (permalink / raw)
To: Shirong Zhao
Cc: linux-wireless@vger.kernel.org, Johannes Berg,
linux-kernel@vger.kernel.org
Shirong Zhao <shxzhaosr@163.com> wrote:
> (v2: reworded subject and commit message, added the two
> Fixes: tags and Ping-Ke's Tested-by/Acked-by)
This should be put after your s-o-b with --- delimiter.
I forgot to say that I will rephrase the commit message when committing.
>
> Point hdr at skb_beacon->data instead of the sk_buff pointer itself,
> to get the correct header length for the TIM offset passed to firmware.
>
> rtw89_fw_h2c_update_beacon() and rtw89_fw_h2c_update_beacon_be() cast
> the sk_buff itself to struct ieee80211_hdr:
>
> hdr = (struct ieee80211_hdr *)skb_beacon;
>
> The 802.11 header lives in the frame data returned by
> ieee80211_beacon_get_tim(), not at the start of struct sk_buff, so that
> cast reads sk_buff metadata instead of frame_control.
No need too much description which obscures the focus.
>
> Fortunately the original (wrong) header fc is 0x0000, so the header
> length is recognized as 24 bytes, which is almost the same as the AP
> mode application.
> The value is still wrong in principle and would
> break as soon as the sk_buff layout supplies a non-zero value there.
Yes. But "fortunately" it is zero for this case.
>
> Fixes: 69466b979a72 ("wifi: rtw89: use struct to fill H2C command to download beacon frame")
> Fixes: a880b9283009 ("wifi: rtw89: add H2C command to download beacon frame for WiFi 7 chips")
> Found by code inspection; not observed at runtime.
This is not standard tag. Should not here.
> Tested-by: Ping-Ke Shih <pkshih@realtek.com>
> Signed-off-by: Shirong Zhao <shxzhaosr@163.com>
> Acked-by: Ping-Ke Shih <pkshih@realtek.com>
Anyway, I'll take v1 and modify commit message while committing.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-19 5:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 5:46 [PATCH] wifi: rtw89: read the beacon header from the frame data Shirong Zhao
2026-11-19 2:29 ` Ping-Ke Shih
2026-11-19 5:06 ` [PATCH v2] wifi: rtw89: read the beacon header from the skb data Shirong Zhao
2026-11-19 5:40 ` 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