All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rtlwifi: rtl8821ae: Fix global-out-of-bounds bug in _rtl8812ae_phy_set_txpower_limit()
@ 2022-12-07 15:23 Li Zetao
  2022-12-09  5:11 ` Ping-Ke Shih
  0 siblings, 1 reply; 12+ messages in thread
From: Li Zetao @ 2022-12-07 15:23 UTC (permalink / raw)
  To: pkshih, kvalo, davem, edumazet, kuba, pabeni
  Cc: lizetao1, Larry.Finger, linville, linux-wireless, netdev,
	linux-kernel

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, so this requires the length of the two strings be greater
than or equal to n. 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", it will
lead to access out of bounds in _rtl8812ae_eq_n_byte().

Fix it by adding a length check in _rtl8812ae_eq_n_byte(). 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: 21e4b0726dc6 ("rtlwifi: rtl8821ae: Move driver from staging to regular tree")
Signed-off-by: Li Zetao <lizetao1@huawei.com>
---
 drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
index a29321e2fa72..720114a9ddb2 100644
--- a/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
+++ b/drivers/net/wireless/realtek/rtlwifi/rtl8821ae/phy.c
@@ -1600,7 +1600,7 @@ static bool _rtl8812ae_get_integer_from_string(const char *str, u8 *pint)
 
 static bool _rtl8812ae_eq_n_byte(const char *str1, const char *str2, u32 num)
 {
-	if (num == 0)
+	if (num == 0 || strlen(str1) < num)
 		return false;
 	while (num > 0) {
 		num--;
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-12-14 12:30 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-07 15:23 [PATCH] rtlwifi: rtl8821ae: Fix global-out-of-bounds bug in _rtl8812ae_phy_set_txpower_limit() Li Zetao
2022-12-09  5:11 ` Ping-Ke Shih
2022-12-10 12:47   ` Li Zetao
2022-12-10 13:15     ` Ping-Ke Shih
2022-12-10 13:52       ` Li Zetao
2022-12-10 16:23   ` [PATCH v2] " Li Zetao
2022-12-11 11:21     ` Ping-Ke Shih
2022-12-12  2:35       ` [PATCH v3] " Li Zetao
2022-12-12  1:35         ` Ping-Ke Shih
2022-12-12  1:37         ` Ping-Ke Shih
2022-12-12  2:58           ` [PATCH v4] wifi: rtlwifi: " Li Zetao
2022-12-14 12:27             ` Kalle Valo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.