FAILED: patch "[PATCH] wifi: rtw89: cap firmware section_num before parsing" failed to apply to 6.6-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 273b0a8be083df6d0319ce62caa870e927f94a31
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 273b0a8be083df6d0319ce62caa870e927f94a31 Mon Sep 17 00:00:00 2001
From: Laxman Acharya Padhya <[email protected]>
Date: Tue, 25 Aug 2026 23:29:38 +0545
Subject: [PATCH] wifi: rtw89: cap firmware section_num before parsing
rtw89_fw_bin_info.section_info has FWDL_SECTION_MAX_NUM (10) entries. The v0/v1 header parsers take section_num from an 8-bit firmware field (0..255) and write info->section_info[i] with no cap. rtw89_fw_download_suit() keeps that object on the stack, so a crafted firmware blob overflows the stack.
Reject a truncated header and a section table that does not fit in the firmware image before reading fw_hdr->sections[i].
--- drivers/net/wireless/realtek/rtw89/fw.c | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/net/wireless/realtek/rtw89/fw.c +32 -0
@@ -156,8 +156,24 @@ static int rtw89_fw_hdr_parser_v0(struct rtw89_dev *rtwdev, const u8 *fw, u32 leif (!info)return -EINVAL ; +if (len <sizeof (*fw_hdr)) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->section_num =le32_get_bits (fw_hdr->w6,FW_HDR_W6_SEC_NUM ); +if (!info->section_num || info->section_num >FWDL_SECTION_MAX_NUM ) { +rtw89_err (rtwdev,"[ERR]invalid fw section num %u\n" , + info->section_num); +return -EINVAL ; + } + base_hdr_len =struct_size (fw_hdr, sections, info->section_num); +if (base_hdr_len > len) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->dynamic_hdr_en =le32_get_bits (fw_hdr->w7,FW_HDR_W7_DYN_HDR ); info->idmem_share_mode =le32_get_bits (fw_hdr->w7,FW_HDR_W7_IDMEM_SHARE_MODE );
@@ -455,9 +471,25 @@ static int rtw89_fw_hdr_parser_v1(struct rtw89_dev *rtwdev, const u8 *fw, u32 leint ret;u32 i; +if (len <sizeof (*fw_hdr)) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->section_num =le32_get_bits (fw_hdr->w6,FW_HDR_V1_W6_SEC_NUM ); +if (!info->section_num || info->section_num >FWDL_SECTION_MAX_NUM ) { +rtw89_err (rtwdev,"[ERR]invalid fw section num %u\n" , + info->section_num); +return -EINVAL ; + } + info->dsp_checksum =le32_get_bits (fw_hdr->w6,FW_HDR_V1_W6_DSP_CHKSUM ); base_hdr_len =struct_size (fw_hdr, sections, info->section_num); +if (base_hdr_len > len) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->dynamic_hdr_en =le32_get_bits (fw_hdr->w7,FW_HDR_V1_W7_DYN_HDR ); info->idmem_share_mode =le32_get_bits (fw_hdr->w7,FW_HDR_V1_W7_IDMEM_SHARE_MODE );
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 wifi: rtw89: fw: consider checksum length of security data
From: Ping-Ke Shih <[email protected]>
[ Upstream commit dedf78efd2885048ca36bc17fbd4e1c0af33f2ad ]
The newer firmware file provides security data with checksum, so we need to consider the length. Otherwise it will fail to validate total firmware length resulting in failed to probe.
Stable-dep-of: 273b0a8be083 ("wifi: rtw89: cap firmware section_num before parsing")
--- drivers/net/wireless/realtek/rtw89/fw.c | 3 +++ drivers/net/wireless/realtek/rtw89/fw.h | 3 +++ 2 files changed, 6 insertions(+)
drivers/net/wireless/realtek/rtw89/fw.c +3 -0
@@ -169,6 +169,7 @@ static int rtw89_fw_hdr_parser_v1(struct rtw89_dev *rtwdev, const u8 *fw, u32 leu32 i; info->section_num =le32_get_bits (fw_hdr->w6,FW_HDR_V1_W6_SEC_NUM ); + info->dsp_checksum =le32_get_bits (fw_hdr->w6,FW_HDR_V1_W6_DSP_CHKSUM ); base_hdr_len =struct_size (fw_hdr, sections, info->section_num); info->dynamic_hdr_en =le32_get_bits (fw_hdr->w7,FW_HDR_V1_W7_DYN_HDR );
@@ -197,6 +198,8 @@ static int rtw89_fw_hdr_parser_v1(struct rtw89_dev *rtwdev, const u8 *fw, u32 le section_info->mssc =le32_get_bits (section->w2,FWSECTION_HDR_V1_W2_MSSC ); mssc_len += section_info->mssc *FWDL_SECURITY_SIGLEN ; +if (info->dsp_checksum) + mssc_len += section_info->mssc *FWDL_SECURITY_CHKSUM_LEN ; }else { section_info->mssc =0 ; }
drivers/net/wireless/realtek/rtw89/fw.h +3 -0
@@ -225,6 +225,7 @@ struct rtw89_fw_bin_info {u32 hdr_len;bool dynamic_hdr_en;u32 dynamic_hdr_len; +bool dsp_checksum;struct rtw89_fw_hdr_section_info section_info[FWDL_SECTION_MAX_NUM ]; };
@@ -421,6 +422,7 @@ static inline void RTW89_SET_EDCA_PARAM(void *cmd, u32 val)#define FWDL_SECURITY_SECTION_TYPE 9#define FWDL_SECURITY_SIGLEN 512 +#define FWDL_SECURITY_CHKSUM_LEN 8struct rtw89_fw_dynhdr_sec {__le32 w0;
@@ -523,6 +525,7 @@ struct rtw89_fw_hdr_v1 {#define FW_HDR_V1_W5_YEAR GENMASK(15, 0)#define FW_HDR_V1_W5_HDR_SIZE GENMASK(31, 16)#define FW_HDR_V1_W6_SEC_NUM GENMASK(15, 8) +#define FW_HDR_V1_W6_DSP_CHKSUM BIT(24)#define FW_HDR_V1_W7_DYN_HDR BIT(16)static inline void SET_FW_HDR_PART_SIZE (void *fwhdr,u32 val)
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 wifi: rtw89: cap firmware section_num before parsing
From: Laxman Acharya Padhya <[email protected]>
[ Upstream commit 273b0a8be083df6d0319ce62caa870e927f94a31 ]
rtw89_fw_bin_info.section_info has FWDL_SECTION_MAX_NUM (10) entries. The v0/v1 header parsers take section_num from an 8-bit firmware field (0..255) and write info->section_info[i] with no cap. rtw89_fw_download_suit() keeps that object on the stack, so a crafted firmware blob overflows the stack.
Reject a truncated header and a section table that does not fit in the firmware image before reading fw_hdr->sections[i].
--- drivers/net/wireless/realtek/rtw89/fw.c | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/net/wireless/realtek/rtw89/fw.c +32 -0
@@ -103,8 +103,24 @@ static int rtw89_fw_hdr_parser_v0(struct rtw89_dev *rtwdev, const u8 *fw, u32 leif (!info)return -EINVAL ; +if (len <sizeof (*fw_hdr)) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->section_num =le32_get_bits (fw_hdr->w6,FW_HDR_W6_SEC_NUM ); +if (!info->section_num || info->section_num >FWDL_SECTION_MAX_NUM ) { +rtw89_err (rtwdev,"[ERR]invalid fw section num %u\n" , + info->section_num); +return -EINVAL ; + } + base_hdr_len =struct_size (fw_hdr, sections, info->section_num); +if (base_hdr_len > len) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->dynamic_hdr_en =le32_get_bits (fw_hdr->w7,FW_HDR_W7_DYN_HDR );if (info->dynamic_hdr_en) {
@@ -168,9 +184,25 @@ static int rtw89_fw_hdr_parser_v1(struct rtw89_dev *rtwdev, const u8 *fw, u32 leu32 mssc_len =0 ;u32 i; +if (len <sizeof (*fw_hdr)) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->section_num =le32_get_bits (fw_hdr->w6,FW_HDR_V1_W6_SEC_NUM ); +if (!info->section_num || info->section_num >FWDL_SECTION_MAX_NUM ) { +rtw89_err (rtwdev,"[ERR]invalid fw section num %u\n" , + info->section_num); +return -EINVAL ; + } + info->dsp_checksum =le32_get_bits (fw_hdr->w6,FW_HDR_V1_W6_DSP_CHKSUM ); base_hdr_len =struct_size (fw_hdr, sections, info->section_num); +if (base_hdr_len > len) { +rtw89_err (rtwdev,"[ERR]fw header truncated\n" ); +return -EINVAL ; + } + info->dynamic_hdr_en =le32_get_bits (fw_hdr->w7,FW_HDR_V1_W7_DYN_HDR );if (info->dynamic_hdr_en) {
Signature · 1 line
2.53.0