* [PATCH v2] pci: Fix infinite loop with ROM image of size 0
[not found] <CAFUqUc6JPgSK4tTP7KuJ8TmVLZR6Abaf9uHUTRZA+OJhv8DoBA@mail.gmail.com>
@ 2015-01-19 8:53 ` Michel Dänzer
2015-01-19 18:48 ` Alex Deucher
2015-01-23 23:51 ` Bjorn Helgaas
0 siblings, 2 replies; 3+ messages in thread
From: Michel Dänzer @ 2015-01-19 8:53 UTC (permalink / raw)
To: Bjorn Helgaas; +Cc: linux-pci, linux-kernel, Federico, dri-devel
From: Michel Dänzer <michel.daenzer@amd.com>
If the image size would ever read as 0, pci_get_rom_size could keep
processing the same image over and over again.
Reported-by: Federico <federicotg@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
---
v2:
* Use unsigned instead of u16 for the local length variable (not sure if
the multiplication by 512 could overflow otherwise)
* Integrate length condition into while statement
* Add stable tag
drivers/pci/rom.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index f955edb..eb0ad53 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -71,6 +71,7 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
{
void __iomem *image;
int last_image;
+ unsigned length;
image = rom;
do {
@@ -93,9 +94,9 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
if (readb(pds + 3) != 'R')
break;
last_image = readb(pds + 21) & 0x80;
- /* this length is reliable */
- image += readw(pds + 16) * 512;
- } while (!last_image);
+ length = readw(pds + 16);
+ image += length * 512;
+ } while (length && !last_image);
/* never return a size larger than the PCI resource window */
/* there are known ROMs that get the size wrong */
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] pci: Fix infinite loop with ROM image of size 0
2015-01-19 8:53 ` [PATCH v2] pci: Fix infinite loop with ROM image of size 0 Michel Dänzer
@ 2015-01-19 18:48 ` Alex Deucher
2015-01-23 23:51 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: Alex Deucher @ 2015-01-19 18:48 UTC (permalink / raw)
To: Michel Dänzer
Cc: Bjorn Helgaas, Linux PCI, LKML, Maling list - DRI developers
On Mon, Jan 19, 2015 at 3:53 AM, Michel Dänzer <michel@daenzer.net> wrote:
> From: Michel Dänzer <michel.daenzer@amd.com>
>
> If the image size would ever read as 0, pci_get_rom_size could keep
> processing the same image over and over again.
>
> Reported-by: Federico <federicotg@gmail.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
> ---
>
> v2:
> * Use unsigned instead of u16 for the local length variable (not sure if
> the multiplication by 512 could overflow otherwise)
> * Integrate length condition into while statement
> * Add stable tag
>
> drivers/pci/rom.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
> index f955edb..eb0ad53 100644
> --- a/drivers/pci/rom.c
> +++ b/drivers/pci/rom.c
> @@ -71,6 +71,7 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
> {
> void __iomem *image;
> int last_image;
> + unsigned length;
>
> image = rom;
> do {
> @@ -93,9 +94,9 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
> if (readb(pds + 3) != 'R')
> break;
> last_image = readb(pds + 21) & 0x80;
> - /* this length is reliable */
> - image += readw(pds + 16) * 512;
> - } while (!last_image);
> + length = readw(pds + 16);
> + image += length * 512;
> + } while (length && !last_image);
>
> /* never return a size larger than the PCI resource window */
> /* there are known ROMs that get the size wrong */
> --
> 2.1.4
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] pci: Fix infinite loop with ROM image of size 0
2015-01-19 8:53 ` [PATCH v2] pci: Fix infinite loop with ROM image of size 0 Michel Dänzer
2015-01-19 18:48 ` Alex Deucher
@ 2015-01-23 23:51 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2015-01-23 23:51 UTC (permalink / raw)
To: Michel Dänzer; +Cc: linux-pci, linux-kernel, Federico, dri-devel
On Mon, Jan 19, 2015 at 05:53:20PM +0900, Michel Dänzer wrote:
> From: Michel Dänzer <michel.daenzer@amd.com>
>
> If the image size would ever read as 0, pci_get_rom_size could keep
> processing the same image over and over again.
>
> Reported-by: Federico <federicotg@gmail.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Applied with Alex's ack to pci/resource for v3.20, thanks!
> ---
>
> v2:
> * Use unsigned instead of u16 for the local length variable (not sure if
> the multiplication by 512 could overflow otherwise)
> * Integrate length condition into while statement
> * Add stable tag
>
> drivers/pci/rom.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
> index f955edb..eb0ad53 100644
> --- a/drivers/pci/rom.c
> +++ b/drivers/pci/rom.c
> @@ -71,6 +71,7 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
> {
> void __iomem *image;
> int last_image;
> + unsigned length;
>
> image = rom;
> do {
> @@ -93,9 +94,9 @@ size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size)
> if (readb(pds + 3) != 'R')
> break;
> last_image = readb(pds + 21) & 0x80;
> - /* this length is reliable */
> - image += readw(pds + 16) * 512;
> - } while (!last_image);
> + length = readw(pds + 16);
> + image += length * 512;
> + } while (length && !last_image);
>
> /* never return a size larger than the PCI resource window */
> /* there are known ROMs that get the size wrong */
> --
> 2.1.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-23 23:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAFUqUc6JPgSK4tTP7KuJ8TmVLZR6Abaf9uHUTRZA+OJhv8DoBA@mail.gmail.com>
2015-01-19 8:53 ` [PATCH v2] pci: Fix infinite loop with ROM image of size 0 Michel Dänzer
2015-01-19 18:48 ` Alex Deucher
2015-01-23 23:51 ` Bjorn Helgaas
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).