mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David E. Box" <david.e.box@linux.intel.com>
To: "Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	platform-driver-x86@vger.kernel.org
Cc: "David E. Box" <david.e.box@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/6] platform/x86/intel/pmt/discovery: Validate feature id before use
Date: Fri, 30 Oct 2026 18:29:35 -0700	[thread overview]
Message-ID: <20261031012939.377995-4-david.e.box@linux.intel.com> (raw)
In-Reply-To: <20261031012939.377995-1-david.e.box@linux.intel.com>

pmt_feature_get_disc_table() reads the feature id from device MMIO and
uses it in the duplicate check, as BIT(disc_tbl->id) and as an index
into pmt_feature_names[], before pmt_feature_id_is_valid() is called.

The id is a 32-bit field, so a malformed table can supply a shift count of
BITS_PER_LONG or more, which is undefined. Validate the id before it is
used.

Fixes: d9a078809356 ("platform/x86/intel/pmt: Add PMT Discovery driver")
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
---
 drivers/platform/x86/intel/pmt/discovery.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/intel/pmt/discovery.c b/drivers/platform/x86/intel/pmt/discovery.c
index 143d2b3be562..24ba7211e59d 100644
--- a/drivers/platform/x86/intel/pmt/discovery.c
+++ b/drivers/platform/x86/intel/pmt/discovery.c
@@ -348,6 +348,10 @@ pmt_feature_get_disc_table(struct pmt_features_priv *priv,
 
 	devm_iounmap(priv->dev, disc_base);
 
+	/* The id is used as a bit position and array index below */
+	if (!pmt_feature_id_is_valid(disc_tbl->id))
+		return SKIP_FEATURE;
+
 	if (priv->mask & BIT(disc_tbl->id))
 		return dev_err_probe(priv->dev, -EINVAL, "Duplicate feature: %s\n",
 				     pmt_feature_names[disc_tbl->id]);
@@ -363,9 +367,6 @@ pmt_feature_get_disc_table(struct pmt_features_priv *priv,
 	if (disc_tbl->version > MAX_FEATURE_VERSION)
 		return SKIP_FEATURE;
 
-	if (!pmt_feature_id_is_valid(disc_tbl->id))
-		return SKIP_FEATURE;
-
 	priv->mask |= BIT(disc_tbl->id);
 
 	return 0;
-- 
2.43.0


  parent reply	other threads:[~2026-10-31  1:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31  1:29 [PATCH 0/6] platform/x86/intel: Harden PMT discovery against malformed device data David E. Box
2026-10-31  1:29 ` [PATCH 1/6] platform/x86/intel/pmt/discovery: Bound attr_size against feature_table capacity David E. Box
2026-10-31  1:29 ` [PATCH 2/6] platform/x86/intel/pmt/discovery: Avoid WARN for malformed tables David E. Box
2026-10-31  1:29 ` David E. Box [this message]
2026-10-31  1:29 ` [PATCH 4/6] platform/x86/intel/vsec: Validate discovery table bounds against the BAR David E. Box
2026-10-31  1:29 ` [PATCH 5/6] platform/x86/intel/pmt/discovery: Validate feature table " David E. Box
2026-10-31  1:29 ` [PATCH 6/6] platform/x86/intel/pmt: Validate telemetry regions " David E. Box

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=20261031012939.377995-4-david.e.box@linux.intel.com \
    --to=david.e.box@linux.intel.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®