Skip to content

Commit b365065

Browse files
Li ZetaoSasha Levin
Li Zetao
authored and
Sasha Levin
committed
wifi: rtlwifi: Fix global-out-of-bounds bug in _rtl8812ae_phy_set_txpower_limit()
[ Upstream commit 117dbed ] 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+ torvalds#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] Signed-off-by: Sasha Levin <[email protected]>
1 parent 59c1c19 commit b365065

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

+20-32
Original file line numberDiff line numberDiff line change
@@ -1599,18 +1599,6 @@ static bool _rtl8812ae_get_integer_from_string(const char *str, u8 *pint)
15991599
return true;
16001600
}
16011601

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

1663-
if (_rtl8812ae_eq_n_byte(pregulation, "FCC", 3))
1651+
if (strcmp(pregulation, "FCC") == 0)
16641652
regulation = 0;
1665-
else if (_rtl8812ae_eq_n_byte(pregulation, "MKK", 3))
1653+
else if (strcmp(pregulation, "MKK") == 0)
16661654
regulation = 1;
1667-
else if (_rtl8812ae_eq_n_byte(pregulation, "ETSI", 4))
1655+
else if (strcmp(pregulation, "ETSI") == 0)
16681656
regulation = 2;
1669-
else if (_rtl8812ae_eq_n_byte(pregulation, "WW13", 4))
1657+
else if (strcmp(pregulation, "WW13") == 0)
16701658
regulation = 3;
16711659

1672-
if (_rtl8812ae_eq_n_byte(prate_section, "CCK", 3))
1660+
if (strcmp(prate_section, "CCK") == 0)
16731661
rate_section = 0;
1674-
else if (_rtl8812ae_eq_n_byte(prate_section, "OFDM", 4))
1662+
else if (strcmp(prate_section, "OFDM") == 0)
16751663
rate_section = 1;
1676-
else if (_rtl8812ae_eq_n_byte(prate_section, "HT", 2) &&
1677-
_rtl8812ae_eq_n_byte(prf_path, "1T", 2))
1664+
else if (strcmp(prate_section, "HT") == 0 &&
1665+
strcmp(prf_path, "1T") == 0)
16781666
rate_section = 2;
1679-
else if (_rtl8812ae_eq_n_byte(prate_section, "HT", 2) &&
1680-
_rtl8812ae_eq_n_byte(prf_path, "2T", 2))
1667+
else if (strcmp(prate_section, "HT") == 0 &&
1668+
strcmp(prf_path, "2T") == 0)
16811669
rate_section = 3;
1682-
else if (_rtl8812ae_eq_n_byte(prate_section, "VHT", 3) &&
1683-
_rtl8812ae_eq_n_byte(prf_path, "1T", 2))
1670+
else if (strcmp(prate_section, "VHT") == 0 &&
1671+
strcmp(prf_path, "1T") == 0)
16841672
rate_section = 4;
1685-
else if (_rtl8812ae_eq_n_byte(prate_section, "VHT", 3) &&
1686-
_rtl8812ae_eq_n_byte(prf_path, "2T", 2))
1673+
else if (strcmp(prate_section, "VHT") == 0 &&
1674+
strcmp(prf_path, "2T") == 0)
16871675
rate_section = 5;
16881676

1689-
if (_rtl8812ae_eq_n_byte(pbandwidth, "20M", 3))
1677+
if (strcmp(pbandwidth, "20M") == 0)
16901678
bandwidth = 0;
1691-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "40M", 3))
1679+
else if (strcmp(pbandwidth, "40M") == 0)
16921680
bandwidth = 1;
1693-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "80M", 3))
1681+
else if (strcmp(pbandwidth, "80M") == 0)
16941682
bandwidth = 2;
1695-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "160M", 4))
1683+
else if (strcmp(pbandwidth, "160M") == 0)
16961684
bandwidth = 3;
16971685

1698-
if (_rtl8812ae_eq_n_byte(pband, "2.4G", 4)) {
1686+
if (strcmp(pband, "2.4G") == 0) {
16991687
ret = _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw,
17001688
BAND_ON_2_4G,
17011689
channel);
@@ -1719,7 +1707,7 @@ static void _rtl8812ae_phy_set_txpower_limit(struct ieee80211_hw *hw,
17191707
regulation, bandwidth, rate_section, channel_index,
17201708
rtlphy->txpwr_limit_2_4g[regulation][bandwidth]
17211709
[rate_section][channel_index][RF90_PATH_A]);
1722-
} else if (_rtl8812ae_eq_n_byte(pband, "5G", 2)) {
1710+
} else if (strcmp(pband, "5G") == 0) {
17231711
ret = _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw,
17241712
BAND_ON_5G,
17251713
channel);

0 commit comments

Comments
 (0)