Skip to content

Commit 3010181

Browse files
Ping-Ke ShihKalle Valo
authored andcommitted
rtw89: fix potentially access out of range of RF register array
The RF register array is used to help firmware to restore RF settings. The original code can potentially access out of range, if the size is between (RTW89_H2C_RF_PAGE_SIZE * RTW89_H2C_RF_PAGE_NUM + 1) to ((RTW89_H2C_RF_PAGE_SIZE + 1) * RTW89_H2C_RF_PAGE_NUM). Fortunately, current used size doesn't fall into the wrong case, and the size will not change if we don't update RF parameter. Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Ping-Ke Shih <pkshih@realtek.com> Signed-off-by: Kalle Valo <kvalo@codeaurora.org> Link: https://lore.kernel.org/r/20211119055729.12826-1-pkshih@realtek.com
1 parent 43863ef commit 3010181

File tree

1 file changed

+19
-14
lines changed
  • drivers/net/wireless/realtek/rtw89

1 file changed

+19
-14
lines changed

drivers/net/wireless/realtek/rtw89/phy.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,12 @@ rtw89_phy_cofig_rf_reg_store(struct rtw89_dev *rtwdev,
654654
u16 idx = info->curr_idx % RTW89_H2C_RF_PAGE_SIZE;
655655
u8 page = info->curr_idx / RTW89_H2C_RF_PAGE_SIZE;
656656

657+
if (page >= RTW89_H2C_RF_PAGE_NUM) {
658+
rtw89_warn(rtwdev, "RF parameters exceed size. path=%d, idx=%d",
659+
rf_path, info->curr_idx);
660+
return;
661+
}
662+
657663
info->rtw89_phy_config_rf_h2c[page][idx] =
658664
cpu_to_le32((reg->addr << 20) | reg->data);
659665
info->curr_idx++;
@@ -662,30 +668,29 @@ rtw89_phy_cofig_rf_reg_store(struct rtw89_dev *rtwdev,
662668
static int rtw89_phy_config_rf_reg_fw(struct rtw89_dev *rtwdev,
663669
struct rtw89_fw_h2c_rf_reg_info *info)
664670
{
665-
u16 page = info->curr_idx / RTW89_H2C_RF_PAGE_SIZE;
666-
u16 len = (info->curr_idx % RTW89_H2C_RF_PAGE_SIZE) * 4;
671+
u16 remain = info->curr_idx;
672+
u16 len = 0;
667673
u8 i;
668674
int ret = 0;
669675

670-
if (page > RTW89_H2C_RF_PAGE_NUM) {
676+
if (remain > RTW89_H2C_RF_PAGE_NUM * RTW89_H2C_RF_PAGE_SIZE) {
671677
rtw89_warn(rtwdev,
672-
"rf reg h2c total page num %d larger than %d (RTW89_H2C_RF_PAGE_NUM)\n",
673-
page, RTW89_H2C_RF_PAGE_NUM);
674-
return -EINVAL;
678+
"rf reg h2c total len %d larger than %d\n",
679+
remain, RTW89_H2C_RF_PAGE_NUM * RTW89_H2C_RF_PAGE_SIZE);
680+
ret = -EINVAL;
681+
goto out;
675682
}
676683

677-
for (i = 0; i < page; i++) {
678-
ret = rtw89_fw_h2c_rf_reg(rtwdev, info,
679-
RTW89_H2C_RF_PAGE_SIZE * 4, i);
684+
for (i = 0; i < RTW89_H2C_RF_PAGE_NUM && remain; i++, remain -= len) {
685+
len = remain > RTW89_H2C_RF_PAGE_SIZE ? RTW89_H2C_RF_PAGE_SIZE : remain;
686+
ret = rtw89_fw_h2c_rf_reg(rtwdev, info, len * 4, i);
680687
if (ret)
681-
return ret;
688+
goto out;
682689
}
683-
ret = rtw89_fw_h2c_rf_reg(rtwdev, info, len, i);
684-
if (ret)
685-
return ret;
690+
out:
686691
info->curr_idx = 0;
687692

688-
return 0;
693+
return ret;
689694
}
690695

691696
static void rtw89_phy_config_rf_reg(struct rtw89_dev *rtwdev,

0 commit comments

Comments
 (0)