linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Evgeny Novikov <novikov@ispras.ru>
To: Rajneesh Bhardwaj <irenic.rajneesh@gmail.com>
Cc: Evgeny Novikov <novikov@ispras.ru>,
	David E Box <david.e.box@intel.com>,
	Hans de Goede <hdegoede@redhat.com>,
	Mark Gross <mgross@linux.intel.com>,
	"David E. Box" <david.e.box@linux.intel.com>,
	Gayatri Kammela <gayatri.kammela@intel.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org
Subject: [PATCH] platform/x86: intel_pmc_core: Fix potential buffer overflows
Date: Tue,  3 Aug 2021 21:11:35 +0300	[thread overview]
Message-ID: <20210803181135.22298-1-novikov@ispras.ru> (raw)

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


             reply	other threads:[~2021-08-03 18:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03 18:11 Evgeny Novikov [this message]
2021-08-03 18:26 ` [PATCH] platform/x86: intel_pmc_core: Fix potential buffer overflows 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210803181135.22298-1-novikov@ispras.ru \
    --to=novikov@ispras.ru \
    --cc=david.e.box@intel.com \
    --cc=david.e.box@linux.intel.com \
    --cc=gayatri.kammela@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=irenic.rajneesh@gmail.com \
    --cc=ldv-project@linuxtesting.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgross@linux.intel.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).