platform/x86: intel_pmc_core: Prevent possibile overflow
authorDavid E. Box <david.e.box@linux.intel.com>
Sat, 14 Aug 2021 01:47:28 +0000 (18:47 -0700)
committerHans de Goede <hdegoede@redhat.com>
Tue, 17 Aug 2021 18:53:10 +0000 (20:53 +0200)
commit45b6f75eab6aabf9d88933830f41f532d39f38d2
treefe122cbd35b1e1b083069bfcd45c06504d41b4c1
parent2010319b3c438ba428e9a5c54998c5b05631cf78
platform/x86: intel_pmc_core: Prevent possibile overflow

Substate priority levels are encoded in 4 bits in the LPM_PRI register.
This value was used as an index to an array whose element size was less
than 16, leading to the possibility of overflow should we read a larger
than expected priority.  In addition to the overflow, bad values could lead
to incorrect state reporting.  So rework the priority code to prevent the
overflow and perform some validation of the register. Use the priority
register values if they give an ordering of unique numbers between 0 and
the maximum number of states.  Otherwise, use a default ordering instead.

Reported-by: Evgeny Novikov <novikov@ispras.ru>
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210814014728.520856-1-david.e.box@linux.intel.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
drivers/platform/x86/intel_pmc_core.c
drivers/platform/x86/intel_pmc_core.h