platform/x86/amd/pmf: Validate the APTS state index
Subsystems (3)
PATCH 1/1 platform/x86/amd/pmf: Validate the APTS state index
The static slider APTS state index is supplied by the BIOS as an 8-bit value, but apts_config_store contains only APTS_MAX_STATES entries. An invalid firmware value can therefore cause amd_pmf_update_slider_v2() to read beyond the end of the array.
Validate the selected index before applying the slider values and return an error when it is out of range.
--- drivers/platform/x86/amd/pmf/sps.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/platform/x86/amd/pmf/sps.c +7 -3
@@ -248,20 +248,24 @@ static int amd_pmf_update_sps_power_limits_v2(struct amd_pmf_dev *pdev, int pwr_switch (pwr_mode) {case POWER_MODE_PERFORMANCE : index = config_store_v2.sps_idx.power_states[src][POWER_MODE_BEST_PERFORMANCE ]; -amd_pmf_update_slider_v2 (pdev, index);break ;case POWER_MODE_BALANCED_POWER : index = config_store_v2.sps_idx.power_states[src][POWER_MODE_BALANCED ]; -amd_pmf_update_slider_v2 (pdev, index);break ;case POWER_MODE_POWER_SAVER : index = config_store_v2.sps_idx.power_states[src][POWER_MODE_BEST_POWER_EFFICIENCY ]; -amd_pmf_update_slider_v2 (pdev, index);break ;default :return -EINVAL ; } +if (index >=APTS_MAX_STATES ) { +dev_err (pdev->dev,"Invalid APTS index: %d\n" , index); +return -EINVAL ; + } + +amd_pmf_update_slider_v2 (pdev, index); +return 0 ; }
Signature · 1 line
2.43.0
Ilpo Järvinen
maintainerQuoted 9 lines · Mario Limonciello
The static slider APTS state index is supplied by the BIOS as an 8-bit value, but
apts_config_storecontains onlyAPTS_MAX_STATESentries. An invalid firmware value can therefore causeamd_pmf_update_slider_v2()to read beyond the end of the array.Validate the selected index before applying the slider values and return an error when it is out of range.
[...]
Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.
FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent cycle or is clearly a regression fix.
The list of commits applied:
[1/1] platform/x86/amd/pmf: Validate the APTS state index
commit: e70b1f5fec16051dcc862a7c82ac173eb11bbbec
--
i.