* [PATCH] PCI: Fail pci_map_rom if the PCI ROM is invalid
@ 2017-11-02 3:48 changbin.du
2017-11-08 0:30 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: changbin.du @ 2017-11-02 3:48 UTC (permalink / raw)
To: bhelgaas; +Cc: tglx, mingo, x86, linux-pci, linux-kernel, Changbin Du
From: Changbin Du <changbin.du@intel.com>
If we detected a invalid PCI ROM (e.g. Invalid PCI ROM header signature),
we should unmap it immediately and fail. It doesn't make any sense that
return a mapped area with size of 0.
I have seen this case on Intel GVTg vGPU, which have no vbios. It will
not cause a real problem, but we should skip it as early as possible.
Signed-off-by: Changbin Du <changbin.du@intel.com>
---
drivers/pci/rom.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index b6edb18..1f5e6af 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -147,12 +147,8 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
return NULL;
rom = ioremap(start, *size);
- if (!rom) {
- /* restore enable if ioremap fails */
- if (!(res->flags & IORESOURCE_ROM_ENABLE))
- pci_disable_rom(pdev);
- return NULL;
- }
+ if (!rom)
+ goto err_ioremap;
/*
* Try to find the true size of the ROM since sometimes the PCI window
@@ -160,7 +156,18 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
* True size is important if the ROM is going to be copied.
*/
*size = pci_get_rom_size(pdev, rom, *size);
+ if (!*size)
+ goto invalid_rom;
+
return rom;
+
+invalid_rom:
+ iounmap(rom);
+err_ioremap:
+ /* restore enable if ioremap fails */
+ if (!(res->flags & IORESOURCE_ROM_ENABLE))
+ pci_disable_rom(pdev);
+ return NULL;
}
EXPORT_SYMBOL(pci_map_rom);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] PCI: Fail pci_map_rom if the PCI ROM is invalid
2017-11-02 3:48 [PATCH] PCI: Fail pci_map_rom if the PCI ROM is invalid changbin.du
@ 2017-11-08 0:30 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2017-11-08 0:30 UTC (permalink / raw)
To: changbin.du; +Cc: bhelgaas, tglx, mingo, x86, linux-pci, linux-kernel
On Thu, Nov 02, 2017 at 11:48:42AM +0800, changbin.du@intel.com wrote:
> From: Changbin Du <changbin.du@intel.com>
>
> If we detected a invalid PCI ROM (e.g. Invalid PCI ROM header signature),
> we should unmap it immediately and fail. It doesn't make any sense that
> return a mapped area with size of 0.
>
> I have seen this case on Intel GVTg vGPU, which have no vbios. It will
> not cause a real problem, but we should skip it as early as possible.
>
> Signed-off-by: Changbin Du <changbin.du@intel.com>
Applied to pci/resource for v4.15, thanks!
I split this into two patches: (1) moving the disable to err_ioremap, and
(2) the actual "if (!*size)" change which is the interesting part.
> ---
> drivers/pci/rom.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
> index b6edb18..1f5e6af 100644
> --- a/drivers/pci/rom.c
> +++ b/drivers/pci/rom.c
> @@ -147,12 +147,8 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
> return NULL;
>
> rom = ioremap(start, *size);
> - if (!rom) {
> - /* restore enable if ioremap fails */
> - if (!(res->flags & IORESOURCE_ROM_ENABLE))
> - pci_disable_rom(pdev);
> - return NULL;
> - }
> + if (!rom)
> + goto err_ioremap;
>
> /*
> * Try to find the true size of the ROM since sometimes the PCI window
> @@ -160,7 +156,18 @@ void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size)
> * True size is important if the ROM is going to be copied.
> */
> *size = pci_get_rom_size(pdev, rom, *size);
> + if (!*size)
> + goto invalid_rom;
> +
> return rom;
> +
> +invalid_rom:
> + iounmap(rom);
> +err_ioremap:
> + /* restore enable if ioremap fails */
> + if (!(res->flags & IORESOURCE_ROM_ENABLE))
> + pci_disable_rom(pdev);
> + return NULL;
> }
> EXPORT_SYMBOL(pci_map_rom);
>
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-11-08 0:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-02 3:48 [PATCH] PCI: Fail pci_map_rom if the PCI ROM is invalid changbin.du
2017-11-08 0:30 ` 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).