Skip to content

Commit 28ea268

Browse files
Li Zetaogregkh
authored andcommitted
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+ #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 5d171ab commit 28ea268

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
@@ -1605,18 +1605,6 @@ static bool _rtl8812ae_get_integer_from_string(const char *str, u8 *pint)
16051605
return true;
16061606
}
16071607

1608-
static bool _rtl8812ae_eq_n_byte(const char *str1, const char *str2, u32 num)
1609-
{
1610-
if (num == 0)
1611-
return false;
1612-
while (num > 0) {
1613-
num--;
1614-
if (str1[num] != str2[num])
1615-
return false;
1616-
}
1617-
return true;
1618-
}
1619-
16201608
static s8 _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(struct ieee80211_hw *hw,
16211609
u8 band, u8 channel)
16221610
{
@@ -1666,42 +1654,42 @@ static void _rtl8812ae_phy_set_txpower_limit(struct ieee80211_hw *hw,
16661654
power_limit = power_limit > MAX_POWER_INDEX ?
16671655
MAX_POWER_INDEX : power_limit;
16681656

1669-
if (_rtl8812ae_eq_n_byte(pregulation, "FCC", 3))
1657+
if (strcmp(pregulation, "FCC") == 0)
16701658
regulation = 0;
1671-
else if (_rtl8812ae_eq_n_byte(pregulation, "MKK", 3))
1659+
else if (strcmp(pregulation, "MKK") == 0)
16721660
regulation = 1;
1673-
else if (_rtl8812ae_eq_n_byte(pregulation, "ETSI", 4))
1661+
else if (strcmp(pregulation, "ETSI") == 0)
16741662
regulation = 2;
1675-
else if (_rtl8812ae_eq_n_byte(pregulation, "WW13", 4))
1663+
else if (strcmp(pregulation, "WW13") == 0)
16761664
regulation = 3;
16771665

1678-
if (_rtl8812ae_eq_n_byte(prate_section, "CCK", 3))
1666+
if (strcmp(prate_section, "CCK") == 0)
16791667
rate_section = 0;
1680-
else if (_rtl8812ae_eq_n_byte(prate_section, "OFDM", 4))
1668+
else if (strcmp(prate_section, "OFDM") == 0)
16811669
rate_section = 1;
1682-
else if (_rtl8812ae_eq_n_byte(prate_section, "HT", 2) &&
1683-
_rtl8812ae_eq_n_byte(prf_path, "1T", 2))
1670+
else if (strcmp(prate_section, "HT") == 0 &&
1671+
strcmp(prf_path, "1T") == 0)
16841672
rate_section = 2;
1685-
else if (_rtl8812ae_eq_n_byte(prate_section, "HT", 2) &&
1686-
_rtl8812ae_eq_n_byte(prf_path, "2T", 2))
1673+
else if (strcmp(prate_section, "HT") == 0 &&
1674+
strcmp(prf_path, "2T") == 0)
16871675
rate_section = 3;
1688-
else if (_rtl8812ae_eq_n_byte(prate_section, "VHT", 3) &&
1689-
_rtl8812ae_eq_n_byte(prf_path, "1T", 2))
1676+
else if (strcmp(prate_section, "VHT") == 0 &&
1677+
strcmp(prf_path, "1T") == 0)
16901678
rate_section = 4;
1691-
else if (_rtl8812ae_eq_n_byte(prate_section, "VHT", 3) &&
1692-
_rtl8812ae_eq_n_byte(prf_path, "2T", 2))
1679+
else if (strcmp(prate_section, "VHT") == 0 &&
1680+
strcmp(prf_path, "2T") == 0)
16931681
rate_section = 5;
16941682

1695-
if (_rtl8812ae_eq_n_byte(pbandwidth, "20M", 3))
1683+
if (strcmp(pbandwidth, "20M") == 0)
16961684
bandwidth = 0;
1697-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "40M", 3))
1685+
else if (strcmp(pbandwidth, "40M") == 0)
16981686
bandwidth = 1;
1699-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "80M", 3))
1687+
else if (strcmp(pbandwidth, "80M") == 0)
17001688
bandwidth = 2;
1701-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "160M", 4))
1689+
else if (strcmp(pbandwidth, "160M") == 0)
17021690
bandwidth = 3;
17031691

1704-
if (_rtl8812ae_eq_n_byte(pband, "2.4G", 4)) {
1692+
if (strcmp(pband, "2.4G") == 0) {
17051693
ret = _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw,
17061694
BAND_ON_2_4G,
17071695
channel);
@@ -1725,7 +1713,7 @@ static void _rtl8812ae_phy_set_txpower_limit(struct ieee80211_hw *hw,
17251713
regulation, bandwidth, rate_section, channel_index,
17261714
rtlphy->txpwr_limit_2_4g[regulation][bandwidth]
17271715
[rate_section][channel_index][RF90_PATH_A]);
1728-
} else if (_rtl8812ae_eq_n_byte(pband, "5G", 2)) {
1716+
} else if (strcmp(pband, "5G") == 0) {
17291717
ret = _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw,
17301718
BAND_ON_5G,
17311719
channel);

0 commit comments

Comments
 (0)