| From de308ac8b5dae99f31759ca6f51826d741831e27 Mon Sep 17 00:00:00 2001 |
| From: James Sewart <jamessewart@arista.com> |
| Date: Tue, 10 Dec 2019 15:51:33 -0600 |
| Subject: [PATCH] PCI: Fix pci_add_dma_alias() bitmask size |
| |
| commit f8bf2aeb651b3460a4b36fd7ba1ba1d31777d35c upstream. |
| |
| The number of possible devfns is 256, but pci_add_dma_alias() allocated a |
| bitmap of size 255. Fix this off-by-one error. |
| |
| This fixes commits 338c3149a221 ("PCI: Add support for multiple DMA |
| aliases") and c6635792737b ("PCI: Allocate dma_alias_mask with |
| bitmap_zalloc()"), but I doubt it was possible to see a problem because |
| it takes 4 64-bit longs (or 8 32-bit longs) to hold 255 bits, and |
| bitmap_zalloc() doesn't save the 255-bit size anywhere. |
| |
| [bhelgaas: commit log, move #define to drivers/pci/pci.h, include loop |
| limit fix from Qian Cai: |
| https://lore.kernel.org/r/20191218170004.5297-1-cai@lca.pw] |
| Signed-off-by: James Sewart <jamessewart@arista.com> |
| Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> |
| Reviewed-by: Logan Gunthorpe <logang@deltatee.com> |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c |
| index 58c945caa438..55e7c6948bd1 100644 |
| --- a/drivers/pci/pci.c |
| +++ b/drivers/pci/pci.c |
| @@ -5860,7 +5860,7 @@ EXPORT_SYMBOL_GPL(pci_pr3_present); |
| void pci_add_dma_alias(struct pci_dev *dev, u8 devfn) |
| { |
| if (!dev->dma_alias_mask) |
| - dev->dma_alias_mask = bitmap_zalloc(U8_MAX, GFP_KERNEL); |
| + dev->dma_alias_mask = bitmap_zalloc(MAX_NR_DEVFNS, GFP_KERNEL); |
| if (!dev->dma_alias_mask) { |
| pci_warn(dev, "Unable to allocate DMA alias mask\n"); |
| return; |
| diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h |
| index 9cb99380c61e..8923436a671d 100644 |
| --- a/drivers/pci/pci.h |
| +++ b/drivers/pci/pci.h |
| @@ -4,6 +4,9 @@ |
| |
| #include <linux/pci.h> |
| |
| +/* Number of possible devfns: 0.0 to 1f.7 inclusive */ |
| +#define MAX_NR_DEVFNS 256 |
| + |
| #define PCI_FIND_CAP_TTL 48 |
| |
| #define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */ |
| diff --git a/drivers/pci/search.c b/drivers/pci/search.c |
| index 5c7922612733..68326e5849da 100644 |
| --- a/drivers/pci/search.c |
| +++ b/drivers/pci/search.c |
| @@ -42,9 +42,9 @@ int pci_for_each_dma_alias(struct pci_dev *pdev, |
| * DMA, iterate over that too. |
| */ |
| if (unlikely(pdev->dma_alias_mask)) { |
| - u8 devfn; |
| + unsigned int devfn; |
| |
| - for_each_set_bit(devfn, pdev->dma_alias_mask, U8_MAX) { |
| + for_each_set_bit(devfn, pdev->dma_alias_mask, MAX_NR_DEVFNS) { |
| ret = fn(pdev, PCI_DEVID(pdev->bus->number, devfn), |
| data); |
| if (ret) |
| -- |
| 2.7.4 |
| |