linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: eocallaghan@alterapraxis.com
To: linux-pci@vger.kernel.org
Subject: [PATCH] drivers/pci: Avoid iterating through memory outside the resource window
Date: Tue, 05 Jan 2016 04:12:38 +1100	[thread overview]
Message-ID: <ebd27b01905fd23bf9144800c1767e88@alterapraxis.com> (raw)

If the 'image' pointer has been advanced more than 'size',
we've already iterated through memory outside the resource window.

We have zero control over whatever we find in the option ROM,
if it's even an option ROM and not just an accident of random
data just happening to look like an option ROM.

Signed-off-by: Edward O'Callaghan <eocallaghan@alterapraxis.com>
---
  drivers/pci/rom.c | 3 +++
  1 file changed, 3 insertions(+)

diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index eb0ad53..45987ad 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -96,6 +96,9 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void 
__iomem *rom, size_t size)
  		last_image = readb(pds + 21) & 0x80;
  		length = readw(pds + 16);
  		image += length * 512;
+		/* Avoid iterating through memory outside the resource window */
+		if (image > rom + size)
+			break;
  	} while (length && !last_image);

  	/* never return a size larger than the PCI resource window */
-- 
2.5.0


             reply	other threads:[~2016-01-04 17:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-04 17:12 eocallaghan [this message]
2016-01-08 18:23 ` [PATCH] drivers/pci: Avoid iterating through memory outside the resource window 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=ebd27b01905fd23bf9144800c1767e88@alterapraxis.com \
    --to=eocallaghan@alterapraxis.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).