]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: rtw89: phy: fix out-of-bounds access in rtw89_phy_read_txpwr_limit()
authorKuan-Chung Chen <damon.chen@realtek.com>
Tue, 11 Nov 2025 02:24:49 +0000 (10:24 +0800)
committerPing-Ke Shih <pkshih@realtek.com>
Thu, 13 Nov 2025 01:36:40 +0000 (09:36 +0800)
Coverity reported a potential out-of-bounds access when 'bw' exceeds the
valid range for the specified band. Add a helper `rtw89_bw_is_valid()`
to check bandwidth validity for each band before accessing limit tables.

Addresses-Coverity-ID: 1598844 ("Out-of-bounds access")
Addresses-Coverity-ID: 1598896 ("Out-of-bounds access")

Signed-off-by: Kuan-Chung Chen <damon.chen@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://patch.msgid.link/20251111022452.28093-6-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/phy.c

index 23892c1359a563ac3a143b0d61361f70abe77732..28e2b15240a7a835dfa7ba218f8a8fbaed467185 100644 (file)
@@ -2376,6 +2376,21 @@ static u8 rtw89_channel_to_idx(struct rtw89_dev *rtwdev, u8 band, u8 channel)
        }
 }
 
+static bool rtw89_phy_validate_txpwr_limit_bw(struct rtw89_dev *rtwdev,
+                                             u8 band, u8 bw)
+{
+       switch (band) {
+       case RTW89_BAND_2G:
+               return bw < RTW89_2G_BW_NUM;
+       case RTW89_BAND_5G:
+               return bw < RTW89_5G_BW_NUM;
+       case RTW89_BAND_6G:
+               return bw < RTW89_6G_BW_NUM;
+       default:
+               return false;
+       }
+}
+
 s8 rtw89_phy_read_txpwr_limit(struct rtw89_dev *rtwdev, u8 band,
                              u8 bw, u8 ntx, u8 rs, u8 bf, u8 ch)
 {
@@ -2400,6 +2415,11 @@ s8 rtw89_phy_read_txpwr_limit(struct rtw89_dev *rtwdev, u8 band,
        };
        s8 cstr;
 
+       if (!rtw89_phy_validate_txpwr_limit_bw(rtwdev, band, bw)) {
+               rtw89_warn(rtwdev, "invalid band %u bandwidth %u\n", band, bw);
+               return 0;
+       }
+
        switch (band) {
        case RTW89_BAND_2G:
                if (has_ant_gain)