All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/x86: intel_pmc_core: Fix potential buffer overflows
@ 2021-08-03 18:11 Evgeny Novikov
  2021-08-03 18:26 ` Andy Shevchenko
  2021-08-03 21:49 ` David E. Box
  0 siblings, 2 replies; 9+ messages in thread
From: Evgeny Novikov @ 2021-08-03 18:11 UTC (permalink / raw)
  To: Rajneesh Bhardwaj
  Cc: Evgeny Novikov, David E Box, Hans de Goede, Mark Gross,
	David E. Box, Gayatri Kammela, platform-driver-x86, linux-kernel,
	ldv-project

It looks like pmc_core_get_low_power_modes() mixes up modes and
priorities. In addition to invalid behavior, potentially this can
cause buffer overflows since the driver reads priorities from the
register and then it uses them as indexes for array lpm_priority
that can contain 8 elements at most. The patch swaps modes and
priorities.

Found by Linux Driver Verification project (linuxtesting.org).

Fixes: 005125bfd70e ("platform/x86: intel_pmc_core: Handle sub-states generically")
Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
---
 drivers/platform/x86/intel_pmc_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/intel_pmc_core.c b/drivers/platform/x86/intel_pmc_core.c
index b0e486a6bdfb..667b3df03764 100644
--- a/drivers/platform/x86/intel_pmc_core.c
+++ b/drivers/platform/x86/intel_pmc_core.c
@@ -1469,8 +1469,8 @@ static void pmc_core_get_low_power_modes(struct pmc_dev *pmcdev)
 		int pri0 = GENMASK(3, 0) & priority;
 		int pri1 = (GENMASK(7, 4) & priority) >> 4;
 
-		lpm_priority[pri0] = mode;
-		lpm_priority[pri1] = mode + 1;
+		lpm_priority[mode] = pri0;
+		lpm_priority[mode + 1] = pri1;
 	}
 
 	/*
-- 
2.26.2


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

end of thread, other threads:[~2021-08-05 16:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 18:11 [PATCH] platform/x86: intel_pmc_core: Fix potential buffer overflows Evgeny Novikov
2021-08-03 18:26 ` Andy Shevchenko
2021-08-03 18:30   ` Andy Shevchenko
2021-08-04  9:43     ` Evgeny Novikov
2021-08-03 21:49 ` David E. Box
2021-08-04  0:30   ` [PATCH] platform/x86: intel_pmc_core: Prevent possibile overflow David E. Box
2021-08-04 10:48     ` Evgeny Novikov
2021-08-04 21:51       ` David E. Box
2021-08-05 16:21         ` Evgeny Novikov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.