PCI: Add BAR index validation in pci_mmap_resource_range()
PATCH 1/1 PCI: Add BAR index validation in pci_mmap_resource_range()
Add validation to ensure the BAR index is valid before accessing PCI resource information in pci_mmap_resource_range(). This prevents potential out-of-bounds access when an invalid BAR index is passed to the function.
The check uses the existing pci_bar_index_is_valid() helper to validate the BAR index early in the function, returning -EINVAL for invalid indices before any resource operations are performed.
Signed-off-by Kaushlendra Kumar <[email protected]>
--- drivers/pci/mmap.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/pci/mmap.c +3 -0
@@ -28,6 +28,9 @@ int pci_mmap_resource_range(struct pci_dev *pdev, int bar,unsigned long size;int ret; +if (!pci_bar_index_is_valid (bar)) +return -EINVAL ; + size = ((pci_resource_len (pdev, bar) -1 ) >>PAGE_SHIFT ) +1 ;if (vma->vm_pgoff +vma_pages (vma) > size)return -EINVAL ;
Signature · 1 line
2.34.1