linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] thermal: intel_powerclamp: Check for a possible array out of bounds access.
@ 2023-06-02  8:55 Daniil Dulov
  2023-06-04 16:13 ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Daniil Dulov @ 2023-06-02  8:55 UTC (permalink / raw)
  To: Zhang Rui
  Cc: Daniil Dulov, Daniel Lezcano, Amit Kucheria, Rafael J. Wysocki,
	Srinivas Pandruvada, Greg Kroah-Hartman, Chen Yu, Sasha Levin,
	Arjan van de Ven, Jacob Pan, linux-pm, linux-kernel, lvc-project

ratio may be equal to MAX_TARGET_RATIO - 1 that will result in
out of bound access.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: d6d71ee4a14a ("PM: Introduce Intel PowerClamp Driver")
Signed-off-by: Daniil Dulov <d.dulov@aladdin.ru>
---
 drivers/thermal/intel/intel_powerclamp.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c
index fb04470d7d4b..9deaf2b8ccf6 100644
--- a/drivers/thermal/intel/intel_powerclamp.c
+++ b/drivers/thermal/intel/intel_powerclamp.c
@@ -277,7 +277,8 @@ static unsigned int get_compensation(int ratio)
 		comp = (cal_data[ratio].steady_comp +
 			cal_data[ratio - 1].steady_comp +
 			cal_data[ratio - 2].steady_comp) / 3;
-	} else if (cal_data[ratio].confidence >= CONFIDENCE_OK &&
+	} else if (ratio < MAX_TARGET_RATIO - 1 &&
+		cal_data[ratio].confidence >= CONFIDENCE_OK &&
 		cal_data[ratio - 1].confidence >= CONFIDENCE_OK &&
 		cal_data[ratio + 1].confidence >= CONFIDENCE_OK) {
 		comp = (cal_data[ratio].steady_comp +
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-05 16:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-02  8:55 [PATCH] thermal: intel_powerclamp: Check for a possible array out of bounds access Daniil Dulov
2023-06-04 16:13 ` Rafael J. Wysocki
2023-06-05 16:36   ` srinivas pandruvada

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).