Skip to content

Commit fc34422

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+ 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 a71cc46 commit fc34422

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
@@ -1626,18 +1626,6 @@ static bool _rtl8812ae_get_integer_from_string(const char *str, u8 *pint)
16261626
return true;
16271627
}
16281628

1629-
static bool _rtl8812ae_eq_n_byte(const char *str1, const char *str2, u32 num)
1630-
{
1631-
if (num == 0)
1632-
return false;
1633-
while (num > 0) {
1634-
num--;
1635-
if (str1[num] != str2[num])
1636-
return false;
1637-
}
1638-
return true;
1639-
}
1640-
16411629
static s8 _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(struct ieee80211_hw *hw,
16421630
u8 band, u8 channel)
16431631
{
@@ -1687,42 +1675,42 @@ static void _rtl8812ae_phy_set_txpower_limit(struct ieee80211_hw *hw,
16871675
power_limit = power_limit > MAX_POWER_INDEX ?
16881676
MAX_POWER_INDEX : power_limit;
16891677

1690-
if (_rtl8812ae_eq_n_byte(pregulation, "FCC", 3))
1678+
if (strcmp(pregulation, "FCC") == 0)
16911679
regulation = 0;
1692-
else if (_rtl8812ae_eq_n_byte(pregulation, "MKK", 3))
1680+
else if (strcmp(pregulation, "MKK") == 0)
16931681
regulation = 1;
1694-
else if (_rtl8812ae_eq_n_byte(pregulation, "ETSI", 4))
1682+
else if (strcmp(pregulation, "ETSI") == 0)
16951683
regulation = 2;
1696-
else if (_rtl8812ae_eq_n_byte(pregulation, "WW13", 4))
1684+
else if (strcmp(pregulation, "WW13") == 0)
16971685
regulation = 3;
16981686

1699-
if (_rtl8812ae_eq_n_byte(prate_section, "CCK", 3))
1687+
if (strcmp(prate_section, "CCK") == 0)
17001688
rate_section = 0;
1701-
else if (_rtl8812ae_eq_n_byte(prate_section, "OFDM", 4))
1689+
else if (strcmp(prate_section, "OFDM") == 0)
17021690
rate_section = 1;
1703-
else if (_rtl8812ae_eq_n_byte(prate_section, "HT", 2) &&
1704-
_rtl8812ae_eq_n_byte(prf_path, "1T", 2))
1691+
else if (strcmp(prate_section, "HT") == 0 &&
1692+
strcmp(prf_path, "1T") == 0)
17051693
rate_section = 2;
1706-
else if (_rtl8812ae_eq_n_byte(prate_section, "HT", 2) &&
1707-
_rtl8812ae_eq_n_byte(prf_path, "2T", 2))
1694+
else if (strcmp(prate_section, "HT") == 0 &&
1695+
strcmp(prf_path, "2T") == 0)
17081696
rate_section = 3;
1709-
else if (_rtl8812ae_eq_n_byte(prate_section, "VHT", 3) &&
1710-
_rtl8812ae_eq_n_byte(prf_path, "1T", 2))
1697+
else if (strcmp(prate_section, "VHT") == 0 &&
1698+
strcmp(prf_path, "1T") == 0)
17111699
rate_section = 4;
1712-
else if (_rtl8812ae_eq_n_byte(prate_section, "VHT", 3) &&
1713-
_rtl8812ae_eq_n_byte(prf_path, "2T", 2))
1700+
else if (strcmp(prate_section, "VHT") == 0 &&
1701+
strcmp(prf_path, "2T") == 0)
17141702
rate_section = 5;
17151703

1716-
if (_rtl8812ae_eq_n_byte(pbandwidth, "20M", 3))
1704+
if (strcmp(pbandwidth, "20M") == 0)
17171705
bandwidth = 0;
1718-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "40M", 3))
1706+
else if (strcmp(pbandwidth, "40M") == 0)
17191707
bandwidth = 1;
1720-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "80M", 3))
1708+
else if (strcmp(pbandwidth, "80M") == 0)
17211709
bandwidth = 2;
1722-
else if (_rtl8812ae_eq_n_byte(pbandwidth, "160M", 4))
1710+
else if (strcmp(pbandwidth, "160M") == 0)
17231711
bandwidth = 3;
17241712

1725-
if (_rtl8812ae_eq_n_byte(pband, "2.4G", 4)) {
1713+
if (strcmp(pband, "2.4G") == 0) {
17261714
ret = _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw,
17271715
BAND_ON_2_4G,
17281716
channel);
@@ -1746,7 +1734,7 @@ static void _rtl8812ae_phy_set_txpower_limit(struct ieee80211_hw *hw,
17461734
regulation, bandwidth, rate_section, channel_index,
17471735
rtlphy->txpwr_limit_2_4g[regulation][bandwidth]
17481736
[rate_section][channel_index][RF90_PATH_A]);
1749-
} else if (_rtl8812ae_eq_n_byte(pband, "5G", 2)) {
1737+
} else if (strcmp(pband, "5G") == 0) {
17501738
ret = _rtl8812ae_phy_get_chnl_idx_of_txpwr_lmt(hw,
17511739
BAND_ON_5G,
17521740
channel);

0 commit comments

Comments
 (0)