From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B8FB1DE2CD; Tue, 8 Oct 2024 12:19:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728389998; cv=none; b=DMR2LpyATpPZs8kZyRMzLW3/KhBKG68RYYqoMha24loJa4ZHdNCfx/pRwSokSGTUQtegtL8/yKroKbqV9aSDAC8WwuGnD/XothQifPs+fMUxIbpi5LZT+DMVEqcXEGSRuozGbx/x2W7V1Wp1hQ5WQsbRSmXjQTNrzkpbU70H1rs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728389998; c=relaxed/simple; bh=Ns+g5ZBus9RfxvvZOLDORiy9Dzj8l30xS0Ob8/HXsUg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ae5NUfTbJD7vnCO3jSZeljWES7mfyIkGW/Q33EdcugjO+MA1eSGjg5ZL3O9Jq8LxkPalwjF42vJlkV1SEpUwNZCcVmf2ZXkY+oFyp0XlWcuSWMFeSWVJiMcWKb0r3ffwcEZmZN9SiCLLjVUKZay/w5OuqcIXyGA1Ir0R1pRQW0k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1UWr9x1j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1UWr9x1j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7497FC4CEC7; Tue, 8 Oct 2024 12:19:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1728389997; bh=Ns+g5ZBus9RfxvvZOLDORiy9Dzj8l30xS0Ob8/HXsUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1UWr9x1jM8y1//nGNmCjq2uZsf/5FCsPcswrlYDRCPuQnF6I/A+cJ+W9KjEVOoikp kDJ0CtG6/JO3xHPDeegoaw9mHJpZ4226Er6vqNYQenQi6icZ0O7Xe0S9/9LvCmmx8U HQoKTi1Lq5wx0lBrZYAU6kpicjbwkPepgvOwEY5o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zong-Zhe Yang , Ping-Ke Shih , Sasha Levin Subject: [PATCH 6.10 128/482] wifi: rtw89: avoid reading out of bounds when loading TX power FW elements Date: Tue, 8 Oct 2024 14:03:11 +0200 Message-ID: <20241008115653.342063330@linuxfoundation.org> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20241008115648.280954295@linuxfoundation.org> References: <20241008115648.280954295@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zong-Zhe Yang [ 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 Signed-off-by: Ping-Ke Shih Link: https://patch.msgid.link/20240902015803.20420-1-pkshih@realtek.com Signed-off-by: Sasha Levin --- 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