1: 5f9f996885a7 ! 1: 2f384fe7303e wifi: rtw89: read the beacon header from the frame data @@ Metadata Author: Shirong Zhao   ## Commit message ## - wifi: rtw89: read the beacon header from the frame data + wifi: rtw89: read the beacon header from the skb data  - 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: + (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 the + ieee80211_beacon_get_tim(), not at the start of struct sk_buff, so that 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. + 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  Signed-off-by: Shirong Zhao  + Acked-by: Ping-Ke Shih   ## drivers/net/wireless/realtek/rtw89/fw.c ##  @@ drivers/net/wireless/realtek/rtw89/fw.c: int rtw89_fw_h2c_update_beacon(struct rtw89_dev *rtwdev,