All of lore.kernel.org
 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 6/6] platform/x86/intel/pmt: Validate telemetry regions against the BAR
Date: Fri, 30 Oct 2026 18:29:38 -0700	[thread overview]
Message-ID: <20261031012939.377995-7-david.e.box@linux.intel.com> (raw)
In-Reply-To: <20261031012939.377995-1-david.e.box@linux.intel.com>

pmt_resolve_access_pci() computes the base address of a telemetry or
crashlog region from the base offset and BAR index in the device's
discovery header, and the region size also comes from the device. The
resulting range is ioremapped by intel_pmt_dev_register() and can be
mmapped by userspace through sysfs, but it is never checked against the
BAR it claims to be in. A malicious or broken device can therefore
direct the driver at MMIO outside its BAR. For ACCESS_BARID the BAR
index is three bits, so it may also select BAR 6 or 7, which are not
standard BARs.

Check the region against its BAR before it is mapped: the BAR holding the
discovery table for ACCESS_LOCAL, or the BAR named in the header for
ACCESS_BARID.

Fixes: e2729113ce66 ("platform/x86: Intel PMT class driver")
Assisted-by: LLM
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
---
 drivers/platform/x86/intel/pmt/class.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/platform/x86/intel/pmt/class.c b/drivers/platform/x86/intel/pmt/class.c
index 2b11c4012f6a..8f87f8db3966 100644
--- a/drivers/platform/x86/intel/pmt/class.c
+++ b/drivers/platform/x86/intel/pmt/class.c
@@ -214,6 +214,10 @@ static int pmt_resolve_access_pci(struct intel_pmt_entry *entry,
 	struct device *dev = &ivdev->auxdev.dev;
 	struct intel_pmt_header *header = &entry->header;
 	struct resource *disc_res;
+	struct resource res;
+	/* BAR the region lives in, the discovery BAR unless the device names one */
+	unsigned int bar = ivdev->tbir;
+	int ret;
 	u8 bir;
 
 	/*
@@ -258,6 +262,7 @@ static int pmt_resolve_access_pci(struct intel_pmt_entry *entry,
 				   (disc_res->start <= pci_resource_end(pci_dev, i))) {
 					entry->base_addr = pci_resource_start(pci_dev, i) +
 							   header->base_offset;
+					bar = i;
 					break;
 				}
 			if (!entry->base_addr)
@@ -280,6 +285,7 @@ static int pmt_resolve_access_pci(struct intel_pmt_entry *entry,
 		 */
 		entry->base_addr = pci_resource_start(pci_dev, bir) +
 				   GET_ADDRESS(header->base_offset);
+		bar = bir;
 		break;
 	default:
 		dev_err(dev, "Unsupported access type %d\n",
@@ -287,6 +293,20 @@ static int pmt_resolve_access_pci(struct intel_pmt_entry *entry,
 		return -EINVAL;
 	}
 
+	/*
+	 * The base offset and size come from the device. Make sure the region
+	 * lies within the BAR it claims to be in before it is mapped.
+	 */
+	if (header->size) {
+		res = DEFINE_RES_MEM(entry->base_addr, header->size);
+
+		ret = intel_vsec_check_bar_resource(ivdev, bar, &res);
+		if (ret) {
+			dev_err(dev, "Region %pR is outside of its BAR\n", &res);
+			return ret;
+		}
+	}
+
 	return 0;
 }
 
@@ -574,3 +594,4 @@ module_exit(pmt_class_exit);
 MODULE_AUTHOR("Alexander Duyck <alexander.h.duyck@linux.intel.com>");
 MODULE_DESCRIPTION("Intel PMT Class driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS("INTEL_VSEC");
-- 
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 ` [PATCH 3/6] platform/x86/intel/pmt/discovery: Validate feature id before use David E. Box
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 ` David E. Box [this message]

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