linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Hannes Reinecke <hare@suse.de>,
	linux-pci@vger.kernel.org, Bjorn Helgaas <bhelgaas@google.com>
Subject: [PATCH v2 4/6] PCI/VPD: Reject resource tags with invalid size
Date: Thu, 29 Jul 2021 13:42:32 -0500	[thread overview]
Message-ID: <20210729184234.976924-5-helgaas@kernel.org> (raw)
In-Reply-To: <20210729184234.976924-1-helgaas@kernel.org>

From: Bjorn Helgaas <bhelgaas@google.com>

VPD is limited in size by the 15-bit VPD Address field in the VPD
Capability.  Each resource tag includes a length that determines the
overall size of the resource.  Reject any resources that would extend past
the maximum VPD size.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/vpd.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index 66703de2cf2b..e52382050e3e 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -77,6 +77,7 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size)
 
 	while (off < old_size && pci_read_vpd(dev, off, 1, header) == 1) {
 		unsigned char tag;
+		size_t size;
 
 		if (off == 0 && (header[0] == 0x00 || header[0] == 0xff))
 			goto error;
@@ -94,8 +95,11 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size)
 						 off + 1);
 					return 0;
 				}
-				off += PCI_VPD_LRDT_TAG_SIZE +
-					pci_vpd_lrdt_size(header);
+				size = pci_vpd_lrdt_size(header);
+				if (off + size > PCI_VPD_MAX_SIZE)
+					goto error;
+
+				off += PCI_VPD_LRDT_TAG_SIZE + size;
 			} else {
 				pci_warn(dev, "invalid large VPD tag %02x at offset %zu",
 					 tag, off);
@@ -103,9 +107,12 @@ static size_t pci_vpd_size(struct pci_dev *dev, size_t old_size)
 			}
 		} else {
 			/* Short Resource Data Type Tag */
-			off += PCI_VPD_SRDT_TAG_SIZE +
-				pci_vpd_srdt_size(header);
 			tag = pci_vpd_srdt_tag(header);
+			size = pci_vpd_srdt_size(header);
+			if (size == 0 || off + size > PCI_VPD_MAX_SIZE)
+				goto error;
+
+			off += PCI_VPD_SRDT_TAG_SIZE + size;
 			if (tag == PCI_VPD_STIN_END)	/* End tag descriptor */
 				return off;
 		}
-- 
2.25.1


  parent reply	other threads:[~2021-07-29 18:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29 18:42 [PATCH v2 0/6] PCI/VPD: pci_vpd_size() cleanups Bjorn Helgaas
2021-07-29 18:42 ` [PATCH v2 1/6] PCI/VPD: Correct diagnostic for VPD read failure Bjorn Helgaas
2021-07-29 18:42 ` [PATCH v2 2/6] PCI/VPD: Check Resource Item Names against those valid for type Bjorn Helgaas
2021-07-29 18:42 ` [PATCH v2 3/6] PCI/VPD: Treat initial 0xff as missing EEPROM Bjorn Helgaas
2021-07-30  6:04   ` Hannes Reinecke
2021-07-29 18:42 ` Bjorn Helgaas [this message]
2021-07-30  6:07   ` [PATCH v2 4/6] PCI/VPD: Reject resource tags with invalid size Hannes Reinecke
2021-08-09 18:15   ` Qian Cai
2021-08-09 18:46     ` Bjorn Helgaas
2021-08-09 18:57       ` Heiner Kallweit
2021-07-29 18:42 ` [PATCH v2 5/6] PCI/VPD: Don't check Large Resource Item Names for validity Bjorn Helgaas
2021-07-29 18:42 ` [PATCH v2 6/6] PCI/VPD: Allow access to valid parts of VPD if some is invalid Bjorn Helgaas
2021-08-02 22:29 ` [PATCH v2 0/6] PCI/VPD: pci_vpd_size() cleanups Bjorn Helgaas

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=20210729184234.976924-5-helgaas@kernel.org \
    --to=helgaas@kernel.org \
    --cc=bhelgaas@google.com \
    --cc=hare@suse.de \
    --cc=hkallweit1@gmail.com \
    --cc=linux-pci@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).