linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Zong-Zhe Yang <kevin_yang@realtek.com>,
	Ping-Ke Shih <pkshih@realtek.com>,
	Sasha Levin <sashal@kernel.org>,
	kvalo@kernel.org, linux-wireless@vger.kernel.org
Subject: [PATCH AUTOSEL 6.10 061/197] wifi: rtw89: avoid reading out of bounds when loading TX power FW elements
Date: Wed, 25 Sep 2024 07:51:20 -0400	[thread overview]
Message-ID: <20240925115823.1303019-61-sashal@kernel.org> (raw)
In-Reply-To: <20240925115823.1303019-1-sashal@kernel.org>

From: Zong-Zhe Yang <kevin_yang@realtek.com>

[ Upstream commit ed2e4bb17a4884cf29c3347353d8aabb7265b46c ]

Because the loop-expression will do one more time before getting false from
cond-expression, the original code copied one more entry size beyond valid
region.

Fix it by moving the entry copy to loop-body.

Signed-off-by: Zong-Zhe Yang <kevin_yang@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://patch.msgid.link/20240902015803.20420-1-pkshih@realtek.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/wireless/realtek/rtw89/core.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/realtek/rtw89/core.h b/drivers/net/wireless/realtek/rtw89/core.h
index 112bdd95fc6ea..504660ee3cba3 100644
--- a/drivers/net/wireless/realtek/rtw89/core.h
+++ b/drivers/net/wireless/realtek/rtw89/core.h
@@ -3888,16 +3888,22 @@ struct rtw89_txpwr_conf {
 	const void *data;
 };
 
+static inline bool rtw89_txpwr_entcpy(void *entry, const void *cursor, u8 size,
+				      const struct rtw89_txpwr_conf *conf)
+{
+	u8 valid_size = min(size, conf->ent_sz);
+
+	memcpy(entry, cursor, valid_size);
+	return true;
+}
+
 #define rtw89_txpwr_conf_valid(conf) (!!(conf)->data)
 
 #define rtw89_for_each_in_txpwr_conf(entry, cursor, conf) \
-	for (typecheck(const void *, cursor), (cursor) = (conf)->data, \
-	     memcpy(&(entry), cursor, \
-		    min_t(u8, sizeof(entry), (conf)->ent_sz)); \
+	for (typecheck(const void *, cursor), (cursor) = (conf)->data; \
 	     (cursor) < (conf)->data + (conf)->num_ents * (conf)->ent_sz; \
-	     (cursor) += (conf)->ent_sz, \
-	     memcpy(&(entry), cursor, \
-		    min_t(u8, sizeof(entry), (conf)->ent_sz)))
+	     (cursor) += (conf)->ent_sz) \
+		if (rtw89_txpwr_entcpy(&(entry), cursor, sizeof(entry), conf))
 
 struct rtw89_txpwr_byrate_data {
 	struct rtw89_txpwr_conf conf;
-- 
2.43.0


  parent reply	other threads:[~2024-09-25 12:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-25 11:50 [PATCH AUTOSEL 6.10 001/197] wifi: ath9k: fix possible integer overflow in ath9k_get_et_stats() Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 002/197] wifi: rtw89: avoid to add interface to list twice when SER Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 003/197] wifi: ath9k_htc: Use __skb_set_length() for resetting urb before resubmit Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 008/197] wifi: iwlwifi: mvm: Fix a race in scan abort flow Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 009/197] wifi: iwlwifi: mvm: drop wrong STA selection in TX Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 010/197] wifi: cfg80211: Set correct chandef when starting CAC Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 021/197] wifi: mt76: mt7915: disable tx worker during tx BA session enable/disable Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 029/197] wifi: ath12k: fix array out-of-bound access in SoC stats Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 030/197] wifi: ath11k: " Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 031/197] wifi: rtw88: select WANT_DEV_COREDUMP Sasha Levin
2024-09-25 11:50 ` [PATCH AUTOSEL 6.10 039/197] wifi: rtw89: correct base HT rate mask for firmware Sasha Levin
2024-09-25 11:51 ` [PATCH AUTOSEL 6.10 049/197] wifi: iwlwifi: mvm: use correct key iteration Sasha Levin
2024-09-25 11:51 ` [PATCH AUTOSEL 6.10 050/197] wifi: iwlwifi: allow only CN mcc from WRDD Sasha Levin
2024-09-25 11:51 ` [PATCH AUTOSEL 6.10 051/197] wifi: iwlwifi: mvm: avoid NULL pointer dereference Sasha Levin
2024-09-25 11:51 ` [PATCH AUTOSEL 6.10 052/197] wifi: mac80211: fix RCU list iterations Sasha Levin
2024-09-25 11:51 ` Sasha Levin [this message]
2024-09-25 11:51 ` [PATCH AUTOSEL 6.10 067/197] wifi: mt76: mt7915: add dummy HW offload of IEEE 802.11 fragmentation Sasha Levin
2024-09-25 11:51 ` [PATCH AUTOSEL 6.10 068/197] wifi: mt76: mt7915: hold dev->mt76.mutex while disabling tx worker Sasha Levin
2024-09-25 11:51 ` [PATCH AUTOSEL 6.10 070/197] wifi: mwifiex: Fix memcpy() field-spanning write warning in mwifiex_cmd_802_11_scan_ext() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240925115823.1303019-61-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=kevin_yang@realtek.com \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=pkshih@realtek.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).