Skip to content

Commit 117dbed

Browse files
Li ZetaoKalle Valo
Li Zetao
authored and
Kalle Valo
committed
wifi: rtlwifi: Fix global-out-of-bounds bug in _rtl8812ae_phy_set_txpower_limit()
There is a global-out-of-bounds reported by KASAN: BUG: KASAN: global-out-of-bounds in _rtl8812ae_eq_n_byte.part.0+0x3d/0x84 [rtl8821ae] Read of size 1 at addr ffffffffa0773c43 by task NetworkManager/411 CPU: 6 PID: 411 Comm: NetworkManager Tainted: G D 6.1.0-rc8+ #144 e15588508517267d37 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), Call Trace: <TASK> ... kasan_report+0xbb/0x1c0 _rtl8812ae_eq_n_byte.part.0+0x3d/0x84 [rtl8821ae] rtl8821ae_phy_bb_config.cold+0x346/0x641 [rtl8821ae] rtl8821ae_hw_init+0x1f5e/0x79b0 [rtl8821ae] ... </TASK> The root cause of the problem is that the comparison order of "prate_section" in _rtl8812ae_phy_set_txpower_limit() is wrong. The _rtl8812ae_eq_n_byte() is used to compare the first n bytes of the two strings from tail to head, which causes the problem. In the _rtl8812ae_phy_set_txpower_limit(), it was originally intended to meet this requirement by carefully designing the comparison order. For example, "pregulation" and "pbandwidth" are compared in order of length from small to large, first is 3 and last is 4. However, the comparison order of "prate_section" dose not obey such order requirement, therefore when "prate_section" is "HT", when comparing from tail to head, it will lead to access out of bounds in _rtl8812ae_eq_n_byte(). As mentioned above, the _rtl8812ae_eq_n_byte() has the same function as strcmp(), so just strcmp() is enough. Fix it by removing _rtl8812ae_eq_n_byte() and use strcmp() barely. Although it can be fixed by adjusting the comparison order of "prate_section", this may cause the value of "rate_section" to not be from 0 to 5. In addition, commit "21e4b0726dc6" not only moved driver from staging to regular tree, but also added setting txpower limit function during the driver config phase, so the problem was introduced by this commit. Fixes: 21e4b07 ("rtlwifi: rtl8821ae: Move driver from staging to regular tree") Signed-off-by: Li Zetao <[email protected]> Acked-by: Ping-Ke Shih <[email protected]> Signed-off-by: Kalle Valo <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9c22d60 commit 117dbed

File tree

1 file changed

+20
-32
lines changed
  • drivers/net/wireless/realtek/rtlwifi/rtl8821ae

1 file changed

+20
-32
lines changed

drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,18 +1598,6 @@ static bool _rtl8812ae_get_integer_from_string(const char *str, u8 *pint)
15981598
return true;
15991599
}
16001600

1601-
static bool _rtl8812ae_eq_n_byte(const char *str1, const char *str2, u32 num)
1602-
{
1603-
if (num == 0)
1604-
return false;
1605-
while (num > 0) {
1606-
num--;
1607-
if (str1[num] != str2[num])
1608-
return false;
1609-
}
1610-
return true;
1611-
}
1612-
16131601
static s8 _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(struct ieee80211_hw *hw,
16141602
u8 band, u8 channel)
16151603
{
@@ -1659,42 +1647,42 @@ static void _rtl8812ae_phy_set_txpower_limit(struct ieee80211_hw *hw,
16591647
power_limit = power_limit > MAX_POWER_INDEX ?
16601648
MAX_POWER_INDEX : power_limit;
16611649

1662-
if (_rtl8812ae_eq_n_byte(pregulation, "FCC", 3))
1650+
if (strcmp(pregulation, "FCC") == 0)
16631651
regulation = 0;
1664-
else if (_rtl8812ae_eq_n_byte(pregulation, "MKK", 3))
1652+
else if (strcmp(pregulation, "MKK") == 0)
16651653
regulation = 1;
1666-
else if (_rtl8812ae_eq_n_byte(pregulation, "ETSI", 4))
1654+
else if (strcmp(pregulation, "ETSI") == 0)
16671655
regulation = 2;
1668-
else if (_rtl8812ae_eq_n_byte(pregulation, "WW13", 4))
1656+
else if (strcmp(pregulation, "WW13") == 0)
16691657
regulation = 3;
16701658

1671-
if (_rtl8812ae_eq_n_byte(prate_section, "CCK", 3))
1659+
if (strcmp(prate_section, "CCK") == 0)
16721660
rate_section = 0;
1673-
else if (_rtl8812ae_eq_n_byte(prate_section, "OFDM", 4))
1661+
else if (strcmp(prate_section, "OFDM") == 0)
16741662
rate_section = 1;
1675-
else if (_rtl8812ae_eq_n_byte(prate_section, "HT", 2) &&
1676-
_rtl8812ae_eq_n_byte(prf_path, "1T", 2))
1663+
else if (strcmp(prate_section, "HT") == 0 &&
1664+
strcmp(prf_path, "1T") == 0)
16771665
rate_section = 2;
1678-
else if (_rtl8812ae_eq_n_byte(prate_section, "HT", 2) &&
1679-
_rtl8812ae_eq_n_byte(prf_path, "2T", 2))
1666+
else if (strcmp(prate_section, "HT") == 0 &&
1667+
strcmp(prf_path, "2T") == 0)
16801668
rate_section = 3;
1681-
else if (_rtl8812ae_eq_n_byte(prate_section, "VHT", 3) &&
1682-
_rtl8812ae_eq_n_byte(prf_path, "1T", 2))
1669+
else if (strcmp(prate_section, "VHT") == 0 &&
1670+
strcmp(prf_path, "1T") == 0)
16831671
rate_section = 4;
1684-
else if (_rtl8812ae_eq_n_byte(prate_section, "VHT", 3) &&
1685-
_rtl8812ae_eq_n_byte(prf_path, "2T", 2))
1672+
else if (strcmp(prate_section, "VHT") == 0 &&
1673+
strcmp(prf_path, "2T") == 0)
16861674
rate_section = 5;
16871675

1688-
if (_rtl8812ae_eq_n_byte(pbandwidth, "20M", 3))
1676+
if (strcmp(pbandwidth, "20M") == 0)
16891677
bandwidth = 0;
1690-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "40M", 3))
1678+
else if (strcmp(pbandwidth, "40M") == 0)
16911679
bandwidth = 1;
1692-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "80M", 3))
1680+
else if (strcmp(pbandwidth, "80M") == 0)
16931681
bandwidth = 2;
1694-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "160M", 4))
1682+
else if (strcmp(pbandwidth, "160M") == 0)
16951683
bandwidth = 3;
16961684

1697-
if (_rtl8812ae_eq_n_byte(pband, "2.4G", 4)) {
1685+
if (strcmp(pband, "2.4G") == 0) {
16981686
ret = _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw,
16991687
BAND_ON_2_4G,
17001688
channel);
@@ -1718,7 +1706,7 @@ static void _rtl8812ae_phy_set_txpower_limit(struct ieee80211_hw *hw,
17181706
regulation, bandwidth, rate_section, channel_index,
17191707
rtlphy->txpwr_limit_2_4g[regulation][bandwidth]
17201708
[rate_section][channel_index][RF90_PATH_A]);
1721-
} else if (_rtl8812ae_eq_n_byte(pband, "5G", 2)) {
1709+
} else if (strcmp(pband, "5G") == 0) {
17221710
ret = _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw,
17231711
BAND_ON_5G,
17241712
channel);

0 commit comments

Comments
 (0)